Hardhat本地分叉中NonfungiblePositionManager添加流动性失败求助
问题:Uniswap V3添加流动性交易无理由回滚(怀疑tick参数问题)
在Hardhat本地分叉环境中,已通过JavaScript调用FactoryV3创建交易池,且将代币授权给NonfungiblePositionManager,确认授权额度与账户资金均充足,但调用NonfungiblePositionManager添加流动性时交易无理由回滚,怀疑是上下tick参数导致问题。目标是通过NonfungiblePositionManager为新创建的交易池添加流动性,目标价格为0.0002(新代币兑DAI)。
代码片段如下:
// contract nonfungiblePosition const NonfungiblePositionManager_abi = require('./abis/NonfungiblePositionManager.json'); const nonfungiblePositionManagerAddress = '0xC36442b4a4522E871399CD717aBDD847Ab11FE88'; const nonfungiblePositionManagerContract = new ethers.Contract(nonfungiblePositionManagerAddress, NonfungiblePositionManager_abi, account); //Get the token addresses and decimal places for the tokens you want to provide liquidity for: const erc20Abi = require('./abis/ERC20.json'); const DAIaddress = '0x6B175474E89094C44Da98b954EedeAC495271d0F'; const happpyaddress = 'adressss'; const DAIDecimals = 18; const happyDecimals = 18; //Define the fee tier for the pool: const fee = 300; // Fee tier of 0.3% // Calculate the desired amount of DAI for a given amount of Happy const HappyPriceInDAI = 0.0002; const amountHappy = ethers.utils.parseUnits('1', happyDecimals); const amountDAI = amounthappy.mul(ethers.utils.parseUnits(happyPriceInDAI.toString(), DAIDecimals)) const slippagePercentage = 0.995; // 0.5% slippage allowed //add the money const mintPool = async () => { console.log("create the pool baby, baby..."); const gasPrice = await provider.getGasPrice(); const tx = await nonfungiblePositionManagerContract.mint({ token1: DAIaddress, token0: happyaddress, fee: fee, tickLower: 8872, tickUpper: 900000, amount0Desired: amounthappy, amount1Desired: amountDAI, amount0Min: amounthappy.mul(ethers.utils.parseUnits(slippagePercentage.toString(), happyDecimals)), amount1Min: amountDAI.mul(ethers.utils.parseUnits(slippagePercentage.toString(), DAIDecimals)), recipient: acct2, deadline: Math.floor(Date.now() / 1000) + 60 * 10,// 10 minutes from now, },{ gasPrice, gasLimit: ethers.utils.hexlify(300000), // 300 gwei, }); const receipt = await tx.wait(); console.log('Add liquidity transaction receipt:', receipt); }; mintPool()
内容的提问来源于stack exchange,提问作者jayyyo
相关产品推荐
相关产品推荐

