How jito-labs/mev-bot works
Project Type and Purpose
• This is a specialized, single‐purpose MEV (miner/executor value) arb bot built in Node.js/TypeScript for the Solana ecosystem.
• It monitors the Solana mempool to spot large pending trades on DEXs (Raydium, Orca, etc.), calculates circular arbitrage routes, and executes backrun transactions via Jito bundles and flashloans.
File Structure
• Top level: configuration files (.env, Dockerfile, tsconfig.json), an analyze/ notebook, a pool‐update script, and the src/ directory.
• src/clients/: connectors for Solana RPC, Jito block engine, and Geyser plugin.
• src/markets/: DEX‐specific adapters (Raydium, Orca, etc.), each with its own initialization and pool metadata.
• Core modules:
• bot.ts – process orchestration (entry point)
• mempool.ts – mempool subscription & incoming‐tx filtering
• lookup‐table‐provider.ts – lookup table caching for bundle size reduction
• calculate‐arb.ts / simulation.ts – route calculation and profitability simulation
• pre‐simulation-filter.ts / post‐simulation-filter.ts – filter out uninteresting or unprofitable opportunities
• send-bundle.ts – bundle construction and submission (flashloan, swaps, repayment)
• worker-pool.ts – multi‐threaded pool for parallel arb calculation
• Utilities/config: logger.ts, constants.ts, config.ts, utils.ts, types.ts.
Extract Architecture Insights from the README
• Three‐phase pipeline:
1. Detect – subscribe to mempool via Geyser, resolve lookup tables
2. Compute – simulate potential arbitrage routes across DEX adapters, pick the best route
3. Execute – assemble flashloan + multi‐hop swap bundle (via Jupiter), submit to Solana through Jito block engine, then log results
• External dependencies: Solana JSON‐RPC, Jito Geyser plugin, Block Engine, Jupiter SDK, Solend flashloan program, CSV file for metrics.
Main Components & Their Interactions
a. Mempool Monitor
• Inputs: Solana RPC + Geyser plugin
• Output: stream of pending transactions matching DEX vault addresses
b. Lookup Table Provider
• Caches on‐chain lookup tables encountered in pending txns
• Feeds the transaction resolver in the simulation
c. Pre‐Simulation Filter
• Discards transactions that do not touch target pool vaults or are too small
d. Worker Pool & Simulation Engine
• Spawns N worker threads, each with a set of Amm calculator objects (from Jupiter SDK) loaded with Geyser‐pushed pool data
• Simulates 2‐hop & 3‐hop routes for profitability in discrete steps
e. Route Selection
• Picks the most profitable route (highest expected return)
f. Bundle Constructor & Executor
• Constructs a Solend flashloan + Jupiter multi‐swap + flashloan repayment + validator tip transaction
• Uses cached lookup tables to reduce transaction size
• Submits the bundle via Jito Block Engine RPC
g. Post‐Execution Logging
• Waits ~30s, fetches on‐chain result, writes trade details to CSV
h. Auxiliary
• update-pool-lists.sh – refreshes the list of pool account addresses
• /trades.ipynb – Jupyter notebook for offline results analysis
Architectural Patterns and Principles
• Pipeline Pattern: Data flows through detection → filtering → simulation → execution → logging.
• Worker Pool: Parallelizes heavy compute across threads for route simulation.
• Adapter Pattern: One adapter per DEX under src/markets.
• Caching Layer: lookup‐table‐provider reduces RPC overhead and bundle size.
• Event‐Driven: Reacts to mempool events, not timed polls.
Final Recommendations
• Be granular: Break src/markets into sub-components if needed to show each DEX adapter.