PreSwap
Calculate swap amounts and check price impact before executing trades.
Quick Start
// Simulate swap before execution
const pool = await sdk.Pool.getPool(poolId)
const preSwapResult = await sdk.Swap.preswap({
pool: pool,
coinTypeA: pool.coinTypeA,
coinTypeB: pool.coinTypeB,
decimalsA: 9, // SUI decimals
decimalsB: 6, // USDC decimals
a2b: true, // SUI -> USDC
byAmountIn: true,
amount: '1000000000', // 1 SUI
currentSqrtPrice: pool.current_sqrt_price
})
console.log({
amountIn: preSwapResult.estimatedAmountIn,
amountOut: preSwapResult.estimatedAmountOut,
fee: preSwapResult.estimatedFeeAmount,
priceAfter: preSwapResult.estimatedEndSqrtPrice
})PreSwap Methods
Single Pool PreSwap
Multi-Pool PreSwap
Find best pool for swap:
Calculate Price Impact
Response Types
Usage Examples
Check Slippage
Compare Pools
Fix Output Amount
Important Notes
PreSwap uses simulation for accurate results
Multi-pool automatically finds best execution
isExceedindicates insufficient liquidityAlways check price impact before large swaps
Results include fees in calculations
Last updated