Docs
Docs/Routing Engine

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:

text
1findRoutes(1 ETH on Ethereum → SOL on Solana):
2
3Direct bridges:
4 ├── Wormhole: ETH(Ethereum) → ETH(Solana) → Jupiter → SOL
5 ├── deBridge: ETH(Ethereum) → ETH(Solana) → Jupiter → SOL
6 └── Allbridge: ETH(Ethereum) → ETH(Solana) → Jupiter → SOL
7
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: 23

Early 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:

typescript
1// Parallel state collection across all chains and bridges
2const states = await Promise.all(
3 candidatePaths.map(path => collectPathState(path))
4);
5
6interface PathState {
7 bridgeQuotes: BridgeQuote[]; // Fee, time, liquidity for each bridge hop
8 dexQuotes: DexQuote[]; // Swap output, slippage for each DEX hop
9 gasEstimates: GasEstimate[]; // Gas cost per chain per transaction
10 bridgeHealth: BridgeHealth[]; // Uptime, congestion, recent failures
11 timestamp: number; // State freshness
12}

Worst-Case Modeling

For each path, the engine models adversarial conditions:

Adversarial FactorWorst-Case Model
Slippage2x quoted slippage (liquidity can drain between quote and execution)
Gas spikes1.5x current gas price (congestion between quote and execution)
Bridge delay3x median confirmation time
MEV extraction0.3% of transfer value on vulnerable hops
Price movement0.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:

text
1Executing: ETH → Uniswap(ETH→USDC) → Wormhole(USDC) → Jupiter(USDC→SOL)
2
3Step 1/3: Swap ETH → USDC on Uniswap
4 ├── Build transaction
5 ├── Simulate (verify output within tolerance)
6 ├── Submit and confirm
7 └── ✓ Received 3,247.82 USDC
8
9Step 2/3: Bridge USDC via Wormhole (Ethereum → Solana)
10 ├── Initiate bridge transfer
11 ├── Monitor VAA confirmation
12 ├── Redeem on Solana
13 └── ✓ Received 3,247.82 USDC on Solana (2m 14s)
14
15Step 3/3: Swap USDC → SOL on Jupiter
16 ├── Fetch quote
17 ├── Submit and confirm
18 └── ✓ Received 14.12 SOL
19
20Result: 1.0 ETH → 14.12 SOL (guaranteed minimum was 13.8 SOL) ✓

Failure Handling

If any step fails or conditions degrade beyond tolerance:

  1. Pre-bridge failure — Revert source chain transaction. No funds at risk.
  2. Bridge stall — Monitor until completion or timeout. Alert user with options.
  3. Post-bridge failure — Assets are on destination chain. Re-route the final swap through alternative DEX.
Safety guarantee: At no point are user funds split across chains without monitoring. The executor tracks the full lifecycle and provides status updates at each step.

Performance

OperationTypical Time
Path discovery<100ms
State collection (parallel)500ms–2s
Minimax evaluation (15 paths)<50ms
Total quote time1–3s
Execution timeDepends on bridge (30s–20min)