High-performance DEX aggregator using Min-Cost Max-Flow optimization to find mathematically optimal trade routes across 20+ Avalanche DEXes.
Browser Server Backend Services ┌────────────────┐ ┌──────────────┐ ┌─────────────────────────┐ │ Swap UI │────────▶│ quote.php │─────────▶│ mcmf-rust (CLI solver) │ │ Compare UI │────────▶│ external │─────────▶│ Odos, KyberSwap, 0x... │ │ Batch UI │────────▶│ multi.php │─────────▶│ multi (Axum HTTP svc) │ └────────────────┘ │ indexer │─────────▶│ indexer.js (Node.js) │ └──────────────┘ └────────────┬────────────┘ │ Multicall3 batching │ ┌────────────▼────────────┐ │ Avalanche C-Chain │ │ 20+ DEXes, 40+ tokens │ │ GodAggregator contract │ └─────────────────────────┘
The indexer runs as a background daemon maintaining a live snapshot of all DEX pool states on Avalanche. It uses Multicall3 for efficient batch RPC calls, refreshing every ~3 seconds.
The core routing engine models DEX routing as a minimum-cost maximum-flow problem on a directed graph:
The multi-intent service extends single-quote solving with batch processing and Coincidence of Wants (CoW) matching:
When two intents have opposing flows (A→B and B→A), they can be matched internally at a fair clearing price.
This eliminates pool interactions for the matched portion, saving slippage and gas for both parties.
Surplus from internal matching is distributed to participants.
N-party circular matching: A→B, B→C, C→A can all be matched internally without touching pools.
The solver detects ring opportunities across the batch and computes multi-hop clearing prices.
Residual (unmatched) flow is routed through pools via standard MCMF.
GodAggregator.sol — a single Solidity contract (0.8.20) that executes optimized multi-DEX routes on-chain.
frontend/ swap/index.html # Main swap interface with wallet connect compare/index.html # Quote comparison vs 6+ aggregators batch/index.html # Batch intent UI with CoW visualization api/ quote.php # Proxies to Rust solver CLI multi.php # Proxies to multi-intent Axum service indexer.php # Proxies to indexer health + refresh quotes-external.php # Fetches from Odos, KyberSwap, 0x, etc. quotes-assemble.php # Transaction calldata assembly indexer/ index.js # Main orchestrator + boot logic discovery.js # One-time V1/LB pool discovery state.js # State management, LB bin math, cache ws.js # WebSocket block subscription + events server.js # HTTP API (/state, /health) rpc.js # Provider, Multicall3, ABI interfaces protocols.js # Protocol configs + DEX ABIs solver/ # Proprietary — not included in this repo contracts/ src/GodAggregator.sol # Multi-DEX router (669 lines, 15 DEX types) src/interfaces/ # 17 DEX interface files foundry.toml # Foundry config (Solidity 0.8.20)
The Rust solver (MCMF optimizer + multi-intent service) is proprietary and not included in this repository.