Create Pool

1. Create pool direct

For general pool creation, use the create_pool_v2 function in the pool_creator module.

Note that the coin amount must be exactly what you want to deposit. For example, if fix_amount_a is true, the amount of coin A must match the exact amount you want to add.

Function params

  • config: the reference of clmm globalconfig object. you can see details at Global config id

  • pools: The indexer of all pools.

network
pools object id

mainnet

0xf699e7f2276f5c9a75944b37a0c5b5d9ddfd2471bf6242483b03ab2887d198d0

testnet

0x50eb61dd5928cec5ea04711a2e9b72e5237e79e9fbcd2ce3d5469dc8708e0ee2

  • tickSpacing: 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 (100)

    10

    0.0005 (500)

    20

    0.001 (1000)

    60

    0.0025 (2500)

    200

    0.01 (10000)

    220

    0.02 (20000)

  • initialize_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() in ts SDK.

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

  • tick_lower_idx: I32 type, it's represents the index of the lower tick boundary.

  • tick_upper_idx: I32 type, it's 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 < currentTickIndex<tickUpperIndex < 443636, 443636 is a constant, derived from the maximum range representable by the Q32.62 fixed-point number format.

  • Currently, creating a pool requires adding bidirectional liquidity.

  • coin_a: The coin A object to add liquidity.

  • coin_b: The coin B object to add liquidity.

  • metadata_a: The metadata object of coin a.

  • metadata_b: The metadata object of coin b.

  • fix_amount_a: When adding liquidity, you can select which coin amount to use as the fixed amount. If it's true, use coin a amount, others use coin b amount.

  • clock:clock: the sui clock object.

Types:

  • coinTypeA: the coin type address about coinA.

  • coinTypeB: the coin type address about coinB.

public fun create_pool_v2<CoinTypeA, CoinTypeB>(
        config: &GlobalConfig,
        pools: &mut Pools,
        tick_spacing: u32,
        initialize_price: u128,
        url: String,
        tick_lower_idx: u32,
        tick_upper_idx: u32,
        coin_a: Coin<CoinTypeA>,
        coin_b: Coin<CoinTypeB>,
        metadata_a: &CoinMetadata<CoinTypeA>,
        metadata_b: &CoinMetadata<CoinTypeB>,
        fix_amount_a: bool,
        clock: &Clock,
        ctx: &mut TxContext
):  (Position, Coin<CoinTypeA>, Coin<CoinTypeB>) {
        ...
}

2. Register then create pool

In certain situations, coin issuers may wish to reclaim the ability to create pools. To accommodate this, the protocol implements a PoolCreationCap mechanism for coin issuers. Here's how it works:

Prerequisites:

  • You must hold the TreasuryCap of the coin

  • The TreasuryCap must not be frozen

  • Only one PoolCreationCap can be minted per coin

Steps to create a restricted pool:

  1. Mint a PoolCreationCap using your coin's TreasuryCap

  2. Register a pool by specifying: Quote coin and Tick spacing.

  3. Create a pool by PoolCreationCap.

The protocol controls which quote coins and tick_spacing values are permitted for pool registration. Currently, only pools with the SUI-200 can be registered.

let pool_creator_cap = factory::mint_pool_creation_cap<T>(
    clmm_global_config,
    clmm_pools,
    &mut treasury_cap,
    ctx
);

factory::register_permission_pair<T, SUI>(
    clmm_global_config,
    clmm_pools,
    200,
    &pool_creator_cap,
    ctx
);

let (lp_position, return_coin_a, return_coin_b) = pool_creator::create_pool_v2_with_creation_cap<T, SUI>(
  clmm_global_config,
  clmm_pools,
  pool_creator_cap,
  200,
  current_sqrt_price,
  string::utf8(b""),
  coin_a,
  coin_b,
  metadata_a,
  metadata_b,
  is_fix_a,
  clk,
  ctx
);

Last updated