Mint Position (add liquidity)
This is an example of creating a new position in Pangea's pool or depositing additional liquidity in an existing position.
import { ethers } from "ethers";
import {BigNumber} from "@ethersproject/bignumber";
/// concentrated Liquidity Pool Manager address
const poolManagerAddress = "0x000...";
/// web3 Provider (metamask provider / jsonRPC provider / ...)
const provider = ethers.getDefaultProvider();
// Create new position
async function createPosition(
poolAddress:string,
lowerTick:number,
upperTick:number,
amount0Desired:BigNumber,
amount1Desired:BigNumber
) {
const pool = await ConcentratedLiquidityPool__factory.connect(poolAddress, provider);
const token0 = await ERC20__factory.connect(await pool.token0(), provider);
const token1 = await ERC20__factory.connect(await pool.token1(), provider);
const poolManager = await ConcentratedLiquidityPoolManager__factory.connect(positionManagerAddress, provider);
// first, approve
await (await token0.approve(poolManager.address,amount0Desired)).wait();
await (await token1.approve(poolManager.address, amount1Desired)).wait();
// second, mint postion
const tx = await poolManager.mint(
poolAddress,
0, // if the lowerOld is not set, will search and input automatically
lowerTick,
0, // if the upperOld is not set, will search and input automatically
uppterTick,
amount0Desired,
amount1Desired,
0,
0 // if positionId = 0 create new. else, add liquidity to the positionId
);
await tx.wait();
}
Last updated