import { ethers, providers } from 'ethers'; import BaseService from '../commons/BaseService'; import { eEthereumTxType, transactionType } from '../commons/types'; import { WETHValidator } from '../commons/validators/methodValidators'; import { isEthAddress, isPositiveAmount, } from '../commons/validators/paramValidators'; import { WETH9 } from './typechain/WETH9'; import { WETH9__factory } from './typechain/WETH9Factory'; export class WETHService extends BaseService { contractAddress: string; constructor(provider: providers.Provider, address: string) { super(provider, WETH9__factory); this.contractAddress = address; } @WETHValidator public async deposit( @isPositiveAmount('amount') @isEthAddress('onBehalOf') amount: number, onBehalfOf: string, ) { const contract = this.getContractInstance(this.contractAddress); const txCallback: () => Promise = this.generateTxCallback({ rawTxMethod: async () => contract.populateTransaction.deposit(), from: onBehalfOf, value: ethers.utils.parseEther(`${amount}`).toString(), }); return { tx: txCallback, txType: eEthereumTxType.DLP_ACTION, gas: this.generateTxPriceEstimation([], txCallback), }; } @WETHValidator public async withdraw( @isPositiveAmount('amount') @isEthAddress('onBehalOf') amount: number, onBehalfOf: string, ) { const contract = this.getContractInstance(this.contractAddress); const txCallback = this.generateTxCallback({ rawTxMethod: async () => contract.populateTransaction.withdraw( ethers.utils.parseEther(`${amount}`).toString(), ), from: onBehalfOf, }); return { tx: txCallback, txType: eEthereumTxType.DLP_ACTION, gas: this.generateTxPriceEstimation([], txCallback), }; } }