Open Position
Before you want to deposit liquidity, you need to choose an appropriate price range (corresponding to the tick range) to open a position.
There are two situations:
Open a position only
Open position and add liquidity (recommended)
In most cases, opening a position and adding liquidity are supposed to be done simultaneously.
1.1. Open a Position Only with tick range
Use sdk.Position.openPositionPayload() 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 boundary
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)
Example
1.2 Open a Position Only with price range
Use sdk.Position.openPositionWithPricePayload() method.
Required Parameters
pool_id: The object id about which pool you want to operationadd_mode_params: Configuration for price range:For custom range:
{ is_full_range: false, min_price: string, max_price: string , price_base_coin: string }For full range:
{ is_full_range: true }
coin_decimals_a: Number of decimal places for coin Acoin_decimals_b: Number of decimal places for coin Bprice_base_coin: Base coin for price calculation ('coin_a' or 'coin_b')
2.1 Open Position with Add Liquidity by tick range
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 amountamount_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)
Example
2.2 Open Position with Add Liquidity by price range
Use sdk.Position.createAddLiquidityFixCoinWithPricePayload() method.
Function Parameters
pool_id: The object id about which pool you want to operationadd_mode_params: Configuration for price range:For custom range:
{ is_full_range: false, min_price: string, max_price: string , price_base_coin: string, coin_decimals_a: number, coin_decimals_b: number }For full range:
{ is_full_range: true }
coin_decimals_a: Number of decimal places for coin Acoin_decimals_b: Number of decimal places for coin Bprice_base_coin: Base coin for price calculation ('coin_a' or 'coin_b')
Example
Use sdk.Position.createAddLiquidityFixTokenPayload() method.
Last updated