import { providers } from 'ethers'; import BaseService from '../commons/BaseService'; import { eEthereumTxType, EthereumTransactionTypeExtended, transactionType, } from '../commons/types'; import { IMulticall__factory } from './typechain/IMulticall__factory'; import { INonfungiblePositionManager } from './typechain/INonfungiblePositionManager'; import { INonfungiblePositionManager__factory } from './typechain/INonfungiblePositionManager__factory'; export class NonfungiblePositionManager extends BaseService { private readonly instance: INonfungiblePositionManager; constructor(provider: providers.Provider, contract: string) { super(provider, INonfungiblePositionManager__factory); this.instance = this.getContractInstance(contract); } public increaseLiquidity({ tokenId, amount0Desired, amount1Desired, amount0Min, amount1Min, deadline, token0PayByETH, token1PayByETH, onBehalfOf, }: { tokenId: string; amount0Desired: string; amount1Desired: string; amount0Min: string; amount1Min: string; deadline: number; token0PayByETH: boolean; token1PayByETH: boolean; onBehalfOf: string; }): EthereumTransactionTypeExtended { const contract = this.instance; const txCallback: () => Promise = token0PayByETH || token1PayByETH ? this.generateTxCallback({ rawTxMethod: async () => { const encodedData0 = contract.interface.encodeFunctionData( 'increaseLiquidity', [ { tokenId, amount0Desired, amount1Desired, amount0Min, amount1Min, deadline, }, ], ); const encodedData1 = contract.interface.encodeFunctionData('refundETH'); return IMulticall__factory.connect( contract.address, contract.provider, ).populateTransaction.multicall([encodedData0, encodedData1], { value: token0PayByETH ? amount0Desired : amount1Desired, }); }, from: onBehalfOf, value: token0PayByETH ? amount0Desired : amount1Desired, }) : this.generateTxCallback({ rawTxMethod: async () => { return contract.populateTransaction.increaseLiquidity({ tokenId, amount0Desired, amount1Desired, amount0Min, amount1Min, deadline, }); }, from: onBehalfOf, }); return { tx: txCallback, txType: eEthereumTxType.DLP_ACTION, gas: this.generateTxPriceEstimation([], txCallback), }; } }