Add liquidity
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.
There are two situations:
add liquidity with a specified liquidity value
add liquidity with fixed coin amount.
1. Add liquidity with a specified liquidity value
use sdk.Position.createAddLiquidityPayload() method.
Function input params
Please refer to the original function for specific parameter types.
poolID: The object id about which pool you want to operation.posID: The object id about position.maxAmountA: The max limit about used coin a amount.maxAmountB: The max limit about used coin b amount.deltaLiquidity: The actual change in liquidity that has been added.
how to calculate
deltaLiquiditymaxAmountAandmaxAmountB?
you can set fixed two coin amount you want to use.
use
ClmmPoolUtil.estLiquidityAndcoinAmountFromOneAmounts()to calculated thedelataLiquidity.Apply price slippage adjustment to the two coin amounts(
max_amount_aandmax_amount_b) calculated above by methodadjustForCoinSlippage.
Notice: how to calculate deltaLiquidity maxAmountA and maxAmountB ?
tickLower: Represents the index of the lower tick boundary.tickUpper: Represents the index of the upper tick boundary.collectFee: If you already has one position, you can select collect fees while adding liquidity.rewarderCoinTypes: If these not empty, it will collect rewarder in this position, if you already open the position.
Example
2. Add liquidity with a fixed coin amount
This function is the same as open position and add liquidity with fixed coin amount.
Function input params
Please refer to the original function for specific parameter types.
poolID: The object id about which pool you want to operation.coinTypeA: the coin type address about coinA.coinTypeB: the coin type address about coinB.tickLower: Represents the index of the lower tick boundary.tickUpper: Represents the index of the upper tick boundary.
isOpen:truemeans if first add liquidity, so needs open one position.posID: The object id about position.fixAmountA:truemeans fixed coinA amount,falsemeans fixed coinB amountamountA: If fixed amount A, you must setamount_a,amount_bwill be auto calculated byClmmPoolUtil.estLiquidityAndcoinAmountFromOneAmounts().amountB: If fixed amount B, you must setamount_b,amount_awill be auto calculated byClmmPoolUtil.estLiquidityAndcoinAmountFromOneAmounts().Notice:
ClmmPoolUtil.estLiquidityAndcoinAmountFromOneAmounts()calculate result means when fixed one coin amount, another coin amount will change because of pool price change. so it will calculated based on the current pool price and processed with slippage.slippage: Price slippage point.collectFee: If you already has one position, you can select collect fees while adding liquidity.rewarderCoinTypes: If these not empty, it will collect rewarder in this position, if you already open the position.
Example
Last updated