πŸ“šSDK Examples

SummitX DEX Integration Examples

This section provides comprehensive examples for integrating with the SummitX DEX protocol. Our SDK examples demonstrate best practices for token swaps, liquidity provision, and smart routing.

πŸš€ Quick Start Example

For a complete working example, check out our summitx-example repositoryarrow-up-right which includes:

Features

  • Token Swapping: Native to ERC20, ERC20 to Native, and ERC20 to ERC20 swaps

  • Wrap/Unwrap: Convert between native tokens and wrapped tokens

  • Smart Routing: Automatic route finding across V3 and Stable pools

  • Quote System: Real-time quotes with price impact and slippage calculations

  • Multi-hop Support: Find optimal routes through multiple pools

  • Rate Limit Protection: Built-in delays to avoid RPC rate limiting

Installation

# Clone the example repository
git clone https://github.com/summitx/summitx-example
cd summitx-example

# Install dependencies
npm install

# Copy environment file
cp .env.example .env

# Add your private key to .env
# PRIVATE_KEY=your_private_key_here

Basic Usage

πŸ“ Code Examples

Native to ERC20 Swap

ERC20 to ERC20 Swap

Wrap and Unwrap Native Tokens

βš™οΈ Configuration

TokenQuoter Options

Environment Variables

πŸ—οΈ Architecture Overview

TokenQuoter

The main class for getting swap quotes:

  • Fetches pool information from subgraphs

  • Calculates optimal routes using SmartRouter

  • Returns quotes with price impact and slippage

  • Supports both trade and rawTrade properties for compatibility

SmartRouter Integration

  • Uses @summitx/smart-router for route finding

  • Supports V3 and Stable pools

  • Automatic route optimization

  • Multi-hop and split route support

Transaction Flow

  1. Get Quote: Fetch quote from TokenQuoter

  2. Generate Parameters: Create swap parameters using SwapRouter

  3. Token Approval: For ERC20 swaps, approve token spending

  4. Execute Swap: Send transaction to Smart Router contract

  5. Router Processing: Router handles the actual swap execution

πŸ”§ Troubleshooting

Common Issues and Solutions

Rate Limiting (429 errors)

  • Implement delays between operations (5 seconds recommended)

  • Consider using a private RPC endpoint for high-frequency operations

Insufficient Balance

  • Check balances before attempting swaps

  • Ensure enough native tokens for gas fees

  • Native swaps need value + gas, not just gas

No Route Found

  • Some token pairs may not have sufficient liquidity

  • Try smaller amounts or different token pairs

  • Check pool availability on the relevant network

Gas Estimation Failed

  • May indicate insufficient balance

  • Check token approvals are in place

  • Verify swap parameters are correct

Debug Tools

The example repository includes debug utilities:

🀝 Support

For additional help:

⚠️ Security Notice

  • Never share or commit private keys

  • Always test on testnet first

  • Verify contract addresses before mainnet deployment

  • Use appropriate slippage settings for your use case

Last updated