How 0xbc1p/sui-mev works
Project Type & Purpose
• Rust-based backend service for MEV (Maximal Extractable Value) in the Sui blockchain ecosystem.
• Two primary binaries:
– arb: Main arbitrage bot (collector → indexer → strategy → executor → on-chain).
– relay: Optional mempool relay for validator-pushed transactions.
High-Level Components
A. External Systems
1. Sui Blockchain & Validator (mempool, RPC endpoint)
2. Mempool Relay (bin/relay) – optional service receiving validator pushes and forwarding to arb.
B. Core Service
1. Arbitrage Bot (bin/arb)
– Collector Module: Gathers transaction & event streams from Sui RPC or relay.
– Indexer (dex-indexer crate): Maintains up-to-date pool state from multiple DeFi protocols.
– Strategy Layer: Implements arbitrage logic (cache, search, worker).
– Executor Module: Builds, signs, and submits transactions via Sui RPC.
2. Shared Libraries
– arb-common: Shared types & utilities between arb & crates.
– logger: Structured logging.
– object-pool: Resource pooling for performance.
– utils: Coin math, heartbeat, telegram alerts, linking.
– version: Build/version info.
3. Protocol-Specific Crates
– dex-indexer: Protocol parsers (Cetus, BlueMove, etc.), file DB for cursors.
– shio: Shio-specific mempool collector/executor.
– simulator: Local chain & HTTP simulator for testing strategies.
Data Flows & Interactions
– Relay → Arb Collector: (optional) P2P push of mempool txs.
– Arb Collector → Indexer: Raw event streams → parsed & pooled state.
– Arb Indexer → Strategy: Up-to-date pool state passed to strategy.worker.
– Strategy → Executor: If arbitrage found, create tx payload.
– Executor → Sui RPC: Signed txs submitted on-chain.
– Simulator: Hooks into Collector/Executor for offline testing.
Architectural Patterns & Principles
– Modular Crate Architecture: Each major concern lives in its own crate.
– Layered Pipeline: Collector → Indexer → Strategy → Executor.
– Plugin-style Protocols: dex-indexer/src/protocols implements a trait per DeFi protocol.
– Separation of Concerns: Relay separated from bot core; simulator isolated.