← Back to all products

Routing Engine

$20

Off-chain routing engine for computing optimal swap paths across DEX liquidity sources.

📁 22 files
TOMLPythonTypeScriptMarkdownJSON

📁 File Structure 22 files

routing-engine/ ├── LICENSE ├── README.md ├── config/ │ └── default.json ├── examples/ │ ├── basic-route.ts │ ├── python-example.py │ └── split-route.ts ├── package.json ├── python/ │ ├── pyproject.toml │ └── routing_engine/ │ ├── __init__.py │ └── client.py ├── security-notes.md ├── src/ │ ├── adapters/ │ │ ├── BaseFetcher.ts │ │ ├── UniswapV2Fetcher.ts │ │ └── UniswapV3Fetcher.ts │ ├── graph/ │ │ ├── PathFinder.ts │ │ ├── PoolGraph.ts │ │ └── types.ts │ ├── index.ts │ ├── pricing/ │ │ ├── GasEstimator.ts │ │ └── QuoteEngine.ts │ └── utils/ │ └── multicall.ts └── tsconfig.json

📖 Documentation Preview README excerpt

Routing Engine

Off-chain pathfinding engine for optimal trade routes across DEXes.

Product 2 of the [defi-router](../../) store. Part of the CryptoForge DeFi toolkit.

Price: $19.99 | License: MIT | Runtime: Node.js ≥18 | Language: TypeScript + Python


Overview

@cryptoforge/routing-engine is a high-performance, off-chain routing engine that finds the optimal trade path across multiple DEX pools. It uses graph algorithms (Dijkstra, split-route optimization) to compute the best route for any token pair, accounting for fees, price impact, liquidity depth, and gas costs.

Key Features

  • Multi-DEX support — Uniswap V2, Uniswap V3, SushiSwap, Curve, Balancer
  • Split-route optimization — Automatically splits large trades across multiple paths to minimize price impact
  • Graph-based pathfinding — Dijkstra shortest-path with liquidity-aware edge weights
  • Constant product simulation — Full swap simulation with fee deduction and price impact calculation
  • Gas-aware quoting — Estimates gas per route and factors it into net output
  • Batched RPC calls — Multicall3 for efficient pool data fetching
  • Python bindings — Use from Python via subprocess or HTTP API
  • Configurable — Max hops, max splits, slippage tolerance, protocol filters, pool exclusions

Architecture


┌─────────────────────────────────────────────────────────────────────┐
│                         QuoteEngine                                  │
│                                                                      │
│  ┌───────────────────┐  ┌──────────────────┐  ┌──────────────────┐  │
│  │    Pool Graph       │  │    PathFinder     │  │  GasEstimator    │  │
│  │  Adjacency list     │  │  Dijkstra + DFS   │  │  Per-protocol    │  │
│  │  Weighted edges     │  │  Split optimizer   │  │  Gas costs       │  │
│  │  Token→Pool mapping │  │  K-shortest paths  │  │  USD conversion  │  │
│  └───────────────────┘  └──────────────────┘  └──────────────────┘  │
│                                                                      │
│  ┌───────────────────────────────────────────────────────────────┐   │
│  │                     DEX Adapters                               │   │
│  │  ┌──────────────┐ ┌──────────────┐ ┌────────────────────────┐│   │
│  │  │ UniswapV2     │ │ UniswapV3     │ │ BaseFetcher (extend   ││   │
│  │  │ Fetcher       │ │ Fetcher       │ │ for Curve, Balancer)  ││   │
│  │  └──────────────┘ └──────────────┘ └────────────────────────┘│   │
│  └───────────────────────────────────────────────────────────────┘   │
│                                                                      │
│  ┌───────────────────────────────────────────────────────────────┐   │
│  │  Multicall3 — Batched RPC calls for efficient data fetching   │   │
│  └───────────────────────────────────────────────────────────────┘   │
└─────────────────────────────────────────────────────────────────────┘

Data Flow:
  RPC → Multicall → Adapters → Pool Graph → PathFinder → QuoteResult

Quick Start

Installation



*... continues with setup instructions, usage examples, and more.*

📄 Code Sample .py preview

examples/python-example.py """ Example: Python Usage of CryptoForge Routing Engine Demonstrates using the Python bindings to find optimal swap routes. Requires the TypeScript engine to be built first (npm run build). """ from routing_engine import RoutingEngineClient # --------------------------------------------------------------------------- # Well-known token addresses (Ethereum Mainnet) # --------------------------------------------------------------------------- WETH = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2" USDC = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48" USDT = "0xdAC17F958D2ee523a2206206994597C13D831ec7" DAI = "0x6B175474E89094C44Da98b954EedeAC495271d0F" # --------------------------------------------------------------------------- # Example 1: Subprocess mode (no server needed) # --------------------------------------------------------------------------- def example_subprocess(): """Find a route using the subprocess client.""" print("=== Subprocess Mode ===\n") client = RoutingEngineClient(mode="subprocess") # 10 ETH in wei amount_in = str(10 * 10**18) quote = client.get_quote( token_in=WETH, token_out=USDC, amount_in=amount_in, max_hops=3, max_splits=2, max_slippage=0.005, ) print(f"Input: {amount_in} wei WETH") print(f"Output: {quote.amount_out} wei USDC") print(f"Rate: {quote.effective_rate:.6f}") print(f"Gas: ${quote.gas_cost_usd:.2f}") print(f"Routes: {len(quote.routes)}") for i, route in enumerate(quote.routes): pct = route.split_percentage * 100 hops = len(route.steps) # ... 86 more lines ...
Buy Now — $20 Back to Products