Routing Engine
How MNMX discovers, evaluates, and executes cross-chain routes.
Path Discovery
Given a source asset on chain A and a destination asset on chain B, the engine builds a tree of all feasible routes:
1findRoutes(1 ETH on Ethereum → SOL on Solana):2
3Direct bridges:4 ├── Wormhole: ETH(Ethereum) → ETH(Solana) → Jupiter → SOL5 ├── deBridge: ETH(Ethereum) → ETH(Solana) → Jupiter → SOL6 └── Allbridge: ETH(Ethereum) → ETH(Solana) → Jupiter → SOL7
8Multi-hop via stablecoins:9 ├── Uniswap(ETH→USDC) → Wormhole(USDC) → Jupiter(USDC→SOL)10 ├── Uniswap(ETH→USDC) → deBridge(USDC) → Jupiter(USDC→SOL)11 └── Uniswap(ETH→USDT) → Allbridge(USDT) → Jupiter(USDT→SOL)12
13Multi-hop via intermediate chains:14 ├── Wormhole(ETH→Arbitrum) → Swap → deBridge(Arbitrum→Solana)15 └── LayerZero(ETH→Base) → Swap → Wormhole(Base→Solana)16
17Total candidate paths: 23Early Pruning
Not all paths are worth evaluating. The engine prunes before the minimax search begins:
- Bridge offline — Skip paths through bridges that are down or congested
- Insufficient liquidity — Skip paths where bridge liquidity is below transfer amount
- Excessive hops — Cap at 4 hops to limit gas accumulation and failure probability
- Dominated paths — Remove paths that are strictly worse than another on all dimensions
Typically reduces 20–50 raw paths to 8–15 viable candidates for minimax evaluation.
State Collection
For each viable path, the StateCollector fetches real-time conditions in parallel:
1// Parallel state collection across all chains and bridges2const states = await Promise.all(3 candidatePaths.map(path => collectPathState(path))4);5
6interface PathState {7 bridgeQuotes: BridgeQuote[]; // Fee, time, liquidity for each bridge hop8 dexQuotes: DexQuote[]; // Swap output, slippage for each DEX hop9 gasEstimates: GasEstimate[]; // Gas cost per chain per transaction10 bridgeHealth: BridgeHealth[]; // Uptime, congestion, recent failures11 timestamp: number; // State freshness12}Worst-Case Modeling
For each path, the engine models adversarial conditions:
| Adversarial Factor | Worst-Case Model |
|---|---|
| Slippage | 2x quoted slippage (liquidity can drain between quote and execution) |
| Gas spikes | 1.5x current gas price (congestion between quote and execution) |
| Bridge delay | 3x median confirmation time |
| MEV extraction | 0.3% of transfer value on vulnerable hops |
| Price movement | 0.5% adverse price change during bridge transit |
The worst-case output for each path is: quoted output minus all worst-case cost adjustments. The minimax score is this worst-case output — the engine picks the path with the highest floor.
Route Execution
Once the optimal route is selected, the RouteExecutorhandles multi-step execution with monitoring:
1Executing: ETH → Uniswap(ETH→USDC) → Wormhole(USDC) → Jupiter(USDC→SOL)2
3Step 1/3: Swap ETH → USDC on Uniswap4 ├── Build transaction5 ├── Simulate (verify output within tolerance)6 ├── Submit and confirm7 └── ✓ Received 3,247.82 USDC8
9Step 2/3: Bridge USDC via Wormhole (Ethereum → Solana)10 ├── Initiate bridge transfer11 ├── Monitor VAA confirmation12 ├── Redeem on Solana13 └── ✓ Received 3,247.82 USDC on Solana (2m 14s)14
15Step 3/3: Swap USDC → SOL on Jupiter16 ├── Fetch quote17 ├── Submit and confirm18 └── ✓ Received 14.12 SOL19
20Result: 1.0 ETH → 14.12 SOL (guaranteed minimum was 13.8 SOL) ✓Failure Handling
If any step fails or conditions degrade beyond tolerance:
- Pre-bridge failure — Revert source chain transaction. No funds at risk.
- Bridge stall — Monitor until completion or timeout. Alert user with options.
- Post-bridge failure — Assets are on destination chain. Re-route the final swap through alternative DEX.
Performance
| Operation | Typical Time |
|---|---|
| Path discovery | <100ms |
| State collection (parallel) | 500ms–2s |
| Minimax evaluation (15 paths) | <50ms |
| Total quote time | 1–3s |
| Execution time | Depends on bridge (30s–20min) |