| 9 | } |
| 10 | |
| 11 | export default class Assets implements IAssets { |
| 12 | constructor(private web3: Web3) {} |
| 13 | |
| 14 | async getNativeTokenBalance(userAddress?: string): Promise<string> { |
| 15 | let address = userAddress ?? (await this.web3.eth.getAccounts())[0]; |
| 16 | |
| 17 | return this.web3.eth.getBalance(address); |
| 18 | } |
| 19 | |
| 20 | async getBalanceForToken(tokenAddress: string, tokenHolderAddress?: string): Promise<string> { |
| 21 | let address = tokenHolderAddress ?? (await this.web3.eth.getAccounts())[0]; |
| 22 | const tokenContract = new this.web3.eth.Contract(ERC20ABI as AbiItem[], tokenAddress); |
| 23 | |
| 24 | return tokenContract.methods.balanceOf(address).call(); |
| 25 | } |
| 26 | |
| 27 | async getTokenInfo(tokenAddress: string): Promise<{ decimals: number; name: string; symbol: string }> { |
| 28 | const tokenContract = new this.web3.eth.Contract(ERC20ABI as AbiItem[], tokenAddress); |
| 29 | return { |
| 30 | decimals: Number(await tokenContract.methods.decimals().call()), |
| 31 | name: await tokenContract.methods.name().call(), |
| 32 | symbol: await tokenContract.methods.symbol().call(), |
| 33 | }; |
| 34 | } |
| 35 | } |
nothing calls this directly
no outgoing calls
no test coverage detected