Router Types
The IU2U Protocol supports multiple router types, each optimized for different trading scenarios and requirements. This document explains the various router implementations and their use cases.
Overview
IU2U Protocol implements several router types to handle different trading patterns:
Simple Router - Direct swaps on single DEXes
Multi-hop Router - Complex routes through multiple pools
Cross-chain Router - Routes spanning multiple blockchains
Aggregation Router - Combines multiple DEXes for optimal execution
Split Router - Divides large orders across multiple routes
Flash Router - Atomic multi-step operations using flash loans
Router Architecture
Base Router Interface
All routers implement a common interface for consistency:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
import "./interfaces/IIU2URouter.sol";
interface IIU2URouter {
struct SwapParams {
address tokenIn;
address tokenOut;
uint256 amountIn;
uint256 amountOutMin;
address[] pools;
uint256 deadline;
address recipient;
bytes extraData;
}
struct Route {
address[] tokens;
address[] pools;
uint256[] fees;
bytes[] swapData;
}
function swapExactTokensForTokens(
SwapParams calldata params
) external payable returns (uint256 amountOut);
function getAmountsOut(
uint256 amountIn,
Route calldata route
) external view returns (uint256[] memory amounts);
function quote(
address tokenA,
address tokenB,
uint256 amountIn
) external view returns (uint256 amountOut, Route memory optimalRoute);
function getSupportedDEXes() external view returns (address[] memory);
function getRouterType() external pure returns (string memory);
}Router Registry
1. Simple Router
The Simple Router handles direct swaps on single DEXes with minimal complexity:
2. Multi-hop Router
The Multi-hop Router enables complex routing through multiple intermediary tokens:
3. Cross-chain Router
The Cross-chain Router handles swaps across different blockchains:
4. Aggregation Router
The Aggregation Router combines quotes from multiple DEXes for optimal pricing:
5. Split Router
The Split Router divides large orders to minimize price impact:
6. Flash Router
The Flash Router enables atomic multi-step operations using flash loans:
Router Selection Strategy
Performance Comparison
Simple
Direct swaps
150k gas
1-2 blocks
Low
Multi-hop
No direct pair
300k gas
1-2 blocks
Medium
Cross-chain
Different chains
400k+ gas
5-30 minutes
High
Aggregation
Best price
500k gas
2-3 blocks
Medium
Split
Large orders
200k per split
Variable
Medium
Flash
Arbitrage
600k gas
1 block
High
Best Practices
Router Selection: Choose based on trade characteristics and user preferences
Gas Optimization: Consider gas costs relative to trade size
Slippage Management: Set appropriate slippage tolerances for each router type
Error Handling: Implement robust fallback mechanisms
Security: Validate all external calls and user inputs
Resources
Last updated

