How the Aggregator Works
Step 1: Collect liquidity pool data
It gathers data from connected AMMs:
Direct pools (TokenAβTokenB)
Intermediate pools (via WETH, USDC, etc.)
Supported:
V2 Pools β constant product (x * y = k)
V3 Pools β concentrated liquidity
Order Book β e.g., Kuru
Step 2: Build the route graph
Nodes = tokens
Edges = liquidity pools
Step 3: Find optimal paths
Uses a modified Bellman-Ford algorithm to find up to 4-hop paths and selects the one with the best output.
Step 4: Simulate and calculate
Each route is simulated considering pool fee, liquidity, and slippage.
Route Graph Visualization
Here's how the aggregator maps available liquidity:
Graph Structure:
Nodes: USDT, WMON, USDC, MON (tokens)
Edges: Pool1, Pool2, Pool3, Pool4 (liquidity pools)
Possible Routes (USDT β DAI):
Direct: USDT β Pool2 β USDC β Pool4 β MON
Multi-hop: USDT β Pool1 β WMON β Pool3 β MON
Complex: USDT β Pool1 β WMON β Pool3 β MON + USDT β Pool2 β USDC β Pool4 β MON (split route)
Route Types
1. Direct Route
Single pool: [USDT] β [WMON]
2. Multi-hop Route
Through intermediates: [TokenA] β [WMON] β [TokenB]
3. Split Route
Split across pools: 60% Kuru, 40% Bean
Route Building Process
Pool discovery (5β10 ms)
Graph construction (10β20 ms)
Path search (50β200 ms)
Alternative search (30β100 ms)
Optimization
Weights assigned based on efficiency
Bonuses/penalties:
+15% for direct routes
+5% for V3
β2% per extra hop
Limits:
Max 60% per route
Min 5% per route
Convert to smart contract weights
Example:
Route 1: 60% β 6000
Route 2: 25% β 2500
Route 3: 15% β 1500
Total: 10000 β
Optimization and Distribution
Three strategies compared:
Single best route
Multiple direct routes
Multi-hop combinations
The system picks the strategy with the highest token output.
Slippage example
Expected: 1000 tokens
Fee 0.2% = -2
Slippage 0.5% = -5
β Minimum = 993 tokens
Last updated