A flash-loan arbitrage bot for Uniswap V4, Uniswap V2 and SushiSwap. It watches pools for price gaps and trades them through one executor contract, on a local anvil fork of mainnet. A terminal UI shows each decision and trade.
Captured from a live fork run, with 16 swaps pushed through SushiSwap and Uniswap V2 on the USDC, USDT, DAI and WBTC pairs.
The main screen: 15 trades executed and 1 reverted, for 3.3128 ETH net. Two sweeps moved 2.3864 ETH to the treasury. Each opportunity shows its verdict: sent, skipped for gas or for the minimum profit, or locked behind a trade in flight. Log times are in the local zone.
A sent decision: the legs, the profit by size curve, the send parameters, and the result. It was decided 16ms after the block was read and sent at 17.6ms, and it earned 0.0643 ETH.
The Pairs tab: each venue pair with its last spread and verdict.
The Config tab shows the running config, with every key commented.
Startup: the screen shows the connect while pools load, before any trading.
Mnemonic: impose maximum pencil dragon steel kick unusual firm steak jeans snow maid
Copy the env file first. It ships the anvil test mnemonic as MNEMONIC_1.
cp .env.example .env
Run it on a fork, each in its own terminal:
make fork
make fund
make run
To see a trade, push one pool off price, for example a large swap on SushiSwap's WETH/USDC pair from another anvil account.
Make targets:
make setupinstalls Foundry and forge-std.make abibuilds the contract and copies its ABI toabi/.make test-contractsruns the forge tests againstFORK_URL.make forkstarts anvil as a mainnet fork, one block every 2 seconds, pinned at the block intarget/fork-blockso a restart reads state from anvil's cache. Stop it with Ctrl-C so the cache is written.make fork-freshdrops that pin and forks the current mainnet head.make reforkresets the running anvil to the current mainnet head.- None of them echoes
FORK_URL, which usually holds a provider key, but anvil prints its fork URL in its startup banner, so keep that terminal's output private. make fundfunds the configured accounts with ETH and tokens on the fork.make sweepsends the executor's base token profit to the treasury.make journalprints the last 20 trade journal entries.make runstarts the bot with the terminal UI.make run-headlessstarts the bot without the UI.make testruns the unit tests. It needs no network.make test-forkruns the fork tests.make benchruns the benchmarks.make lintrunscargo fmt --checkand clippy.make teardownremoves the Foundry install thatmake setupadded.
After make teardown, run make setup again before any fork target.
The first make run on a newly pinned block connects slowly, about ten minutes, because anvil fetches pool state from FORK_URL one storage slot at a time, about ten thousand requests. That costs credits on a paid key. Later runs on the same block read anvil's disk cache and connect in seconds. A free node such as publicnode keeps old state for only a few minutes, so an old pin needs a node that serves historical state, or make fork-fresh.
make test-fork starts its own anvil on port 8546, pinned to a block. It stops it when the tests end.
The first run fetches state from the public RPC and takes about 16 minutes. A repeat run on the cached block takes about 72 seconds. Plain make test stays hermetic.
Each network has a file in config/. Keys below are from config/ethereum.toml.
- Accounts: each
[[accounts]]entry names an env var, such asMNEMONIC_1, and theindicesto derive.owneris the index that deploys the executor.treasuryis a plain address. - Gas caps:
max_gas_costat the top level,max_fee_per_gas,priority_feeand the gas limits (gas_v2_v2,gas_v2_v4,gas_v4_v4,max_gas_limit) under[adapter]. - Journal: trades are written to
logs/trades-<network>.jsonl. Read it withmake journal.
Copy config/ethereum.toml and edit it. Run with NETWORK=<name>.
- Add a venue in
src/chain/evm/venue. - Add a library in
contracts/legs. - Add a
Familyvariant.




