You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Apr 25, 2024. It is now read-only.
I am forking polygon mainnet on hardhat then running it locally, The pool created is betweem USDC and TokenA (a token i created)
consthre=require("hardhat");const{ ethers }=hre;const{
Pool,
TickMath,
nearestUsableTick,TICK_SPACINGS,}=require("@uniswap/v3-sdk");const{abi: poolAbi,}=require("@uniswap/v3-core/artifacts/contracts/UniswapV3Pool.sol/UniswapV3Pool.json");const{abi: factoryAbi,}=require("@uniswap/v3-core/artifacts/contracts/UniswapV3Factory.sol/UniswapV3Factory.json");const{abi: routerAbi,}=require("@uniswap/v3-periphery/artifacts/contracts/SwapRouter.sol/SwapRouter.json");const{abi: NonfungiblePositionManagerAbi}=require('@uniswap/v3-periphery/artifacts/contracts/NonfungiblePositionManager.sol/NonfungiblePositionManager.json');const{abi: usdcAbi}=require("./../contracts/abi/udsc.json");const{abi: wmaticAbi}=require("./../contracts/abi/WMATIC.json");const{abi: TokenAAbi}=require("./../contracts/abi/TokenA.json");constdotenv=require("dotenv");dotenv.config();asyncfunctionmain(){// get signerconst[signer]=awaitethers.getSigners();// deploy tokenA//...awaittokenA.deployed();// all addresses//...constprovider=newethers.providers.JsonRpcProvider(process.env.POLYGON_RPC_URL);// all connections//.../// STEP 1: GET USDC//.../// STEP 1: CREATE POOLconstfee=3000;// Fee in hundredths of a percent (e.g., 3000 is 3%)consttickSpacing=TICK_SPACINGS[fee];constinitialSqrtPrice=TickMath.getSqrtRatioAtTick(0);// Set the initial price ratioconstinitialTick=nearestUsableTick(-887272,tickSpacing);// Set the initial tickconsole.log(0);// approve router contract to usdcconstresult=awaitusdc.connect(signer).approve(routerAddress,ethers.constants.MaxUint256,{gasLimit: 30000000,});console.log("RESULT ::: ",result);// await TokenA.approve(routerAddress, ethers.constants.MaxUint256);console.log(1);constcreatePoolTx=awaitfactory.connect(signer).createPool(USDC,TokenA.address,fee);console.log(2);constcreatePoolReceipt=awaitcreatePoolTx.wait();console.log(3);constpoolAddress=createPoolReceipt.events[0].args.pool;console.log(4,poolAddress);constpool=newethers.Contract(poolAddress,poolAbi);console.log(5);// const initializeTx = await pool.connect(signer).initialize(initialSqrtPrice, {gasLimit: 30000000});// console.log(6);// await initializeTx.wait();// console.log(7);console.log(createPoolReceipt,poolAddress);/// STEP 2: ADD LIQUIDITY// Define the amounts of tokens to addconstamountUSDCDesired=ethers.utils.parseUnits('10000000000000000000000',6);// 10,000 USDCconstamountTokenADesired=ethers.utils.parseEther('10000000000000000000000',18);// 10000 TokenA// tickLower = floor(log(0.99) / log(1.0001)) = -202// tickUpper = floor(log(1.01) / log(1.0001)) = 200// Define the range positionconsttickLower=-202;consttickUpper=200;console.log(6);constapproveUSDC=awaitusdc.connect(signer).approve(positionManager.address,amountUSDCDesired);console.log(7);constapproveTokenA=awaitTokenA.connect(signer).approve(positionManager.address,amountTokenADesired);console.log(8);awaitapproveUSDC.wait();awaitapproveTokenA.wait();// ERROR// Add liquidityconsttx=awaitpositionManager.connect(signer).mint([USDC,TokenA.address,fee,tickLower,tickUpper,amountUSDCDesired,amountTokenADesired,0,0,signer.address,Math.floor(Date.now()/1000)+60*20// 20 minutes from the current Unix time]);console.log(11);awaittx.wait();console.log('Liquidity added');}// We recommend this pattern to be able to use async/await everywhere// and properly handle errors.main().catch((error)=>{console.error(error);process.exitCode=1;});
On await positionManager.connect(signer).mint it fails with the string LOK, which I cannot understand because there are no more calls calling to the pool, its just this code which executes line after line.
This error could be linked to this issue. When creating the pool, the pool gets created without any issue but I have to then close the node running the polygon mainnet fork to execute the same script again also the code does not initialize the pool (hence it is commented out)
The text was updated successfully, but these errors were encountered:
I was having this issue on both Polygon and Mumbai. I created a new pool and then was getting the LOK error trying to mint the first LP position. I ended up resolving it by calling initialize() on the UniswapV3Pool contract. so in this order:
-create new pool
-initialize the pool
-mint new position using NonfungiblePositionManager
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Packages & Versions
Code
I am forking polygon mainnet on hardhat then running it locally, The pool created is betweem USDC and TokenA (a token i created)
On
await positionManager.connect(signer).mint
it fails with the string LOK, which I cannot understand because there are no more calls calling to the pool, its just this code which executes line after line.This error could be linked to this issue. When creating the pool, the pool gets created without any issue but I have to then close the node running the polygon mainnet fork to execute the same script again also the code does not initialize the pool (hence it is commented out)
The text was updated successfully, but these errors were encountered: