Price Impact

Calculate and manage price impact for swaps in CLMM pools.

Quick Start

// Calculate price impact before swap
const pool = await sdk.Pool.getPool(poolId)
const ticks = await sdk.Pool.fetchTicks({
  pool_id: poolId,
  coinTypeA: pool.coinTypeA,
  coinTypeB: pool.coinTypeB
})

const result = sdk.Swap.calculateRates({
  currentPool: pool,
  coinTypeA: pool.coinTypeA,
  coinTypeB: pool.coinTypeB,
  decimalsA: 9,
  decimalsB: 6,
  a2b: true,
  byAmountIn: true,
  amount: new BN('1000000000'), // 1 SUI
  swapTicks: ticks
})

console.log(`Price Impact: ${result.priceImpactPct.toFixed(2)}%`)

Understanding Price Impact

Price impact occurs when your trade moves the pool price:

  • Small trades: Minimal impact (<0.1%)

  • Medium trades: Noticeable impact (0.1-1%)

  • Large trades: Significant impact (>1%)

Calculate Methods

Method 1: Local Calculation

Method 2: From PreSwap

Router Price Impact

Calculate impact across multiple pools:

Impact Thresholds

Set appropriate warnings based on impact:

Minimize Price Impact

1. Split Large Trades

2. Use Multiple Pools

Complete Example

Price Impact Formula

Important Notes

  • Price impact increases with trade size

  • Impact is higher in low liquidity pools

  • Concentrated liquidity affects impact differently

  • Always set appropriate slippage tolerance

  • Consider splitting large trades

  • Monitor impact in real-time for better UX

Last updated