Create a Pool
Creating a pool in the CPMM V2 protocol is a two-step process:
- Deployment: Uploading the contract code and initial data to the blockchain.
- Initialization: Performing the wallet discovery process to connect the pool with the Jetton assets it will trade.
We provide the @dedust/kit library to simplify these interactions.
1. Pool Configuration
Before deploying, you must define the pool's configuration. This includes the assets to be traded, the fee structure, and how fees are collected.
Use PoolConfig.create from the SDK to generate the configuration object.
import { Asset, FeeIn, PoolConfig } from '@dedust/kit/cpmm-v2';
import { Address } from '@ton/core';
// 1. Define the assets (TON and a Jetton)
const assetX = Asset.native();
const assetY = Asset.jetton(Address.parse('EQ...'));
// 2. Create the configuration
const poolConfig = PoolConfig.create({
assetX,
assetY,
baseFeeBPS: 25, // 0.25% fee
feeIn: FeeIn.assetY(), // Collect fees in Asset Y
});Key Parameters
- Assets: The pair of assets to be traded.
- Fees:
baseFeeBPS: The trading fee in basis points (1 BPS = 0.01%).creatorFeeBPS(optional): An additional fee paid to the pool creator.
- Fee Strategy (
feeIn): Determines whether fees are collected in the input asset (FeeIn.both()), always in Asset X (FeeIn.assetX()), or always in Asset Y (FeeIn.assetY()).
2. Deployment
To deploy the pool, you create a Pool instance from your configuration. The SDK automatically calculates the
deterministic address and the StateInit (code and initial data) required for deployment.
Sending the InitPool message to the calculated address will trigger the deployment and start the initialization
process.
import { Pool } from '@dedust/kit/cpmm-v2';
import { toNano } from '@ton/core';
// 3. Create a Pool instance
// This does not deploy it yet, but calculates the address and init state
const pool = tonClient.open(Pool.fromConfig(poolConfig));
// 4. Send the deployment transaction
await pool.sendInit(sender);3. Initialization Flow
Once the deployment transaction is sent, the pool enters the Initialization phase. In this phase, the pool must " discover" the correct wallet addresses for the Jettons it supports.
This process is automated by the contract logic to adhere to the TEP-89 standard.
Message Flow
The following sequence describes the interactions between the Creator, the Pool, and the Jetton Minter.
- Trigger: The creator sends an
InitPoolmessage (viapool.sendInit). - Discovery:
- The Pool processes the configuration.
- For each Jetton asset, the Pool sends a standard
ProvideWalletAddressmessage to the asset's Minter.
- Resolution:
- The Jetton Minter calculates the wallet address for the Pool and replies with a
TakeWalletAddressmessage. - The Pool stores the resolved wallet address.
- The Jetton Minter calculates the wallet address for the Pool and replies with a
- Completion:
- Once all wallets are resolved, the Pool switches its status to
Initialized. - The Pool sends an
InitPoolResultmessage back to the creator to confirm success.
- Once all wallets are resolved, the Pool switches its status to