-
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
MEV-Share is the active Flashbots orderflow protocol. The canonical developer journey is: "read the docs → clone mev-share-client-ts → write a backrunner". A Zig backrunner example gives eth.zig a natural home in that journey for performance-conscious searchers.
What the bot does
- Connect to the MEV-Share event stream (SSE) and listen for pending transactions
- For each pending tx event: check if it involves a known token swap (by function selector hint)
- If profitable: construct a backrun bundle (user tx hash + our backrun tx)
- Submit via
mev_sendBundleto the MEV-Share relay
Implementation outline
examples/09_mev_share_backrunner.zig
const eth = @import("eth");
const mev_share = eth.mev_share;
// Comptime: pre-hash the swap selectors we care about
const UNISWAP_V2_SWAP = comptime eth.keccak.selector("swapExactTokensForTokens(uint256,uint256,address[],address,uint256)");
const UNISWAP_V3_SWAP = comptime eth.keccak.selector("exactInputSingle((address,address,uint24,address,uint256,uint256,uint160))");
var client = try mev_share.MevShareClient.init(allocator, auth_signer, .mainnet);
try client.on(allocator, struct {
fn handle(event: mev_share.PendingEvent) void {
switch (event) {
.transaction => |tx| {
// Check if this tx is a swap we can backrun
if (tx.function_selector) |sel| {
if (std.mem.eql(u8, &sel, &UNISWAP_V2_SWAP)) {
submitBackrun(tx.hash);
}
}
},
else => {},
}
}
}.handle);Key eth.zig features showcased
- Comptime function selector matching (zero-cost dispatch on 4-byte selectors)
- MEV-Share client (SSE streaming +
mev_sendBundle) - EIP-1559 transaction construction and signing
- Fast ABI encode for the backrun payload
Prerequisites
- SSE transport for MEV-Share event streaming #33 (SSE transport)
- MEV-Share client module (mev_share.zig) #34 (MEV-Share client module)
Deliverable
examples/09_mev_share_backrunner.zig with instructions for running against the Sepolia MEV-Share endpoint (no mainnet funds required to test the subscription flow).
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requestexampleExample code / showcaseExample code / showcase