Create Pool
1. Create pool direct
For general pool creation, use the create_pool_v3 or create_pool_v2 function in the pool_creator module.
Coin amount must be exactly what you want to deposit. For example, if
fix_amount_ais true, the amount of coin A must match the exact amount you want to add.It's more recommended to use
create_pool_v3because Sui's coinmetadata mechanism has been updated. Some coins' coinmetadata has already been destroyed, and now it is allowed to create pools without using coin metadata.
Note that the
Function params
config: the reference of clmm globalconfig object. you can see details at Global Config IDpools: The indexer of all pools. Pools IDtickSpacing: tick spacing will affect price precision. Now mainnet exist some different type tick_spacing, they correspond to different fee rates.tick spacingfee rate2
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 transformationpricetosqrtPrice: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.
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.(don't need increate_pool_v3)metadata_b: The metadata object of coin b.(don't need increate_pool_v3)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_v3<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>,
fix_amount_a: bool,
clock: &Clock,
ctx: &mut TxContext,
): (Position, Coin<CoinTypeA>, Coin<CoinTypeB>) {
...
}
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
TreasuryCapof the coinThe
TreasuryCapmust not be frozenOnly one
PoolCreationCapcan be minted per coin
Steps to create a restricted pool:
Mint a
PoolCreationCapusing your coin'sTreasuryCapRegister a pool by specifying: Quote coin and Tick spacing.
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
);
or
let (lp_position, return_coin_a, return_coin_b) = pool_creator::create_pool_v3_with_creation_cap<T, SUI>(
clmm_global_config,
clmm_pools,
pool_creator_cap,
200,
current_sqrt_price,
string::utf8(b""),
coin_a,
coin_b,
is_fix_a,
clk,
ctx
);Last updated