How darkhorse-techsolution/mev-lib works
mev-lib is a Rust utility library for Ethereum MEV tooling, not a complete bot: it provides typed DeFi primitives, AMM calculations, calldata decoding, and optional local transaction simulation. A typical consumer supplies transaction calldata to the decoder or configures a transaction and state for simulation; the library returns parsed calls or an execution result. The README also documents simulation state overrides, forking, and tracing. Those broader capabilities are represented, but unsampled implementation details and their wiring are not asserted.
Main entry points: mod.rs Calldata decoder · executor.rs EVM executor · selector.rs Method selectors · uniswap_v2.rs Uniswap V2 decoder
Components 15
Core primitives
- Token types
src/types/token.rs - Pool and reserves
src/types/pool.rs - Swap types
src/types/swap.rs
Calldata decoding
- Calldata decoder
src/decoder/mod.rs - Method selectors
src/decoder/selector.rs - Uniswap V2 decoder
src/decoder/uniswap_v2.rs - Uniswap V3 decoder
src/decoder/uniswap_v3.rs - ERC20 decoder
src/decoder/erc20.rs
AMM calculations
- Uniswap V2 math
src/math/uniswap_v2.rs
Transaction simulation
- Simulation inputs
src/simulation/types.rs - EVM executor
src/simulation/executor.rs - Execution results
src/simulation/result.rs - State overrides
src/simulation/types.rs - Forked state
src/simulation
Other components
- Library consumer
Connections 15
- Library consumer → Calldata decoder: submits calldata
README.md - Calldata decoder → Uniswap V2 decoder: tries V2
src/decoder/mod.rs - Calldata decoder → Uniswap V3 decoder: tries V3
src/decoder/mod.rs - Calldata decoder → ERC20 decoder: tries ERC20
src/decoder/mod.rs - Uniswap V2 decoder → Method selectors: matches selectors
src/decoder/uniswap_v2.rs - Uniswap V3 decoder → Method selectors: uses selectors
src/decoder/uniswap_v3.rs - ERC20 decoder → Method selectors: uses selectors
src/decoder/erc20.rs - Calldata decoder → Library consumer: returns decoded call
src/decoder/mod.rs - Library consumer → Uniswap V2 math: calculates swap outputs
README.md - Library consumer → Simulation inputs: configures transaction
README.md - Library consumer → EVM executor: requests simulation
README.md - EVM executor → Simulation inputs: reads inputs
src/simulation/executor.rs - EVM executor → Execution results: produces result
README.md - Library consumer → State overrides: sets state overrides
README.md - Library consumer → Forked state: uses forked state
src/simulation/mod.rs