-
Notifications
You must be signed in to change notification settings - Fork 8
UniswapV2/V3 router ABI decoding #15
Copy link
Copy link
Open
Labels
enhancementNew feature or requestNew feature or requesthelp wantedExtra attention is neededExtra attention is neededl2L2 chain supportL2 chain supportmevMEV/searcher toolingMEV/searcher tooling
Description
Summary
Add pre-built ABI decoders for the most common DEX router contracts (UniswapV2Router02, UniswapV3SwapRouter, Universal Router).
Motivation
The overwhelming majority of MEV opportunities come from DEX swaps. Searchers decode every pending transaction to check if it's a swap, extract the parameters (token pair, amount, slippage), and evaluate whether an arb or sandwich is profitable.
Having optimized, pre-built decoders for the most common routers eliminates boilerplate and leverages eth.zig's fast ABI decoding (1.77x faster than Alloy) where it matters most.
Proposed API
const eth = @import("eth");
// Decode a pending transaction
const decoded = eth.dex.decode(tx.data) orelse continue;
switch (decoded) {
.v2_swap_exact_tokens_for_tokens => |swap| {
// swap.amountIn, swap.amountOutMin, swap.path, swap.to, swap.deadline
},
.v3_exact_input_single => |swap| {
// swap.tokenIn, swap.tokenOut, swap.fee, swap.recipient, swap.amountIn, swap.sqrtPriceLimitX96
},
.universal_router_execute => |cmd| {
// Decode Universal Router commands
},
}Scope
Phase 1: Core routers
- UniswapV2Router02:
swapExactTokensForTokens,swapTokensForExactTokens,swapExactETHForTokens,swapTokensForExactETH - UniswapV3SwapRouter:
exactInputSingle,exactInput,exactOutputSingle,exactOutput - Universal Router:
executecommand decoding
Phase 2: Additional DEXs
- SushiSwap (V2-compatible)
- PancakeSwap (V2/V3-compatible)
- Aerodrome/Velodrome (Base/OP)
- Camelot (Arbitrum)
Implementation Notes
- Use comptime function selectors for zero-cost selector matching
- Struct types for each decoded swap variant
- Should compose with pending tx subscription (Flashbots / MEV bundle submission #13) for a complete mempool monitoring pipeline
- The Universal Router uses a command-based encoding that needs special handling
References
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requesthelp wantedExtra attention is neededExtra attention is neededl2L2 chain supportL2 chain supportmevMEV/searcher toolingMEV/searcher tooling