> ## Documentation Index
> Fetch the complete documentation index at: https://docs.onebalance.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Slippage Tolerance Troubleshooting

> Common issues and solutions when implementing slippage tolerance in OneBalance integrations.

This guide covers common issues when implementing slippage tolerance and provides solutions for optimal transaction success rates.

## Parameter Validation

### Invalid Value Type

**Issue**: Getting validation errors when adding slippage tolerance parameter.

```bash Error theme={null}
{
  "error": "Invalid slippageTolerance: must be a positive integer"
}
```

**Cause**: Passing string, float, or negative values instead of positive integer.

```typescript ❌ Wrong theme={null}
const request = {
  slippageTolerance: "100"    // String
  slippageTolerance: 1.5      // Float  
  slippageTolerance: -50      // Negative
};
```

```typescript ✅ Correct theme={null}
const request = {
  slippageTolerance: 100      // Positive integer in basis points
};
```

### Value Too High

**Issue**: Setting slippage tolerance above reasonable levels.

```typescript ❌ Wrong theme={null}
const request = {
  slippageTolerance: 1500     // 15% - extremely high
};
```

```typescript ✅ Correct theme={null}
const request = {
  slippageTolerance: 500      // 5% - more reasonable maximum
};
```

## Quote Still Failing

**Issue**: Transactions still failing despite setting slippage tolerance.

| Problem                | Likely Cause                        | Solution                    |
| ---------------------- | ----------------------------------- | --------------------------- |
| **Slippage too low**   | Market moving faster than tolerance | Increase slippage tolerance |
| **Network congestion** | High gas costs affecting execution  | Wait for lower congestion   |
| **Large trade size**   | Price impact exceeding slippage     | Break into smaller trades   |
| **Volatile market**    | Rapid price movements               | Use higher slippage         |

### Simple Retry Pattern

```typescript theme={null}
async function executeWithRetry(baseRequest: QuoteRequest) {
  const slippageValues = [50, 100, 200]; // 0.5%, 1%, 2%
  
  for (const slippage of slippageValues) {
    try {
      const quote = await getQuote({
        ...baseRequest,
        slippageTolerance: slippage
      });
      
      return await executeQuote(quote);
      
    } catch (error: any) {
      console.log(`Failed at ${slippage / 100}% slippage`);
      if (slippage === 200) {
        throw error; // Final attempt failed
      }
    }
  }
}
```

## Choosing Appropriate Values

**Issue**: Unsure what slippage values to use for different scenarios.

### Recommended Values

<CardGroup cols={3}>
  <Card title="Stablecoins" icon="coins">
    **10-50 basis points**

    USDC ↔ USDT: `10` (0.1%)

    DAI ↔ USDC: `25` (0.25%)
  </Card>

  <Card title="Major Tokens" icon="trending-up">
    **50-100 basis points**

    ETH ↔ USDC: `100` (1%)

    BTC ↔ ETH: `100` (1%)
  </Card>

  <Card title="Volatile Assets" icon="zap">
    **100-500 basis points**

    Altcoins: `300` (3%)

    New tokens: `500` (5%)
  </Card>
</CardGroup>

### Asset Classification Helper

```typescript theme={null}
function getRecommendedSlippage(fromAsset: string, toAsset: string): number {
  const stablecoins = ['usdc', 'usdt', 'dai'];
  const majorTokens = ['eth', 'weth', 'btc', 'wbtc'];
  
  const isStablecoin = (asset: string) => 
    stablecoins.some(stable => asset.toLowerCase().includes(stable));
  
  const isMajor = (asset: string) =>
    majorTokens.some(major => asset.toLowerCase().includes(major));

  // Stablecoin to stablecoin
  if (isStablecoin(fromAsset) && isStablecoin(toAsset)) {
    return 25; // 0.25%
  }
  
  // Major token pairs
  if (isMajor(fromAsset) && isMajor(toAsset)) {
    return 100; // 1%
  }
  
  // Default for volatile tokens
  return 300; // 3%
}
```

## Integration Issues

### React State Management

```typescript theme={null}
import { useState } from 'react';

function useSlippageTolerance(defaultSlippage = 100) {
  const [slippage, setSlippage] = useState(defaultSlippage);
  
  const executeWithSlippage = async (quoteRequest: QuoteRequest) => {
    const quote = await getQuote({
      ...quoteRequest,
      slippageTolerance: slippage
    });
    
    return await executeQuote(quote);
  };
  
  return {
    slippage,
    setSlippage,
    executeWithSlippage
  };
}
```

### Basic Error Handling

```typescript theme={null}
async function handleSlippageExecution(request: QuoteRequest) {
  try {
    const quote = await getQuote(request);
    return await executeQuote(quote);
    
  } catch (error: any) {
    console.error('Transaction failed:', error.message);
    
    // Suggest increasing slippage if current value is low
    const currentSlippage = request.slippageTolerance || 0;
    if (currentSlippage < 100) {
      console.log('Consider increasing slippage tolerance to 1% (100 basis points)');
    }
    
    throw error;
  }
}
```

## Best Practices

<Steps>
  <Step title="Start Conservative">
    Begin with 1% (100 basis points) for most use cases
  </Step>

  <Step title="Asset-Specific Values">
    Use lower slippage for stablecoins, higher for volatile tokens
  </Step>

  <Step title="Implement Retry">
    Add automatic retry with progressive slippage increases
  </Step>

  <Step title="Monitor Performance">
    Track success rates and adjust defaults based on real data
  </Step>
</Steps>

## Getting Help

<CardGroup cols={2}>
  <Card title="Still Having Issues?" icon="message-circle">
    Use the **Intercom chat widget** in the bottom right corner for instant help, or email [support@onebalance.io](mailto:support@onebalance.io).
  </Card>

  <Card title="Share Information" icon="bug">
    Include your slippage values, error messages, and asset pair information for faster resolution.
  </Card>
</CardGroup>

<Tip>
  Most issues can be resolved by starting with 100 basis points (1%) and implementing simple retry logic with higher values.
</Tip>
