Quarrythe mempool.
A bare-metal MEV arbitrage engine. A TypeScript scanner watches Ethereum's public mempool for swaps about to land on a Uniswap-V2-shaped DEX; for each candidate it back-computes the price the victim will leave behind, runs a closed-form optimal-input solver, and — if the round-trip profit clears fees and gas — signs an EIP-1559 transaction that borrows from Aave V3 and routes through a 188-byte Yul executor.
Every opcode shaved off the on-chain leg widens the marginal profit envelope. That's the engineering thesis.
Core samples
from the seam.
Four headline figures from the working operation. Pulled from the repository's test ledger; reproducible against the published anvil fork harness.
The drilling
log.
Nine deterministic steps from a pending mempool transaction to a signed Flashbots-shaped bundle. The off-chain side does all the math; the on-chain Yul executor is monolithic — no Solidity, no function dispatcher, no ABI decoding, just calldataload reads against a tightly packed 220-byte payload.
Pool 1's output flows directly to pool 2 — the canonical Uniswap V2 trick, saving ~25k gas of intermediate ERC20 transfer. A balance snapshot at entry and exit guards the trade: if the arbitrage window closes between detection and inclusion, the whole transaction reverts and only the base network fee is burned.
- 01100 m
WebSocket pending-tx
Subscribe to mempool over WS via viem.
- 02140 m
Router filter
Uniswap V2 + Sushiswap only. Everything else dropped.
- 03200 m
Calldata decode
Four router methods, discriminated union — no dynamic dispatch.
- 04280 m
Multicall reserves
Multicall3 reads both pair reserves in a single RPC round-trip.
- 05360 m
Score the back-run
Apply victim → solve x* = (r·√K − R₁ᵢₙ·R₂ᵢₙ) / (r·(R₂ᵢₙ + r·R₁ₒᵤₜ)).
- 06460 m
Gate against gas
Refuse if profit ≤ flashloan premium + bundle gas cost.
- 07580 m
Pack 220-byte calldata
No ABI offsets. Tight byte string designed for calldataload.
- 08720 m
Sign + bundle
EIP-1559 envelope → Aave V3 flashLoanSimple → Yul executor.
- 09870 m
Yul executes
Borrow → swap → swap → assert → approve → return profit.
Field demo.
Forked mainnet.
The full pipeline runs against a local anvil fork. The bot holds zero inventory; Aave V3 fronts the WETH and gets repaid atomically plus a 5 bp premium inside the same transaction.

# Terminal 1 — fork mainnet at HEAD anvil --fork-url https://ethereum-rpc.publicnode.com # Terminal 2 — run the pipeline cd bot bun run demo
The 0.11% drift between net predicted and net realised is exactly the 2 bp safety margin baked into the calldata builder for Uniswap V2's K-invariant integer-arithmetic check — documented in JOURNAL.md.
Equipment
inventory.
Two intentionally independent trees. They communicate via deployed contract address + ABI only — never via a shared TS package. Each side has its own toolchain, its own test suite, its own gas/perf budget.
- ·amm.ts
- ·decode.ts
- ·pairs.ts
- ·reserves.ts
- ·score.ts
- ·gas.ts
- ·bundle.ts
- ·sign.ts
- ·scanner.ts
- ·Executor.yul
- ·amm.test.ts
- ·decode.test.ts
- ·pairs.test.ts
- ·score.test.ts
- ·bundle.test.ts
- ·sign.test.ts
- ·flashloan.test.ts
- ·Executor.t.sol
- ·ExecutorFork.t.sol
- ·ExecutorFlashloan.t.sol
188 bytes of Yul.110k gas on real pools.
Read the JOURNAL for the incidents — selector bugs, K-invariant boundary drift, whale-balance shortages — that shaped the design. Every entry is a sample log.