# 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.

{% hint style="success" %}

1. 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.
2. It's more recommended to use `create_pool_v3` because 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.
   {% endhint %}

Note that the&#x20;

### Function params

* **`config`**: the reference of clmm globalconfig object. you can see details at [#global-config-id](https://cetus-1.gitbook.io/cetus-developer-docs/developer/getting-started#global-config-id "mention")
* **`pools`**: The indexer of all pools. [#pools-id](https://cetus-1.gitbook.io/cetus-developer-docs/developer/getting-started#pools-id "mention")
* **`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.

{% hint style="info" %}

* 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.
  {% endhint %}

* **`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 in `create_pool_v3`)

* **`metadata_b`**: The metadata object of coin b.(don't need in `create_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.

<pre class="language-rust"><code class="lang-rust">public fun create_pool_v3&#x3C;CoinTypeA, CoinTypeB>(
    config: &#x26;GlobalConfig,
    pools: &#x26;mut Pools,
    tick_spacing: u32,
    initialize_price: u128,
    url: String,
    tick_lower_idx: u32,
    tick_upper_idx: u32,
    coin_a: Coin&#x3C;CoinTypeA>,
    coin_b: Coin&#x3C;CoinTypeB>,
    fix_amount_a: bool,
    clock: &#x26;Clock,
    ctx: &#x26;mut TxContext,
): (Position, Coin&#x3C;CoinTypeA>, Coin&#x3C;CoinTypeB>) {
        ...
}
<strong>
</strong><strong>public fun create_pool_v2&#x3C;CoinTypeA, CoinTypeB>(
</strong>        config: &#x26;GlobalConfig,
        pools: &#x26;mut Pools,
        tick_spacing: u32,
        initialize_price: u128,
        url: String,
        tick_lower_idx: u32,
        tick_upper_idx: u32,
        coin_a: Coin&#x3C;CoinTypeA>,
        coin_b: Coin&#x3C;CoinTypeB>,
        metadata_a: &#x26;CoinMetadata&#x3C;CoinTypeA>,
        metadata_b: &#x26;CoinMetadata&#x3C;CoinTypeB>,
        fix_amount_a: bool,
        clock: &#x26;Clock,
        ctx: &#x26;mut TxContext
):  (Position, Coin&#x3C;CoinTypeA>, Coin&#x3C;CoinTypeB>) {
        ...
}
</code></pre>

## 2. Register then create pool&#x20;

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.

```rust
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
);
```
