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
    • Contract Address
  • Developer Docs
    • Installation
    • Initialize SDK
    • Contract
      • getConfig
      • getFees
    • NFT
      • getOwner
      • getFields
      • getPositionFields
      • getPositionFieldsByPositionId
    • Pool
      • getPools
      • getPool
      • createPool
      • addLiquidity
      • increaseLiquidity
      • decreaseLiquidity
      • removeLiquidity
    • Trade
      • swap
      • computeSwapResultV2
    • Vault
      • createAndDepositVault
      • depositVault
      • withdrawVault
      • withdrawAllVault
      • collectClmmRewardDirectReturnVault
      • closeVault
      • computeTokenWithdrawVaultSwapResult
      • getVaultBalanceAmount
      • getMyVaults
  • 📱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. Trade

swap

Swap from one coin to another one with specific pools.

Signature

swap(options: SwapOptions): Promise<Transaction>

Params

interface SwapOptions {
  routes: Array<{
    // Pool object ID
    pool: string;
    // Swap from coinA to coinB
    a2b: boolean;
    // computed next tick index
    nextTickIndex: number;
  }>;
  // Coin A address
  coinTypeA: string;
  // Coin B address
  coinTypeB: string;
  // User's wallet address
  address: string;
  // Amount of coinA
  amountA: string | number;
  // Amount of coinB
  amountB: string | number;
  // When `true`, amountA is input by user. 
  // When `false`, amountB is input by user. 
  amountSpecifiedIsInput: boolean;
  // 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 swapResult = await sdk.trade.computeSwapResultV2(...);
const nextTickIndex = sdk.math.bitsToNumber(swapResult.tick_current_index.bits);
const routes = [{
  pool: '0x2c6fc12bf0d093b5391e7c0fed7e044d52bc14eb29f6352a3fb358e33e80729e',
  a2b: true,
  nextTickIndex,
}];

const tx = await sdk.trade.swap({
  routes,
  coinTypeA: '0x5d1f47ea69bb0de31c313d7acf89b890dbb8991ea8e03c6c355171f84bb1ba4a::turbos::TURBOS',
  coinTypeB: '0x2::sui::SUI',
  amountA: 100,
  amounbB: 225,
  amountSpecifiedIsInput: true,
  slippage: 0.2,
});
PreviousTradeNextcomputeSwapResultV2

Last updated 10 months ago