-
Notifications
You must be signed in to change notification settings - Fork 7
Open
Labels
enhancementNew feature or requestNew feature or requestexampleExample code / showcaseExample code / showcase
Description
Motivation
flashbots/simple-arbitrage (2,100+ stars) is the canonical reference every new MEV developer reads first. It is written in TypeScript. A Zig port using eth.zig would:
- Give eth.zig a direct presence in the highest-traffic Flashbots repository
- Demonstrate eth.zig's comptime ABI selectors and fast decode in a real-world searcher context
- Show Flashbots bundle submission end-to-end with a working example
- Provide a contribution opportunity to the Flashbots org (PR to add Zig reference, or a linked
simple-arbitrage-zigrepo)
What the bot does
- Subscribe to new blocks via WebSocket
- On each block: fetch Uniswap V2 pair reserves (batch
eth_call) across a set of WETH/token pairs - Find crossed markets (pairs where arbitrage is profitable)
- Construct a bundle:
uniswapWeth(amount, targets, payloads)call to a deployedBundleExecutorcontract - Simulate the bundle (
eth_callBundle) to verify profit - Submit the bundle to Flashbots relay (
eth_sendBundle) targeting current + next block
Implementation outline
examples/08_simple_arbitrage.zig
// Key eth.zig features showcased:
// 1. Comptime selectors
const GET_RESERVES = comptime eth.keccak.selector("getReserves()");
const UNISWAP_WETH = comptime eth.keccak.selector("uniswapWeth(uint256,uint256,address[],bytes[])");
// 2. Batch eth_call for reserve fetching (issue #11)
const reserves = try provider.batchCall(allocator, reserve_calls);
// 3. UniswapV2 quote math (issue #16)
const profit = eth.uniswap.getAmountOut(amount_in, reserve_in, reserve_out);
// 4. Bundle construction + submission
var bundle = flashbots.Bundle.init(allocator);
try bundle.addTransaction(signed_arb_tx);
const result = try fb_client.sendBundle(allocator, .{
.transactions = bundle.transactions(),
.block_number = block_number + 1,
});Prerequisites
- Batch eth_call support #11 (batch eth_call) — for efficient reserve fetching across many pairs
- Pure Zig DEX quote calculation (UniswapV2/V3 math) #16 (UniswapV2 math) — for profitability calculation
flashbots.zig— already merged
Deliverable
A self-contained examples/08_simple_arbitrage.zig with:
- A
PAIRSlist configurable via environment/comptime BundleExecutorcontract ABI inlined- Working against Anvil fork (integration test)
- README section documenting the example and linking to the Flashbots original
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requestexampleExample code / showcaseExample code / showcase