Turbos
  • 📖About Turbos
    • Getting Started
    • About Turbos Finance
    • Why Sui Network
  • 📽️Products
    • Concentrated Liquidity AMM
      • Fee Tier for Token Pairs
      • Oracle
    • Automated Rebalance Vault
      • Step-by-Step Guide
      • Referral Program
    • TurboStar
    • TurbosBoost
  • 💡Protocol Concepts
    • About Concentrated Liquidity
    • Fee Tiers
    • Glossary
  • 🪙Tokenomics
    • TURBOS
    • Token Utility
    • Emission Distribution
  • ⚙️Others
    • Roadmap
    • Audits
    • Brand kit
    • Risks
    • Token Address
  • Developer Docs
    • Dev Overview
    • via SDK
      • Get Started
      • Initialize SDK
      • Clmm
        • getConfig
        • getFeesConfig
        • getPools
        • getPool
        • createPool
        • createAndAddLiquidity
        • increaseLiquidity
        • decreaseLiquidity
        • removeLiquidityAndBurn
        • preSwap
        • swap
        • collect Fees
        • collect Rewards
        • Fee
        • Liquidity and coin amounts calculation
        • APR calculation
      • Vault
        • createAndDepositVault
        • depositVault
        • withdrawVault
        • withdrawAllVault
        • collectClmmRewardDirectReturnVault
        • closeVault
        • computeTokenWithdrawVaultSwapResult
        • getVaultBalanceAmount
        • getMyVaults
  • Turbos Fun
    • Base
    • Create Pool
    • Calculate Token Amount
    • Buy
    • Sell
  • 📱Socials
    • Official website
    • Twitter
    • Discord
    • Medium
    • Zealy
  • Tutorials
    • Supported Wallets
      • SafePal Wallet
    • Move tutorial
    • Sui tutorial
Powered by GitBook
On this page
  • Signature
  • Params
  • Examples
  1. Developer Docs
  2. via SDK
  3. Clmm

createAndAddLiquidity

This method simultaneously creates a position and adds liquidity. The NFT, which represents the position, will be sent to the creator's address. All subsequent operations will require using the position ID (NFT).

Signature

addLiquidity(options: AddLiquidityOptions): Promise<Transaction>

Params

interface AddLiquidityOptions {
  // pool object ID
  pool: string;
  // Operator address
  address: string;
   // Amount of coin A
  amountA: string | number; 
  // Amount of coin B
  amountB: string | number;
  // Represents the index of the lower tick boundary
  tickLower: number;
  // Represents the index of the upper tick boundary
  tickUpper: number;
  // Acceptable wasted amount percentage. Range: [0, 100)
  slippage: string | number;
  // Expires timeout(ms), defaults 60_000
  deadline?: number;
  // Custom transaction handler
  txb?: Transaction;
}

Examples

const turbosSdk = new TurbosSdk(Network.testnet, {
  url: 'https://fullnode.testnet.sui.io',
});
const signer = turbosSdk.account.getKeypairFromMnemonics("your mnemonic");
const poolId = '0x328572f9d3c99bdb0a2da46fa61ef7917e1d35e67ec9472d412aa82b4a5222b2';
const pool = await turbosSdk.pool.getPool(poolId);
const coinADecimals = 9;
const current_tick_index = turbosSdk.math.sqrtPriceX64ToTickIndex(
  new BN(pool.sqrt_price),
);
const tickLower = turbosSdk.math.getPrevInitializableTickIndex(
  current_tick_index,
  pool.tick_spacing,
);
const tickUpper = turbosSdk.math.getNextInitializableTickIndex(
  current_tick_index,
  pool.tick_spacing,
);
const amountA = 1 * 10 ** coinADecimals;
const amounts = turbosSdk.pool.estimateAmountsFromOneAmount({
  sqrtPrice: pool.sqrt_price,
  tickLower,
  tickUpper,
  amount: amountA.toString(),
  isAmountA: true,
});
const txb = await turbosSdk.pool.addLiquidity({
  pool: poolId,
  amountA: amounts[0],
  amountB: amounts[1],
  address: signer.toSuiAddress(),
  slippage: 10, //10% slippage
  tickLower,
  tickUpper,
});
const result = await turbosSdk.provider.signAndExecuteTransaction({
  transaction: txb,
  signer,
});
console.log(result);
PreviouscreatePoolNextincreaseLiquidity

Last updated 1 day ago