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
add liquidity with fixed coin amount
1. add liquidity with a specified liquidity
Use sdk.Position.createAddLiquidityPayload() method.
Function Parameters
pool_id: The object id about which pool you want to operationpos_id: The object id about position.max_amount_a: The max limit about used coin a amount.max_amount_b: The max limit about used coin b amount.delta_liquidity: The actual change in liquidity that has been added.tick_lower: Represents the index of the lower tick boundarytick_upper: Represents the index of the upper tick boundarycollect_fee: If you already has one position, you can select collect fees while adding liquidity.rewarder_coin_types: If these not empty, it will collect rewarder in this position, if you already open the position.
Important Notes
How to Calculate delta_liquidity, max_amount_a, and max_amount_b ?
delta_liquidity, max_amount_a, and max_amount_b ?you can set fixed two coin amount you want to use.
use
ClmmPoolUtil.estLiquidityAndCoinAmountFromOneAmounts()to calculated the delta_liquidity.Apply price slippage adjustment to the two coin amounts(max_amount_a and max_amount_b) calculated above by method
adjustForCoinSlippage
Example
2. Add liquidity with a fixed coin amount
Use sdk.Position.createAddLiquidityFixTokenPayload() method.
Function Parameters
pool_id: The object id about which pool you want to operationcoin_type_a: The coin type address about coinAcoin_type_b: The coin type address about coinBtick_lower: Represents the index of the lower tick boundarytick_upper: Represents the index of the upper tick boundaryis_open: true means if first add liquidity, so needs open one positionpos_id: The object id about positionfix_amount_a: true means fixed coinA amount, false means fixed coinB amountslippage: Price slippage point.amount_a: If fixed amount A, you must set amount_a, amount_b will be auto calculated byClmmPoolUtil.estLiquidityAndCoinAmountFromOneAmounts()amount_b: If fixed amount B, you must set amount_b, amount_a will be auto calculated byClmmPoolUtil.estLiquidityAndCoinAmountFromOneAmounts()collect_fee: If you already has one position, you can select collect fees while adding liquidityrewarder_coin_types: If these not empty, it will collect rewarder in this position, if you already open the position
Important Notes
The tick index must be an integer multiple of tickSpacing. If the provided parameter is not a multiple of tickSpacing, the contract will throw an error.
-443636 < tick_lower_index < tick_upper_index < 443636, 443636 is a constant, derived from the maximum range representable by the Q32.62 fixed-point number format.If you know price range, you can use
TickMath.priceToTickIndex()to transform real price to tick index.You can just open one position near the current price of the pool, use
TickMath.getPrevInitializeTickIndex()andTickMath.getNextInitializeTickIndex()to find the next initialized tick.If you want to add global liquidity, you can set:
tick_lower_index = -443636 + (443636 % tick_spacing)tick_upper_index = 443636 - (443636 % tick_spacing)
Last updated