You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
L2 liquidation keepers are a distinct and underserved use case for Ethereum libraries. Unlike L1 MEV (which requires Flashbots bundles and gas auctions), L2 FCFS sequencers reward raw speed — exactly where eth.zig's performance advantage is most tangible.
This example also serves as the reference implementation for perpcity liquidation keepers, demonstrating eth.zig's production readiness on Base.
What the bot does
Subscribe to PerpManager contract logs via WebSocket to maintain an in-memory position state
On each position open/adjust/close event: recompute proximity to liquidation threshold
Maintain a priority queue of positions sorted by distance from liquidation
For near-threshold positions: pre-sign the liquidation transaction (ready to broadcast, zero compute on hot path)
When a position crosses the threshold: broadcast the pre-signed tx directly to the Base sequencer RPC
Why L2 is different
On L1, liquidation bots compete via gas price auctions. On Base (FCFS), the winner is whoever reaches the sequencer first. This means:
Pre-signing txs (so broadcast is a single syscall) matters
WebSocket latency to the sequencer RPC matters
Computation on the hot path (between threshold detection and broadcast) must be zero
eth.zig is uniquely positioned here: comptime ABI decoding, minimal allocations, and direct WebSocket transport with no JS runtime overhead.
Implementation outline
examples/10_liquidation_keeper.zig
// Pre-computed event topic at compile timeconstPOSITION_OPENED=comptimeeth.keccak.eventTopic(
"PositionOpened(address,bytes32,uint256,int256,int256)"
);
// Priority queue: positions sorted by (current_margin_ratio - liq_threshold)varat_risk=PriorityQueue(PositionRisk).init(allocator);
// Pre-signed tx cache: position_id -> signed_tx_bytes (ready to broadcast)varpresigned=HashMap([32]u8, []u8).init(allocator);
// Hot path: called when position crosses thresholdfnonLiquidatable(position_id: [32]u8) !void {
consttx=presigned.get(position_id) orelsereturnerror.NotPresigned;
_=tryprovider.sendRawTransaction(tx); // single RPC call, pre-signed
}
Key eth.zig features showcased
Comptime event topic hashing for zero-cost log matching
Motivation
L2 liquidation keepers are a distinct and underserved use case for Ethereum libraries. Unlike L1 MEV (which requires Flashbots bundles and gas auctions), L2 FCFS sequencers reward raw speed — exactly where eth.zig's performance advantage is most tangible.
This example also serves as the reference implementation for perpcity liquidation keepers, demonstrating eth.zig's production readiness on Base.
What the bot does
PerpManagercontract logs via WebSocket to maintain an in-memory position stateWhy L2 is different
On L1, liquidation bots compete via gas price auctions. On Base (FCFS), the winner is whoever reaches the sequencer first. This means:
eth.zig is uniquely positioned here: comptime ABI decoding, minimal allocations, and direct WebSocket transport with no JS runtime overhead.
Implementation outline
examples/10_liquidation_keeper.zigKey eth.zig features showcased
newHeads+getLogssubscription (viawatchLogs— see watchLogs: block-scoped log subscription helper #36)eth_sendRawTransactionto Base RPCConfiguration
Prerequisites
Deliverable
examples/10_liquidation_keeper.zigwith:sendRawTransactioncall (should be <1ms on Apple Silicon)