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
  • Preswap by simulation transaction
  • Signature
  • Params
  • Examples
  1. Developer Docs
  2. via SDK
  3. Clmm

preSwap

To initiate a swap, start with a preliminary swap assessment to understand the potential outcome. Afterward, you can set the amount limit based on the swap result and the slippage tolerance.

Preswap by simulation transaction

Signature

computeSwapResultV2(options: ComputeSwapResultOptionsV2): Promise<Transaction>

Params

interface ComputeSwapResultOptionsV2 {
  pools: Array<{
    // Pool object ID
    pool: string;
    // swap from coinA to coinB
    a2b: boolean;
    amountSpecified: string | number 
  }>;
  // Operator's wallet address
  address: string;
  amountSpecifiedIsInput: boolean;
  tickStep?: number;
}
  • pools : Multiple pools can be passed for prediction, which is particularly useful when there are multiple fee pools with the same token.

  • address : Transaction sender

  • a2b : Swap Direction: A value of true indicates a swap from CoinA to CoinB

  • amountSpecifiedIsInput : true means fixed the amount of input, false means fixed the amount of output

  • tickStep: Represented this pre swap can move up to how many tickSpacing

Examples

const turbosSdk = new TurbosSdk(Network.testnet, {
  url: 'https://fullnode.testnet.sui.io',
});
const signer = turbosSdk.account.getKeypairFromMnemonics("your mnemonic");
const poolId = '0xb32fb8ec0b447a833066496bd7251d3a2ee57a0a97c54bf4cc945a986235582a';
const preSwapResult = await turbosSdk.trade.computeSwapResultV2({
  pools: [
    {
      pool: poolId,
      a2b: true,
      amountSpecified: 1000000,
    },
  ],
  amountSpecifiedIsInput: true,
  tickStep: 100,
  address: signer.toSuiAddress(),
});
console.log(preSwapResult);

Response

[
  {
    a_to_b: true,
    amount_a: '1000000',
    amount_b: '297',
    fee_amount: '10000',
    is_exact_in: true,
    liquidity: '15182876622',
    pool: '0xb32fb8ec0b447a833066496bd7251d3a2ee57a0a97c54bf4cc945a986235582a',
    protocol_fee: '0',
    recipient: '0x9563578937da5bd33657306871057dbe50c18900d300ecd97c93c3cbda2262ed',
    sqrt_price: '319730214661613148',
    tick_current_index: { bits: 4294886188 },
    tick_pre_index: { bits: 4294886188 }
  }
]
PreviousremoveLiquidityAndBurnNextswap

Last updated 2 days ago