Create Pool

1. Default Fee Options

The SDK provides predefined fee configurations for different types of trading pairs. These configurations are optimized based on asset volatility and market characteristics:

  • binStep: The step size between bins, determining the price granularity of the pool. Smaller values provide finer price resolution but require more computational resources.

  • baseFactor: A multiplier used in fee calculations, affecting the overall fee structure of the pool.

  • fee: The trading fee rate as a decimal (e.g., '0.0001' = 0.01%). This is the fee charged for each swap transaction.

Fee Tier Recommendations:

  • Low fees (0.01% - 0.05%): Best for stable pairs or low-volatility mainstream assets

  • Medium fees (0.1% - 0.3%): Suitable for medium-volatility assets or mainstream trading pairs

  • High fees (0.4% - 4%): Recommended for high-volatility assets, altcoins, or small market cap pairs

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

When creating a new pool, choose the fee configuration that best matches your trading pair's characteristics:

// Example: Create a pool for a stable pair (USDC/USDT)
const stablePairConfig = { binStep: 1, baseFactor: 10000, fee: '0.0001' }

// Example: Create a pool for a volatile altcoin pair
const altcoinConfig = { binStep: 100, baseFactor: 10000, fee: '0.01' }

2. Create Pool

There are two ways to create a pool:

Method 1: Create Pool Only

// Create a new pool without adding liquidity
const bin_step = 2
const base_factor = 10000
const price = '1.1'
const active_id = BinUtils.getBinIdFromPrice(price, bin_step, true, 6, 6)

const tx = new Transaction()
await sdk.Pool.createPoolPayload({
  active_id,
  bin_step,
  coin_type_a: '0x...::usdc::USDC',
  coin_type_b: '0x...::usdt::USDT',
  base_factor,
}, tx)

Method 2: Create Pool and Add Liquidity in One Transaction

// Create pool and add liquidity in one transaction
const bin_step = 2
const base_factor = 10000
const price = '1.1'
const active_id = BinUtils.getBinIdFromPrice(price, bin_step, true, 6, 6)

// Calculate liquidity distribution
const bin_infos = sdk.Position.calculateAddLiquidityInfo({
  active_id,
  bin_step,
  lower_bin_id: active_id - 10,
  upper_bin_id: active_id + 10,
  amount_a_in_active_bin: '0',
  amount_b_in_active_bin: '0',
  strategy_type: StrategyType.Spot,
  coin_amount: '10000000',
  fix_amount_a: true,
})

const createAndAddTx = await sdk.Pool.createPoolAndAddLiquidityPayload({
  active_id,
  lower_bin_id: active_id - 10,
  upper_bin_id: active_id + 10,
  bin_step,
  bin_infos,
  coin_type_a: '0x14a71d857b34677a7d57e0feb303df1adb515a37780645ab763d42ce8d1a5e48::usdc::USDC',
  coin_type_b: '0x14a71d857b34677a7d57e0feb303df1adb515a37780645ab763d42ce8d1a5e48::eth::ETH',
  strategy_type: StrategyType.Spot,
  use_bin_infos: false,
  base_factor,
})

Last updated