Swap

Execute token swaps on Ferra DAMM pools, including fee estimation and pre-swap simulation.

Get Swap Fee

Calculate swap fees before executing:

const pool = await sdk.Pool.getPool(poolId)

// Fee rate from pool
console.log('Fee rate:', pool.feeRate)

// Get available fee tiers
const feeTiers = await sdk.Pool.getBaseFeesAvailable()

feeTiers.forEach(tier => {
  console.log(`Tick spacing: ${tier.tick_spacing}`)
  console.log(`Fee rate: ${tier.fee_rate / 10000000}%`)
})

Estimate Fee from PreSwap

const preSwapResult = await sdk.Swap.preswap({
  pool: pool,
  coinTypeA: pool.coinTypeA,
  coinTypeB: pool.coinTypeB,
  decimalsA: 9,
  decimalsB: 6,
  a2b: true,
  byAmountIn: true,
  amount: '1000000000',
  currentSqrtPrice: pool.currentSqrtPrice
})

console.log('Estimated fee:', preSwapResult.estimatedFeeAmount)

PreSwap

Calculate swap amounts and check price impact before executing trades.

Quick Start

Single Pool PreSwap

Multi-Pool PreSwap

Find best pool for swap:

Calculate Price Impact

Response Types

Compare Pools

Fix Output Amount


Swap

Execute token swaps on Ferra DAMM pools.

Quick Start

Swap Parameters

Parameter
Type
Description

pool_id

string

Pool object ID

coinTypeA

string

Type of coin A

coinTypeB

string

Type of coin B

a2b

boolean

Direction: true = A->B, false = B->A

by_amount_in

boolean

true = fix input, false = fix output

amount

string

Amount to swap

amount_limit

string

Min output (if by_amount_in) or max input

Swap Directions

Swap A to B

Swap B to A

Fix Output Amount

Get exactly the amount you want:

Calculate Slippage

Gas Optimization (SUI)

Optimize gas when swapping SUI:

Partner Swaps

Route fees to partners:

Advanced Usage

Manual Coin Management

Batch Swaps

Complete Example

Error Handling

Important Notes

  • Always use amount_limit for slippage protection

  • SDK automatically handles coin selection

  • Excess coins are returned to sender

  • Partner swaps share fees with partners

  • Gas optimization available for SUI swaps

Last updated