Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.

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:

  1. Open a position only

  2. 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 operation

  • coin_type_a: The coin type address about coinA

  • coin_type_b: The coin type address about coinB

  • tick_lower: Represents the index of the lower tick boundary

  • tick_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() and TickMath.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 operation

  • add_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 A

  • coin_decimals_b: Number of decimal places for coin B

  • price_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 operation

  • coin_type_a: The coin type address about coinA

  • coin_type_b: The coin type address about coinB

  • tick_lower: Represents the index of the lower tick boundary

  • tick_upper: Represents the index of the upper tick boundary

  • is_open: true means if first add liquidity, so needs open one position

  • pos_id: The object id about position

  • fix_amount_a: true means fixed coinA amount, false means fixed coinB amount

  • amount_a: If fixed amount A, you must set amount_a, amount_b will be auto calculated by ClmmPoolUtil.estLiquidityAndCoinAmountFromOneAmounts()

  • amount_b: If fixed amount B, you must set amount_b, amount_a will be auto calculated by ClmmPoolUtil.estLiquidityAndCoinAmountFromOneAmounts()

  • collect_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

  • 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() and TickMath.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 operation

  • add_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 A

  • coin_decimals_b: Number of decimal places for coin B

  • price_base_coin: Base coin for price calculation ('coin_a' or 'coin_b')

Example

Use sdk.Position.createAddLiquidityFixTokenPayload() method.

Last updated