Create Pool

1. Create pool

Just create one clmmpool, without adding any initial liquidity.

Function input params

  • tick_spacing: tick spacing will affect price precision. Now mainnet exist some different type tick_spacing, they correspond to different fee rates.

    tick spacing
    fee rate

    2

    0.0001

    10

    0.0005

    60

    0.0025

    200

    0.01

  • initialize_sqrt_price: for computational convenience, we use fixed-point numbers to represent square root prices. Use the provided by the SDK transformation price to sqrtPrice: TickMath.priceToSqrtPriceX64().

  • uri: the icon of pool, it's allows null.

  • metadata_a: the metadata address about tokenA.

  • metadata_b: the metadata address about tokenB.

Example

 const token0 = currTokenConfig.USDC
 const token1 = currTokenConfig.USDT
 const tick_spacing = 60
 const initialize_sqrt_price = TickMath.tickIndexToSqrtPriceX64(TickMath.priceToTickIndex(d(1.1), token0.decimals, token1.decimals))

// Define pool creation parameters
 const params : CreatePoolParams = {
      tick_spacing,
      uri: '',
      initialize_sqrt_price: initialize_sqrt_price.toString(),
      metadata_a: token1.metadata,
      metadata_b: token0.metadata
    }

 const payload = sdk.Pool.createPoolPaylod(params)
 const respone = await executeTransaction([payload], sdk, key, false)

2. Create pool and add liquidity

Create one clmmpool and add some initial liquidity simultaneously. (Recommended)

Function input params

  • tick_lower: Represents the index of the lower tick boundary.

  • tick_upper: Represents the index of the upper tick boundary.

  • amount_a: the amount about Token A, which used to add liquidity.

  • amount_b: the amount about Token B, which used to add liquidity. Notice: amount a and b was calculated by ClmmPoolUtil.estLiquidityAndcoinAmountFromOneAmounts(), it will affected by selected tick interval、amount about one fixed Token(TokenA or TokenB)、current sqrt price of pool and allowed price slippage. You can see the usage in the next example.

  • fix_amount_a: true means fixed TokenA amount, false means fixed TokenB amount.

Example

const token0 = currTokenConfig.USDC
const token1 = currTokenConfig.USDT
const tick_spacing = 60
const initialize_price = TickMath.tickIndexToSqrtPriceX64(TickMath.priceToTickIndex(d(1.1), token0.decimals, token1.decimals))

const lowTick = TickPriceData.buildTickPriceData('0.8', tick_spacing, token0, token1)
const highTick = TickPriceData.buildTickPriceData('1.2', tick_spacing, token0, token1)

const fix_amount_a = true
const coin_amount = '1000000'
const slippage = 0.1

const liquidityInput = ClmmPoolUtil.estLiquidityAndcoinAmountFromOneAmounts(
    lowTick.tick,
    highTick.tick,
    new BN(coin_amount),
    fix_amount_a,
    true,
    slippage,
    initialize_price
)

const amount_a = fix_amount_a ? coin_amount : liquidityInput.tokenMaxA.toString()
const amount_b = fix_amount_a ? liquidityInput.tokenMaxB.toString() : coin_amount

// Define parameters for creating a pool with liquidity
const params : CreatePoolWithLiquidityParams= {
    tick_spacing,
    uri: '',
    initialize_price: initialize_price.toString(),
    metadata_a: token1.metadata,
    metadata_b: token0.metadata,
    tick_lower: lowTick.tick,
    tick_upper: highTick.tick,
    amount_a,
    amount_b,
    fix_amount_a
}
const payload = sdk.Pool.createPoolPaylod(params)
const respone = await executeTransaction([payload], sdk, key, false)

Last updated