import BigNumberJs from 'bignumber.js'; import { providers } from 'ethers'; import BaseService from '../commons/BaseService'; import { eEthereumTxType, transactionType } from '../commons/types'; import { IAutoCompoundApe } from './typechain/IAutoCompoundApe'; import { IAutoCompoundApe__factory } from './typechain/IAutoCompoundApe__factory'; const APE_COIN_DECIMAL = 18; export class AutoCompoundApe extends BaseService { instance: IAutoCompoundApe; constructor(provider: providers.Provider, address: string) { super(provider, IAutoCompoundApe__factory); this.instance = this.getContractInstance(address); } public async deposit({ amount, user }: { amount: string; user: string }) { const populatedTransaction = this.instance.populateTransaction.deposit( user, new BigNumberJs(amount).shiftedBy(APE_COIN_DECIMAL).toFixed(), ); const txCallback: () => Promise = this.generateTxCallback({ rawTxMethod: async () => populatedTransaction, from: user, }); return { tx: txCallback, txType: eEthereumTxType.STAKE_ACTION, gas: this.generateTxPriceEstimation([], txCallback), }; } public async withdraw({ amount, user }: { amount: string; user: string }) { const populatedTransaction = this.instance.populateTransaction.withdraw( new BigNumberJs(amount).shiftedBy(APE_COIN_DECIMAL).toFixed(), ); const txCallback: () => Promise = this.generateTxCallback({ rawTxMethod: async () => populatedTransaction, from: user, }); return { tx: txCallback, txType: eEthereumTxType.STAKE_ACTION, gas: this.generateTxPriceEstimation([], txCallback), }; } }