Remove liquidity
When you want to adjust the liquidity of your position or withdraw liquidity from the position, you can use the following method. When you withdraw liquidity, you also have the option to collect fees or rewards at the same time. Please refer to the parameter description below for more details.
Function input params
pid: The object id about position.
delta_liquidity: The quantity of liquidity.
min_amount_a: The minimum amount of coin A that a user can acquire.
min_amount_b: The minimum amount of coin B that a user can acquire.
Example
const pool = await sdk.Pool.getPool(poolAddress)
const position = await sdk.Position.getPositionInfo(positionId)
const slippage = 0.01
const curSqrtPrice = new BN(pool.current_sqrt_price)
const tick_lower = position.tick_lower_index
const tick_upper = position.tick_upper_index
const lowerSqrtPrice = TickMath.tickIndexToSqrtPriceX64(tick_lower)
const upperSqrtPrice = TickMath.tickIndexToSqrtPriceX64(tick_upper)
const liquidity = '1000000'
const coinAmounts = ClmmPoolUtil.getCoinAmountFromLiquidity(new BN(liquidity), curSqrtPrice, lowerSqrtPrice, upperSqrtPrice, true)
const min_amount_a = d(coinAmounts.coinA.toString()).mul(1 - slippage).toFixed(0)
const min_amount_b = d(coinAmounts.coinB.toString()).mul(1 - slippage).toFixed(0)
// Define parameters for removing liquidity
const params: RemoveLiquidityParams = {
pid: position.id,
min_amount_a,
min_amount_b,
delta_liquidity: liquidity
}
const payload = sdk.Position.removeLiquidityPaylod(params)
const respone = await executeTransaction([payload], sdk, key, false)
Last updated