import BigNumber from 'bignumber.js/bignumber' ; import * as Types from './types.js' ; import { contractAddresses , supportedPools , } from './constants.js' ; import UNIV2PairAbi from './abi/uni_v2_lp.json' ; import FarmAbi from './abi/farm.json' ; import ERC20Abi from './abi/erc20.json' ; import ERC20V2Abi from './abi/erc20v2.json' ; import WETHAbi from './abi/weth.json' ; export class Contracts { constructor ( provider , networkId , web3 , options ) { this . web3 = web3 ; this . defaultConfirmations = options . defaultConfirmations ; this . autoGasMultiplier = options . autoGasMultiplier || 1.5 ; this . confirmationType = options . confirmationType || Types . ConfirmationType . Confirmed ; this . defaultGas = options . defaultGas ; this . defaultGasPrice = options . defaultGasPrice ; this . erc20 = new this . web3 . eth . Contract ( ERC20Abi ) ; this . erc20v2 = new this . web3 . eth . Contract ( ERC20V2Abi ) ; this . farm = new this . web3 . eth . Contract ( FarmAbi ) ; this . weth = new this . web3 . eth . Contract ( WETHAbi ) ; this . pools = supportedPools . map ( ( pool ) => Object . assign ( pool , { lpAddress : pool . lpAddresses [ networkId ] , tokenAddress : pool . tokenAddresses [ networkId ] , lpContract : new this . web3 . eth . Contract ( UNIV2PairAbi ) , tokenContract : pool . version === 'V1' ? new this . web3 . eth . Contract ( ERC20Abi ) : new this . web3 . eth . Contract ( ERC20V2Abi ) , } ) ) ; this . setProvider ( provider , networkId ) ; this . setDefaultAccount ( this . web3 . eth . defaultAccount ) ; } setProvider ( provider , networkId ) { const setProvider = ( contract , address ) => { contract . setProvider ( provider ) ; if ( address ) contract . options . address = address ; else console . error ( 'Contract address not found in network' , networkId ) ; } ; setProvider ( this . erc20 , contractAddresses . erc20 [ networkId ] ) ; setProvider ( this . erc20v2 , contractAddresses . erc20v2 [ networkId ] ) ; setProvider ( this . farm , contractAddresses . farm [ networkId ] ) ; setProvider ( this . weth , contractAddresses . weth [ networkId ] ) ; this . pools . forEach ( ( { lpContract , lpAddress , tokenContract , tokenAddress } ) => { setProvider ( lpContract , lpAddress ) ; setProvider ( tokenContract , tokenAddress ) ; } ) ; } setDefaultAccount ( account ) { this . erc20 . options . from = account ; this . erc20v2 . options . from = account ; this . farm . options . from = account ; } }