In the hardhat local fork, I created the pool by interacting with factoryv3 in javascript. I approve the tokens to nonfungiblepositionmanager. I check allowance and it’s all good. I have enough funds But when I try to add liquidity it don’t work interacting Nonfungiblepositionmanager. I think It might be the upper and lower ticker causing the error. Here is the code snippet:
// 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()
I expected to add liquidity to my new created pool using Nonfungiblepositionmanager. The price Im looking to create is 0.0002 with my new token.
You just need to edit TICK values.
I just took the following code in my example :
{
token0: WETH,
token1: DAI,
fee: 3000,
tickLower: -60000,
tickUpper: 60000,
amount0Desired: 1000,
amount1Desired: 1000,
amount0Min: 0,
amount1Min: 0,
recipient: address(this),
deadline: block.timestamp
}
The ones from Uniswap documentation did not work with my fork of Arbitrum locally.