Files
smom-dbis-138/docs/bridge/trustless/DEX_INTEGRATION.md

2.7 KiB

DEX Integration Documentation

Overview

This document describes DEX integration for swapping ETH/WETH to stablecoins in the trustless bridge system.

Current Integration

Supported DEXs

  1. Uniswap V3 (Primary)

    • Router: 0xE592427A0AEce92De3Edee1F18E0157C05861564
    • Fee tiers: 0.05%, 0.3%, 1%
    • Direct WETH → Stablecoin swaps
    • Note: the trustless router contracts in this repo call the legacy exactInputSingle ABI directly
  2. Curve (Secondary)

    • 3Pool: 0xbEbc44782C7dB0a1A60Cb6fe97d0b483032FF1C7
    • For stable/stable pairs
    • Note: Requires intermediate swap for WETH
  3. 1inch (Optional)

    • Router: 0x1111111254EEB25477B68fb85Ed929f73A960582
    • Aggregation routing
    • Best rate finding

Integration Improvements

1. 1inch Aggregation

Current: Not fully integrated

Enhancement: Add 1inch router integration

import "./interfaces/IAggregationRouter.sol";

function swapVia1inch(
    address tokenIn,
    address tokenOut,
    uint256 amountIn,
    uint256 amountOutMin,
    bytes calldata swapData
) internal returns (uint256) {
    IERC20(tokenIn).approve(oneInchRouter, amountIn);
    return IAggregationRouter(oneInchRouter).swap(
        tokenIn,
        tokenOut,
        amountIn,
        amountOutMin,
        swapData
    );
}

2. Multi-Hop Swaps

Current: Direct swaps only

Enhancement: Support multi-hop routing

// WETH → USDC → USDT (if better rate)
function swapMultiHop(
    address[] calldata path,
    uint256[] calldata amounts,
    uint24[] calldata fees
) internal returns (uint256) {
    // Execute multiple swaps
}

3. Slippage Protection

Current: Basic amountOutMin parameter

Enhancement: Dynamic slippage based on market conditions

function getDynamicSlippage(uint256 amountIn) public view returns (uint256) {
    uint256 baseSlippage = 50; // 0.5%
    uint256 volatilityMultiplier = getVolatilityMultiplier();
    return baseSlippage * volatilityMultiplier;
}

Supported Stablecoins

Current

  • USDT: 0xdAC17F958D2ee523a2206206994597C13D831ec7
  • USDC: 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48
  • DAI: 0x6B175474E89094C44Da98b954EedeAC495271d0F

Future

  • Additional stablecoins as needed
  • Token whitelist mechanism
  • Dynamic token support

Testing

Test Suite

Create test/bridge/trustless/DEXIntegration.t.sol:

  • Test Uniswap V3 swaps
  • Test Curve swaps
  • Test 1inch aggregation
  • Test multi-hop swaps
  • Test slippage protection

References

  • SwapRouter: contracts/bridge/trustless/SwapRouter.sol
  • Interfaces: contracts/bridge/trustless/interfaces/
  • Test Suite: test/bridge/trustless/DEXIntegration.t.sol