# Create clmm pool

Everyone can create cetus clmm pools directly.&#x20;

## 1. Create a clmm pool with some initial liquidity to be added

#### sdk.Pool.createPoolTransactionPayload()

#### Function input params

*Please refer to the original function for specific parameter types.*

* **`tick_spacing`**: 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   |
  | 10           | 0.0005   |
  | 20           | 0.001    |
  | 60           | 0.0025   |
  | 200          | 0.01     |
  | 220          | 0.02     |
* **`initialize_sqrt_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()`.
* **`uri`**: the icon of pool, it's allows null.
* **`coin_type_a`**: the coin type address about coinA.
* **`coin_type_b`**: the coin type address about coinB.

{% hint style="info" %}
**How to determine coinTypeA and coinTypeB ?**

1. **Complete the Coin Type**: Before comparing, ensure that the coin type is complete.
2. **Character-by-Character Comparison**: Start from the first character and compare the characters of the two coins' coinType addresses one by one.
3. **ASCII Value Comparison**: When encountering differing characters, compare their ASCII values. The coin corresponding to the character with the larger ASCII value is considered "coin a".

**Example 1**:

* **coinTypeA**:`0x6864a6f921804860930db6ddbe2e16acdf8504495ea7481637a1c8b9a8fe54b::cetus::CETUS`
* **coinTypeB**:`0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI`

**Example 2**:

* **coinTypeA**:`0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC`
* **coinTypeB**:`0xc060006111016b8a020ad5b33834984a437aaa7d3c74c18e09a95d48aceab08c::coin::COIN`
  {% endhint %}

#### Example

* **`amount_a`**: the amount about coin A, which used to add liquidity.
* **`amount_b`**: the amount about coin B, which used to add liquidity.

  *Notice: amount a and b was calculated by `ClmmPoolUtil.estLiquidityAndcoinAmountFromOneAmounts()`, it will affected by selected tick interval、amount about one fixed coin(coinA or coinB)、current sqrt price of pool and allowed price slippage. You can see the usage in the next example.*
* **`fix_amount_a`**: `true` means fixed coinA amount, `false` means fixed coinB amount.
* **`tick_lower`**: Represents the index of the lower tick boundary.
* **`tick_upper`**: 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 %}

- **`metadataA:`** The coin metadata id of the coin a.
- **`metadataB:`** The coin metadata id of the coin b.

#### Example

<pre class="language-ts"><code class="lang-ts">import BN from 'bn.js'
import { ClmmPoolUtil, initCetusSDK, TickMath } from '@cetusprotocol/cetus-sui-clmm-sdk'
import { SuiClient } from '@mysten/sui/client'

const sdk = initCetusSDK({network: 'mainnet'})

const signer = ... // set keypair
sdk.senderAddress = signer.getPublicKey().toSuiAddress() // set sdk.senderAddress
<strong>
</strong><strong>// initialize sqrt_price
</strong>const initialize_sqrt_price = TickMath.priceToSqrtPriceX64(d(1.2),6,6).toString()
const tick_spacing = 2
const current_tick_index = TickMath.sqrtPriceX64ToTickIndex(new BN(initialize_sqrt_price))
// build tick range
const tick_lower = TickMath.getPrevInitializableTickIndex(new BN(current_tick_index).toNumber()
    , new BN(tick_spacing).toNumber())
const tick_upper = TickMath.getNextInitializableTickIndex(new BN(current_tick_index).toNumber()
    , new BN(tick_spacing).toNumber())
// input token amount
const fix_coin_amount = new BN(200)
// input token amount is token a
const fix_amount_a = true
// slippage value 0.05 means 5%
const slippage = 0.05
const cur_sqrt_price = new BN(initialize_sqrt_price)
// Estimate liquidity and token amount from one amounts
const liquidityInput = ClmmPoolUtil.estLiquidityAndcoinAmountFromOneAmounts(
        lowerTick,
        upperTick,
        fix_coin_amount,
        fix_amount_a,
        true,
        slippage,
        cur_sqrt_price
      )
// Estimate  token a and token b amount
const amount_a = fix_amount_a ? fix_coin_amount.toNumber()  : liquidityInput.tokenMaxA.toNumber()
const amount_b = fix_amount_a ? liquidityInput.tokenMaxB.toNumber()  : fix_coin_amount.toNumber()

const coinTypeA = '0x3cfe7b9f6106808a8178ebd2d5ae6656cd0ccec15d33e63fd857c180bde8da75::coin:CetusUSDT'
const coinTypeB = '0x3cfe7b9f6106808a8178ebd2d5ae6656cd0ccec15d33e63fd857c180bde8da75::coin::CetusUSDC'

const coinMetadataAID = await suiClient.getCoinMetadata({coinType: coinTypeA}).id
const coinMetadataBID = await suiClient.getCoinMetadata({coinType: coinTypeB}).id

// build creatPoolPayload Payload
const creatPoolPayload = sdk.Pool.createPoolTransactionPayload({
    coinTypeA,
    coinTypeB,
    tick_spacing: tick_spacing,
    initialize_sqrt_price: initialize_sqrt_price,
    uri: '',
    amount_a,
    amount_b,
    fix_amount_a,
    tick_lower,
    tick_upper,
    metadata_a: coinMetadataAID,
    metadata_b: coinMetadataBID,
  })

 const res = await sendTransaction(signer, creatPoolTransactionPayload, true)
</code></pre>


---

# 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-sdk/features-available/create-clmm-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.
