-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtokens.ts
53 lines (45 loc) · 1.41 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { Token } from '@uniswap/sdk-core'
import { Signer, BigNumber, BigNumberish, Contract, providers } from 'ethers'
import { CHAIN_ID } from './config'
const ERC20_ABI = [
'function allowance(address, address) external view returns (uint256)',
'function approve(address, uint) external returns (bool)',
'function balanceOf(address) external view returns(uint256)',
]
type TokenWithContract = {
contract: (provider: providers.BaseProvider) => Contract
walletHas: (signer: Signer, requiredAmount: BigNumberish) => Promise<boolean>
token: Token
}
const buildERC20TokenWithContract = (
address: string,
name: string,
symbol: string,
decimals: number,
): TokenWithContract => {
return {
contract: (provider) => {
return new Contract(address, ERC20_ABI, provider)
},
walletHas: async (signer, requiredAmount) => {
const contract = new Contract(address, ERC20_ABI, signer.provider)
const signerBalance = await contract
.connect(signer)
.balanceOf(await signer.getAddress())
return signerBalance.gte(BigNumber.from(requiredAmount))
},
token: new Token(CHAIN_ID, address, decimals, symbol, name),
}
}
export const UNI = buildERC20TokenWithContract(
'0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984',
'Uniswap',
'UNI',
18,
)
export const WETH = buildERC20TokenWithContract(
'0xc778417E063141139Fce010982780140Aa0cD5Ab',
'Wrapped Ether',
'WETH',
18,
)