Create Pool

Create Pool

For general pool creation, use the create_pool_v2 or create_pool function in the registry module.

Function params

  • registry: the reference to the global registry.

network
registry object id

mainnet

0xb1d55e7d895823c65f98d99b81a69436cf7d1638629c9ccb921326039cda1f1b

testnet

0x319070e26a6809f439d3c4a45e63bf74939c5fe3165de7b65968ee8547f71bd0

  • metadata_a: Metadata object id for token A.(create_pool_v2 don't need it)

  • metadata_b: Metadata object id for token B.(create_pool_v2 don't need it)

  • bin_step: Bin step configuration for the pool.

  • base_factor: Base factor for the pool configuration

Base fee
Bin Step
Base factor

0.01%

1

10,000

0.02%

1

20,000

0.03%

2

15,000

0.04%

2

20,000

0.05%

5

10,000

0.10%

10

10,000

0.15%

15

10,000

0.20%

20

10,000

0.25%

25

10,000

0.30%

30

10,000

0.40%

50

8,000

0.60%

80

7,500

0.80%

100

8,000

1.00%

100

10,000

2.00%

200

10,000

4.00%

400

10,000

  • active_id: Initial active bin ID for the pool

How to calculate bin id by price?

Formula: bin_id = log(price) / log(1 + bin_step/10000)

Explanation: The bin ID represents which price level (bin) a given price falls into within a geometric sequence. Each bin is (1 + bin_step/10000) times larger than the previous one, where bin_step is measured in basis points (1/10000). The logarithm calculates how many multiplicative steps are needed to reach the target price from the base price of 1.

Example: If bin_step = 20 (0.2%) and price = 1.5, then bin_id = log(1.5) / log(1.002) ≈ 203, meaning the price 1.5 is at the 203rd bin in the geometric price scale.

  • url: URL for pool metadata.

  • config: Reference to the global config for validations

network
global config object id

mainnet

0xf31b605d117f959b9730e8c07b08b856cb05143c5e81d5751c90d2979e82f599

testnet

0x88bb33e9eff2fccab980a0e4b43fc4572abd08f08304d47a20d3e4e99d94d159

  • versioned: Versioned object for version checking

network
versioned config object id

mainnet

0x05370b2d656612dd5759cbe80463de301e3b94a921dfc72dd9daa2ecdeb2d0a8

testnet

0xa710caae87b2129acc97fbb98ea7011e3137c3291b02c0fcce866d67d5d9e8d0

  • clock: Clock object for timestamp operations. (0x6)

Types

  • coinTypeA: the coin type address about coinA.

  • coinTypeB: the coin type address about coinB.

/// Creates a new pool for the specified token pair.
///
/// This function creates a new pool with the given configuration, validates
/// all parameters, and registers it in the global registry.
///
/// ## Type Parameters
/// - `CoinTypeA`: Type of token A in the pool
/// - `CoinTypeB`: Type of token B in the pool
///
/// ## Parameters
/// - `registry`: Mutable reference to the global registry
/// - `metadata_a`: Metadata for token A
/// - `metadata_b`: Metadata for token B
/// - `bin_step`: Bin step configuration for the pool
/// - `base_factor`: Base factor for the pool configuration
/// - `active_id`: Initial active bin ID for the pool
/// - `url`: URL for pool metadata
/// - `config`: Reference to the global config for validations
/// - `versioned`: Versioned object for version checking
/// - `clock`: Clock object for timestamp operations
/// - `ctx`: Transaction context
///
/// ## Returns
/// - `(CreatePoolReceipt, Pool)`: Tuple of receipt and created pool
///
/// ## Errors
/// - `ECoinTypeNotAllowed`: If one or both coin types are not allowed
/// - `EInvalidActiveId`: If active ID is outside valid price range
/// - `ESameCoinType`: If both token types are the same
/// - `EPoolAlreadyExist`: If pool with the same key already exists
/// - `ENoUserOperationPermission`: If sender lacks user operation permission
///
/// ## Events Emitted
/// - `CreatePoolEvent`: Contains pool creation details
public fun create_pool<CoinTypeA, CoinTypeB>(
    registry: &mut Registry,
    metadata_a: &CoinMetadata<CoinTypeA>,
    metadata_b: &CoinMetadata<CoinTypeB>,
    bin_step: u16,
    base_factor: u16,
    active_id: u32,
    url: String,
    config: &mut GlobalConfig,
    versioned: &Versioned,
    clock: &Clock,
    ctx: &mut TxContext,
): (CreatePoolReceipt, Pool<CoinTypeA, CoinTypeB>) {
    ...
}

public fun create_pool_v2<CoinTypeA, CoinTypeB>(
    registry: &mut Registry,
    bin_step: u16,
    base_factor: u16,
    active_id: u32,
    url: String,
    config: &mut GlobalConfig,
    versioned: &Versioned,
    clock: &Clock,
    ctx: &mut TxContext,
): (CreatePoolReceipt, Pool<CoinTypeA, CoinTypeB>){
    abort 1
}

Last updated