-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathtokens.ts
32 lines (27 loc) · 1.16 KB
/
tokens.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { BigNumber, Contract, providers, Signer } from 'ethers'
import { ERC20_ABI } from './abis'
function _execTokenFunction<T>(
tokenAddress: string,
signerOrProvider: Signer | providers.Provider,
fnc: string,
args: any[] = [],
): Promise<T> {
const token = new Contract(tokenAddress, ERC20_ABI, signerOrProvider)
return token[fnc](...args) as Promise<T>
}
export const ERC20Decimals = async (tokenAddress: string, signerOrProvider: Signer | providers.Provider) => {
return _execTokenFunction<number>(tokenAddress, signerOrProvider, 'decimals')
}
export const ERC20Name = async (tokenAddress: string, signerOrProvider: Signer | providers.Provider) => {
return _execTokenFunction<string>(tokenAddress, signerOrProvider, 'name')
}
export const ERC20Symbol = async (tokenAddress: string, signerOrProvider: Signer | providers.Provider) => {
return _execTokenFunction<string>(tokenAddress, signerOrProvider, 'symbol')
}
export const ERC20Balance = async (
tokenAddress: string,
holderAddress: string,
signerOrProvider: Signer | providers.Provider,
) => {
return _execTokenFunction<BigNumber>(tokenAddress, signerOrProvider, 'balanceOf', [holderAddress])
}