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 positon and add liquidity (recommended)
In most cases, opening a position and adding liquidity are supposed to be done simultaneously.
1. Open a position only
Use sdk.Position.openPositionTransactionPayload()
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.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.
The tick index must be an integer multiple of
tickSpacing
. If the provided parameter is not a multiple oftickSpacing
, the contract will throw an error.-443636 <
tickLowerIndex
<tickUpperIndex
< 443636, 443636 is a constant, derived from the maximum range representable by the Q32.62 fixed-point number format.If you know price range, then 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.getPrevInitializableTickIndex()
andTickMath.getNextInitializableTickIndex()
to find the next initialized tick.If you want to add global liquidity, you can set
tickLowerIndex
= - 443636 + (443636 % tick_spacing),tickUpperIndex
= 443636 - (443636 % tick_spacing)
Example:
2. Open position with add liquidity
Use sdk.Position.createAddLiquidityFixTokenPayload()
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.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.
The tick index must be an integer multiple of
tickSpacing
. If the provided parameter is not a multiple oftickSpacing
, the contract will throw an error.-443636 <
tickLowerIndex
<tickUpperIndex
< 443636, 443636 is a constant, derived from the maximum range representable by the Q32.62 fixed-point number format.If you know price range, then 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.getPrevInitializableTickIndex()
andTickMath.getNextInitializableTickIndex()
to find the next initialized tick.If you want to add global liquidity, you can set
tickLowerIndex
= - 443636 + (443636 % tick_spacing),tickUpperIndex
= 443636 - (443636 % tick_spacing)
isOpen
:true
means if first add liquidity, so needs open one position.posID
: The object id about position.fixAmountA
:true
means fixed coinA amount,false
means fixed coinB amountamountA
: If fixed amount A, you must setamountA
,amountB
will be auto calculated byClmmPoolUtil.estLiquidityAndcoinAmountFromOneAmounts()
.amountB
: If fixed amount B, you must setamountB
,amountA
will be auto calculated byClmmPoolUtil.estLiquidityAndcoinAmountFromOneAmounts()
.
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