Create clmm pool

Everyone can create cetus clmm pools directly. There are following ways to create clmmpool.

  1. Just create one clmmpool, without adding any initial liquidity.

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

  3. create pools in batch

1. Create a clmm pool without adding initial liquidity

Function input params

Please refer to the original function for specific parameter types.

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

    tick spacingfee rate

    2

    0.0001

    10

    0.0005

    60

    0.0025

    200

    0.01

  • initializeSqrtPrice: 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.

  • coinTypeA: the coin type address about coinA.

  • coinTypeB: the coin type address about coinB.

    Notice: The lexicographical order of coinTypeA must be less than that of coinTypeB.

Example:

sdk.senderAddress = buildTestAccount().getPublicKey().toSuiAddress()
const paramss: CreatePoolParams = {
  tick_spacing: 2,
  initialize_sqrt_price: TickMath.priceToSqrtPriceX64(
    d(1.01),
    6,
    6
  ).toString(),
  uri: '',
  coinTypeA: `0x3cfe7b9f6106808a8178ebd2d5ae6656cd0ccec15d33e63fd857c180bde8da75::coin:CetusUSDT`,
  coinTypeB: `0x3cfe7b9f6106808a8178ebd2d5ae6656cd0ccec15d33e63fd857c180bde8da75::coin::CetusUSDC`,
}

const creatPoolTransactionPayload = await sdk.Pool.creatPoolTransactionPayload(paramss)
const transferTxn = await sdk.fullClient.sendTransaction(buildTestAccount(), creatPoolTransactionPayload)

2. Create a clmm pool with some initial liquidity to be added

Function input params

Please refer to the original function for specific parameter types.

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

    tick spacingfee rate

    2

    0.0001

    10

    0.0005

    60

    0.0025

    200

    0.01

  • initializeSqrtPrice: 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.

  • coinTypeA: the coin type address about coinA.

  • coinTypeB: the coin type address about coinB. Notice: The lexicographical order of coinTypeA must be less than that of coinTypeB.

  • amountA: the amount about coin A, which used to add liquidity.

  • amountB: the amount about coin 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 coin(coinA or coinB)、current sqrt price of pool and allowed price slippage. You can see the usage in the next example.

  • fixAmountA: true means fixed coinA amount, false means fixed coinB amount.

  • 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 of tickSpacing, 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.

Example

// initialize sqrt_price
const initialize_sqrt_price = TickMath.priceToSqrtPriceX64(d(1.2),6,6).toString()
const tick_spacing = 2
const current_tick_index = TickMath.sqrtPriceX64ToTickIndex(new BN(initialize_sqrt_price))
// build tick range
const lowerTick = TickMath.getPrevInitializableTickIndex(new BN(current_tick_index).toNumber()
    , new BN(tick_spacing).toNumber())
const upperTick = TickMath.getNextInitializableTickIndex(new BN(current_tick_index).toNumber()
    , new BN(tick_spacing).toNumber())
// input token amount
const fix_coin_amount = new BN(200)
// input token amount is token a
const fix_amount_a = true
// slippage value 0.05 means 5%
const slippage = 0.05
const curSqrtPrice = new BN(pool.current_sqrt_price)
// Estimate liquidity and token amount from one amounts
const liquidityInput = ClmmPoolUtil.estLiquidityAndcoinAmountFromOneAmounts(
        lowerTick,
        upperTick,
        fix_coin_amount,
        fix_amount_a,
        true,
        slippage,
        curSqrtPrice
      )
// Estimate  token a and token b amount
const amount_a = fix_amount_a ? fix_coin_amount.toNumber()  : liquidityInput.tokenMaxA.toNumber()
const amount_b = fix_amount_a ? liquidityInput.tokenMaxB.toNumber()  : fix_coin_amount.toNumber()

// build creatPoolPayload Payload
const creatPoolPayload = sdk.Pool.creatPoolTransactionPayload({
    coinTypeA: `0x3cfe7b9f6106808a8178ebd2d5ae6656cd0ccec15d33e63fd857c180bde8da75::coin:CetusUSDT`,
    coinTypeB: `0x3cfe7b9f6106808a8178ebd2d5ae6656cd0ccec15d33e63fd857c180bde8da75::coin::CetusUSDC`,
    tick_spacing: tick_spacing,
    initialize_sqrt_price: initialize_sqrt_price,
    uri: '',
    amount_a: amount_a,
    amount_b: amount_b,
    fix_amount_a: fix_amount_a,
    tick_lower: lowerTick,
    tick_upper: upperTick
  })

 // send the transaction
 const transferTxn = await sendTransaction(signer, creatPoolTransactionPayload,true)
 console.log('doCreatPool: ', transferTxn)

3. Batch create pools

Function input params

Please refer to the original function for specific parameter types.

Each subsequent parameter is identical to the parameters used when creating a pool. However, you can use an array of CreatePoolParams.

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

    tick spacingfee rate

    2

    0.0001

    10

    0.0005

    60

    0.0025

    200

    0.01

  • initializeSqrtPrice: 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.

  • coinTypeA: the coin type address about coinA.

  • coinTypeB: the coin type address about coinB.

    Notice: The lexicographical order of coinTypeA must be less than that of coinTypeB.

Example

const signer = new RawSigner(buildTestAccount(), sdk.fullClient)

// build creatPoolPayload Payload
const creatPoolPayload0 = sdk.Pool.creatPoolTransactionPayload({
    coinTypeA: `0x3cfe7b9f6106808a8178ebd2d5ae6656cd0ccec15d33e63fd857c180bde8da75::coin:CetusUSDT`,
    coinTypeB: `0x3cfe7b9f6106808a8178ebd2d5ae6656cd0ccec15d33e63fd857c180bde8da75::coin::CetusUSDC`,
    tick_spacing: tick_spacing0,
    initialize_sqrt_price: initialize_sqrt_price0,
    uri: '',
    amount_a: amount_a,
    amount_b: amount_b,
    fix_amount_a: fix_amount_a,
    tick_lower: lowerTick,
    tick_upper: upperTick
  })

const creatPoolPayload1 = sdk.Pool.creatPoolTransactionPayload({
  coinTypeA: `0x3cfe7b9f6106808a8178ebd2d5ae6656cd0ccec15d33e63fd857c180bde8da75::coin:CetusUSDT`,
  coinTypeB: `0x3cfe7b9f6106808a8178ebd2d5ae6656cd0ccec15d33e63fd857c180bde8da75::coin::CetusUSDC`,
  tick_spacing: tick_spacing1,
  initialize_sqrt_price: initialize_sqrt_price1,
  uri: '',
  amount_a: amount_a,
  amount_b: amount_b,
  fix_amount_a: fix_amount_a,
  tick_lower: lowerTick,
  tick_upper: upperTick
})

const creatPoolTransactionPayload = await sdk.Pool.creatPoolsTransactionPayload([creatPoolPayload0, creatPoolPayload1])

// send the transaction
const transferTxn = await sdk.fullClient.sendTransaction(sendKeypair, creatPoolTransactionPayload)
console.log('doCreatPool: ', transferTxn)

Last updated