# Create Pool

## Create Pool

For general pool creation, use the `create_pool_v3/create_pool_v2/create_pool`    function in the `registry` module.

{% hint style="success" %}
The original `create_pool` relied on the `CoinMetadata` of both coins, so after Sui’s metadata mechanism changed and some `CoinMetadata` got destroyed, it no longer worked for those coins. `create_pool_v2` and `create_pool_v3` both support creating pools **without** coin metadata, and `create_pool_v3` is now recommended. The difference between them is how `global_config` is passed: `create_pool_v2` one uses a mutable reference, and `create_pool_v3` uses an immutable reference.
{% endhint %}

### Function params

* **registry**: the reference to the global registry.

<table><thead><tr><th width="113.15234375">network</th><th>registry object id</th></tr></thead><tbody><tr><td>mainnet</td><td>0xb1d55e7d895823c65f98d99b81a69436cf7d1638629c9ccb921326039cda1f1b</td></tr><tr><td>testnet</td><td>0x319070e26a6809f439d3c4a45e63bf74939c5fe3165de7b65968ee8547f71bd0</td></tr></tbody></table>

* **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

<table><thead><tr><th width="113.15234375">network</th><th>global config object id</th></tr></thead><tbody><tr><td>mainnet</td><td>0xf31b605d117f959b9730e8c07b08b856cb05143c5e81d5751c90d2979e82f599</td></tr><tr><td>testnet</td><td>0x88bb33e9eff2fccab980a0e4b43fc4572abd08f08304d47a20d3e4e99d94d159</td></tr></tbody></table>

* **versioned**: Versioned object for version checking

<table><thead><tr><th width="113.15234375">network</th><th>versioned config object id</th></tr></thead><tbody><tr><td>mainnet</td><td>0x05370b2d656612dd5759cbe80463de301e3b94a921dfc72dd9daa2ecdeb2d0a8</td></tr><tr><td>testnet</td><td>0xa710caae87b2129acc97fbb98ea7011e3137c3291b02c0fcce866d67d5d9e8d0</td></tr></tbody></table>

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

### Types <a href="#types" id="types"></a>

* **`coinTypeA`**: the coin type address about coinA.
* **`coinTypeB`**: the coin type address about coinB.

```rust
/// 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>) {
    ...
}

// // use &GlobalConfig
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>){
    ...
}

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


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://cetus-1.gitbook.io/cetus-developer-docs/developer/via-dlmm-contract/features-available/create-pool.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
