Add Liquidity With Fixed Coin
Once you have set a suitable tick range, you can proceed to add liquidity to this position. The quantity composition of tokens you need to add is affected by the current price of the pool and the tick interval you have chosen.
Function input params
pid: The object id about which pool you want to operation.
fix_amount_a: true means fixed coinA amount, false means fixed coinB amount
offer_amount_a:If fixed amount A, you must set amountA, amountB will be auto calculated by ClmmPoolUtil.estLiquidityAndcoinAmountFromOneAmounts().
offer_amount_b: f fixed amount B, you must set amountB, amountA will be auto calculated by ClmmPoolUtil.estLiquidityAndcoinAmountFromOneAmounts().
Example
const pool = await sdk.Pool.getPool(poolAddress)
const position = await sdk.Position.getPositionInfo(positionId)
const fix_amount_a = true
const coin_amount = '1000000'
const slippage = 0.1
const curSqrtPrice = new BN(pool.current_sqrt_price)
const tick_lower = position.tick_lower_index
const tick_upper = position.tick_upper_index
const liquidityInput = ClmmPoolUtil.estLiquidityAndcoinAmountFromOneAmounts(
tick_lower,
tick_upper,
new BN(coin_amount),
fix_amount_a,
true,
slippage,
curSqrtPrice
)
const amount_a = fix_amount_a ? coin_amount : liquidityInput.tokenMaxA.toString()
const amount_b = fix_amount_a ? liquidityInput.tokenMaxB.toString() : coin_amount
// Define parameters for adding liquidity by fixing coin
const params: AddLiquidityFixCoinParams = {
pid: positionId,
fix_amount_a,
offer_amount_a: amount_a,
offer_amount_b: amount_b
}
const payload = sdk.Position.addLiquidityPaylod(params)
const respone = await executeTransaction([payload], sdk, key, false)
Last updated