QUARRY
000 mfield op QRY-3·26

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.

Scope. Quarry targets cross-DEX arbitrage — closing price gaps the market would close anyway. The kind of MEV broadly considered net-positive for on-chain price efficiency. Predatory strategies (sandwiches, JIT against retail) are out of scope.
020 m · sandstonemanifest 01 / 04

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.

Sample · 02 m
188B
Runtime bytecode
vs. 1.5–3 KB for a Solidity equivalent of the same dual-entry contract.
Sample · 05 m
110k gas
Two-hop arbitrage
Measured against real Uniswap V2 + Sushiswap on a mainnet fork.
Sample · 08 m
99.89%
Solver accuracy
Off-chain prediction vs. on-chain realised profit, end-to-end.
Sample · 11 m
0wei
Capital required
Aave V3 flashLoanSimple fronts the WETH; atomic repayment.
200 m · clay · shalemanifest 02 / 04

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.

  1. 01
    100 m

    WebSocket pending-tx

    Subscribe to mempool over WS via viem.

  2. 02
    140 m

    Router filter

    Uniswap V2 + Sushiswap only. Everything else dropped.

  3. 03
    200 m

    Calldata decode

    Four router methods, discriminated union — no dynamic dispatch.

  4. 04
    280 m

    Multicall reserves

    Multicall3 reads both pair reserves in a single RPC round-trip.

  5. 05
    360 m

    Score the back-run

    Apply victim → solve x* = (r·√K − R₁ᵢₙ·R₂ᵢₙ) / (r·(R₂ᵢₙ + r·R₁ₒᵤₜ)).

  6. 06
    460 m

    Gate against gas

    Refuse if profit ≤ flashloan premium + bundle gas cost.

  7. 07
    580 m

    Pack 220-byte calldata

    No ABI offsets. Tight byte string designed for calldataload.

  8. 08
    720 m

    Sign + bundle

    EIP-1559 envelope → Aave V3 flashLoanSimple → Yul executor.

  9. 09
    870 m

    Yul executes

    Borrow → swap → swap → assert → approve → return profit.

480 m · slate · veinmanifest 03 / 04

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.

Field capture · anvil-fork · HEADframe 01 / 01
bun run demo — back-run pipeline scoring a 1M-USDC victim swap, borrowing 5.3 WETH from Aave V3, netting 0.557 WETH net of premium against real Uniswap V2 + Sushiswap pools
Back-run pipeline scoring a 1 M USDC victim swap, borrowing 5.3 WETH from Aave V3, netting 0.557 WETH net of premium.
# 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.

720 m · granitemanifest 04 / 04

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.

bot/src
TypeScript · Bun
  • ·amm.ts
  • ·decode.ts
  • ·pairs.ts
  • ·reserves.ts
  • ·score.ts
  • ·gas.ts
  • ·bundle.ts
  • ·sign.ts
  • ·scanner.ts
contracts/src
Yul · Foundry
  • ·Executor.yul
bot/test
Bun · 60 tests
  • ·amm.test.ts
  • ·decode.test.ts
  • ·pairs.test.ts
  • ·score.test.ts
  • ·bundle.test.ts
  • ·sign.test.ts
  • ·flashloan.test.ts
contracts/test
Solidity · forge
  • ·Executor.t.sol
  • ·ExecutorFork.t.sol
  • ·ExecutorFlashloan.t.sol
980 m · bedrockclosing report

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.