Skip to main content
Slippage protection ensures your swaps execute within acceptable price bounds, protecting you from unfavorable price movements between quote and execution.

What is slippage?

Slippage is the difference between the expected price of a trade and the actual execution price. It occurs when:
  • Market prices move between getting a quote and executing
  • Large trades create price impact in liquidity pools
  • Network congestion delays transaction execution
  • Other trades execute before yours
Without slippage protection, your swap may execute at a much worse price than expected, or fail entirely.

Slippage tolerance

The SDK provides two ways to set slippage tolerance:

Fixed slippage percentage

Set a specific maximum slippage percentage:
const quote = await client.dex.getQuote({
  chainIndex: '8453',
  fromTokenAddress: '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE',
  toTokenAddress: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',
  amount: '1000000000000000000',
  slippagePercent: '0.005'  // 0.5% slippage tolerance
});
Common slippage values:
ValuePercentageUse case
0.0010.1%Stablecoin swaps, high liquidity pairs
0.0050.5%Standard swaps, moderate liquidity
0.011%Volatile tokens, lower liquidity
0.033%Very volatile tokens, very low liquidity

Auto slippage

Let the SDK automatically calculate optimal slippage based on market conditions:
const quote = await client.dex.getQuote({
  chainIndex: '8453',
  fromTokenAddress: '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE',
  toTokenAddress: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',
  amount: '1000000000000000000',
  autoSlippage: true,
  maxAutoSlippagePercent: '0.05'  // Maximum 5% auto slippage
});
Auto slippage analyzes current market volatility and liquidity to set the optimal slippage tolerance, while respecting your maximum limit.

Price impact protection

Price impact is different from slippage - it’s the effect your trade has on the market price due to your trade size:
const quote = await client.dex.getQuote({
  chainIndex: '8453',
  fromTokenAddress: '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE',
  toTokenAddress: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',
  amount: '1000000000000000000',
  slippagePercent: '0.005',
  priceImpactProtectionPercent: '0.03'  // Reject if price impact > 3%
});
The trade will be rejected if the price impact exceeds 3%.

Check price impact

Always check the price impact in your quote before executing:
const quote = await client.dex.getQuote({
  chainIndex: '8453',
  fromTokenAddress,
  toTokenAddress,
  amount,
  slippagePercent: '0.005'
});

const priceImpact = parseFloat(quote.data[0].priceImpactPercent);

console.log(`Price impact: ${priceImpact}%`);

if (priceImpact > 3) {
  console.warn('⚠️ High price impact! Consider reducing trade size.');
}

if (priceImpact > 5) {
  throw new Error('Price impact too high - aborting trade');
}

Minimum receive amount

The SDK calculates the minimum amount you’ll receive based on your slippage tolerance:
const swapData = await client.dex.getSwapData({
  chainIndex: '8453',
  fromTokenAddress,
  toTokenAddress,
  amount,
  slippagePercent: '0.005',
  userWalletAddress
});

const minReceive = swapData.data[0].tx.minReceiveAmount;
const expectedReceive = swapData.data[0].routerResult.toTokenAmount;

console.log(`Expected: ${expectedReceive}`);
console.log(`Minimum: ${minReceive}`);
console.log(`Difference: ${(1 - parseFloat(minReceive) / parseFloat(expectedReceive)) * 100}%`);
The transaction will revert if you receive less than minReceiveAmount.

Slippage strategies

For risk-averse users or high-value trades:
const swapData = await client.dex.getSwapData({
  chainIndex: '8453',
  fromTokenAddress,
  toTokenAddress,
  amount,
  slippagePercent: '0.001',  // 0.1% slippage
  priceImpactProtectionPercent: '0.01',  // 1% max price impact
  userWalletAddress
});
Conservative slippage may cause transactions to fail in volatile markets. Be prepared to retry with higher slippage.

Handling slippage failures

When a transaction fails due to slippage:
try {
  const result = await client.dex.executeSwap({
    chainIndex: '8453',
    fromTokenAddress,
    toTokenAddress,
    amount,
    slippagePercent: '0.005',
    userWalletAddress
  });
  
  console.log('Swap successful:', result.transactionId);
  
} catch (error: any) {
  if (error.message?.includes('slippage') || error.message?.includes('Slippage')) {
    console.error('Transaction failed due to slippage');
    
    // Retry with higher slippage
    console.log('Retrying with 1% slippage...');
    
    const retryResult = await client.dex.executeSwap({
      chainIndex: '8453',
      fromTokenAddress,
      toTokenAddress,
      amount,
      slippagePercent: '0.01',  // Increased from 0.5% to 1%
      userWalletAddress
    });
    
    console.log('Retry successful:', retryResult.transactionId);
  } else {
    throw error;
  }
}

Dynamic slippage based on trade size

Adjust slippage tolerance based on trade size:
function calculateSlippage(amountUSD: number): string {
  if (amountUSD < 100) {
    return '0.005';  // 0.5% for small trades
  } else if (amountUSD < 1000) {
    return '0.01';   // 1% for medium trades
  } else {
    return '0.03';   // 3% for large trades
  }
}

const amountInUSD = 5000;  // $5,000 trade
const slippage = calculateSlippage(amountInUSD);

const swapData = await client.dex.getSwapData({
  chainIndex: '8453',
  fromTokenAddress,
  toTokenAddress,
  amount,
  slippagePercent: slippage,
  userWalletAddress
});

Best practices

Review price impact before executing to avoid excessive losses:
const quote = await client.dex.getQuote({
  chainIndex: '8453',
  fromTokenAddress,
  toTokenAddress,
  amount,
  slippagePercent: '0.005'
});

const priceImpact = parseFloat(quote.data[0].priceImpactPercent);

// Warn user if price impact is high
if (priceImpact > 1) {
  const confirmed = await confirmHighImpact(priceImpact);
  if (!confirmed) {
    throw new Error('User cancelled high impact trade');
  }
}
Let the SDK optimize slippage in fast-moving markets:
const swapData = await client.dex.getSwapData({
  chainIndex: '8453',
  fromTokenAddress,
  toTokenAddress,
  amount,
  autoSlippage: true,
  maxAutoSlippagePercent: '0.05',
  userWalletAddress
});
Use slippage protection together with MEV protection for maximum security:
// Get swap with slippage protection
const swapData = await client.dex.getSwapData({
  chainIndex: '8453',
  fromTokenAddress,
  toTokenAddress,
  amount,
  slippagePercent: '0.005',
  priceImpactProtectionPercent: '0.03',
  userWalletAddress
});

// Execute with MEV protection
const signedTx = await wallet.signTransaction(transaction);

await client.dex.broadcastTransaction({
  signedTx,
  chainIndex: '8453',
  address: walletAddress,
  enableMevProtection: true
});

Next steps

MEV protection

Protect against front-running and sandwich attacks

Custom routes

Control which DEXs are used for swaps

Quote API

Get price quotes with slippage parameters

Error handling

Handle slippage and other errors

Build docs developers (and LLMs) love