import Web3 from 'web3' ; import { provider } from 'web3-core' ; import { AbiItem } from 'web3-utils' ; import ERC20ABI from '../constants/abi/ERC20.json' ; import { Contract } from 'web3-eth-contract' ; export const getContract = ( provider , address ) => { const web3 = new Web3 ( provider ) ; const contract = new web3 . eth . Contract ( ( ERC20ABI . abi as unknown ) as AbiItem , address ) ; return contract ; } ; export const getAllowance = async ( lpContract , farmContract , account ) : Promise < string > => { try { const allowance = await lpContract . methods . allowance ( account , farmContract . options . address ) . call ( ) ; return allowance ; } catch ( e ) { return '0' ; } } ; export const getBalance = async ( provider , tokenAddress , userAddress ) : Promise < string > => { const lpContract = getContract ( provider , tokenAddress ) ; try { const balance = await lpContract . methods . balanceOf ( userAddress ) . call ( ) ; return balance ; } catch ( e ) { return '0' ; } } ;