RHEON docs
Avalanche C-Chain

Rheon DEX Aggregator

High-performance DEX aggregator using Min-Cost Max-Flow optimization to find mathematically optimal trade routes across 20+ Avalanche DEXes.

1 Architecture Overview

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  
                                                      └─────────────────────────┘
Frontend
HTML/JS/Tailwind — no framework. Swap interface, aggregator comparison, batch trading UI.
3 pages · ethers.js v5 · EIP-6963 wallet discovery
API Layer
Thin PHP proxies between browser and backend services. Input validation, CORS, error handling.
5 endpoints · curl proxying · keepalive signals
Solver (Rust)
MCMF optimizer with zero-alloc hot loops. Pre-allocated SPFA buffers, LTO-optimized builds.
~4,000 lines Rust · 5-30ms latency · v7+v8 dual-solve
Indexer (Node.js)
Real-time pool state daemon. Multicall3 batching, disk caching, activity-based refresh.
~4,300 lines JS · 3s refresh · ethers.js + Multicall3

2 How It Works

Pool State Indexer

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.

Phase 1: Discovery
Sequential multicall scan of all factory contracts to discover V1 and LB pairs. Builds complete pair list with reserve data.
Phase 2: Hot Refresh
JSON-RPC batch updates for all known pools. LB bins refreshed per-pair with 100-bin window. Disk cache for cold restarts.
TraderJoe V1 Pangolin SushiSwap TJ LB v2.1/v2.2 UniV3 PangolinV3 SushiV3 PharaohCL KyberElastic BlackholeCL Curve Platypus Synapse WooFi DODO V2 Balancer V3 Uniswap V4 GMX Solidly forks LydiaFinance

MCMF Solver

The core routing engine models DEX routing as a minimum-cost maximum-flow problem on a directed graph:

// Graph model
Tokens = nodes in the flow network
DEX pools = edges with piecewise-linear cost (price impact)
AMM curves = discretized into capacity-constrained buckets
MCMF = find max output by routing flow through cheapest paths
MCMF Solve
Finds the optimal flow allocation across all available DEX pools simultaneously. Multiple solver strategies are evaluated and the best result is selected.
Refinement
Converts the discrete graph solution back to continuous AMM math for higher precision. Verifies output with forward simulation through actual pool curves.
Iterative Mode
For large trades, runs multiple optimization rounds to account for how the trade itself moves pool prices. Converges toward the true optimal allocation.
Solver Pipeline
Fetch State Build Graph MCMF v7+v8 Refine Pick Best Output

Batch Solver & CoW Matching

The multi-intent service extends single-quote solving with batch processing and Coincidence of Wants (CoW) matching:

Coincidence of Wants (CoW)

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.

Ring Trades

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.

Batch Pipeline
Receive Intents Detect CoW Match Rings MCMF Residuals Results

Smart Contract

GodAggregator.sol — a single Solidity contract (0.8.20) that executes optimized multi-DEX routes on-chain.

// Supports 15 DEX types via internal dispatch
execute() // Multi-step route: [step0, step1, ...] each with DEX type
swapMultiRoute() // Multi-hop through one path via a single router
swapSplit() // Split across multiple V1 DEXes for same pair
swapSimple() // Single-DEX V1 swap
V1 (UniV2) Liquidity Book UniV3 CL Algebra CL Solidly Curve WooFi DODO Balancer V3 Uniswap V4 Platypus Synapse KyberElastic GMX Kyber DMM

3 Performance

5-30ms
Solver latency
~3s
Indexer refresh cycle
20+
DEXes indexed
40+
Tokens supported
Optimization Details
Zero-allocation hot loops — Pre-allocated buffers and compact data structures eliminate heap allocation in the solver's inner loop.
LTO-optimized release builds — Link-time optimization and aggressive inlining. Entire solver fits in CPU cache.
Adaptive graph construction — Pool representation scales with relevance to the trade, balancing solve speed and route quality.
Multi-strategy evaluation — Multiple solver configurations are evaluated and refined. Output always ≥ best direct quote as a safety net.

4 Tech Stack

Rust
Core solver + multi-intent service. serde, ureq, axum, tokio, dashmap.
Node.js
Indexer daemon. ethers.js v5, Multicall3, node-fetch.
Solidity 0.8.20
On-chain aggregator. Foundry toolchain, 200-run optimization.
PHP
Lightweight API proxies. curl, shell_exec for solver CLI.
HTML / JS / Tailwind
Frontend. No framework, minimal deps, dark theme.
Avalanche C-Chain
Target chain (43114). Native support for all major Avalanche DEXes.

5 Repository Structure

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.

Solo developer project — architecture, solver algorithms, smart contracts, indexer, and frontend all built from scratch.
Avalanche Build Games 2026