Reading the record
Replaying a trade
The replay runs router v3's execute off chain on chain state from any block: the router's checks in its order, with its errors, the Uniswap v3 swap in exact integer math, and the two token transfers as calls on the same state. It answers what the router would have done with a trade, and runs a past fill again on the state right before it, to compare with its Filled event.
A trade at a block
Give a client account, the two tokens and the amount in. The replay uses the account's router v3 settings at that block and the agent wallet pinned at install as the sender. Without block it runs at the head block, with that block's time; a trade sent now lands a little later, when the market price's age or the 24-hour spend can differ.
curl "https://api.fillmark.trade/v1/replay?account=0xB5667f1c68bADFc54CE5eaCc60EACb89473Ec37C&tokenIn=0x5fc5360d0400a0fd4f2af552add042d716f1d168&tokenOut=0xCEC185eB182c47d1bA1EFc84e6959e18cd620Be4&amountIn=11000000"- replay.ok, replay.error
- Whether the router would fill. When it would not,
erroris the router's error, such asWorseThanNav,PriceOutOfRangeorOverDailyLimit(see router errors),Error:and the pool's reason when the pool refuses, orTransferFailedwhen the account cannot pay the pool, where the router passes on the account's own error. - replay.checks
- The checks in the router's order: the client's permission and the agent wallet, the market price and its age, the swap, the pool price bounds, then the client's limits. When ok is false, the last one is the check that failed.
- replay.prices
- As in the
Filledevent: market price, pool price, fill price, and the cost against the market price in USDG units. Positive is worse for the client. - amountOut, fillFee
- What the account would receive, and the fill fee the burner would get.
- block, timestamp
- The block the state comes from and the time the router saw.
Optional: block, minOut, sqrtPriceLimitX96, agentId, nonce and sender. Without them the replay uses the installed agent, no price limit beyond the router's own bounds, the nonce 2^256 − 1 and the pinned agent wallet.
A past fill
Give the transaction of a router v3 fill. The replay rebuilds the state right before it: the block before, then every earlier transaction of its block, with its block's time. To show that state is right, it first runs the transaction itself on it and checks that the result matches the receipt, log for log (stateRebuilt); when it does not, no replay is given. Then it replays the fill and compares every field of the Filled event with the replay's (matches, differences).
curl https://api.fillmark.trade/v1/replay/0xdb16f1944b4debcf1313a94ff1f20cfba50379146c4206ab7ee11217057b9c15How it is checked
The tests in the record folder run the replay and router v3 itself on the same state and compare the outcomes. A fill is compared on every field of its Filled event, and a refusal on the error name. A refusal the router passes on from the account or a token has no name in the router's ABI, so it is compared as such a revert.
- live
- Fixed trades at a recent block: fills, and refusals for size, limits, sender, install and deadline.
- fuzz
- Random trades, client limits and times, with the client's settings changed through state overrides and read back through the router before use. SEED repeats a run.
- selfcheck
- The rebuilt state reproduces recent transactions log for log.
- history
- Every router v3 fill, replayed on the state right before it, against its event.
cd record && npm install
RPC=<url> npx tsx test/replay.ts live
FUZZ=500 RPC=<url> npx tsx test/replay.ts fuzz
RPC=<url> npx tsx test/replay.ts selfcheck
RPC=<url> npx tsx test/replay.ts historyWhat it does not cover
- Gas
- The router gives its payment call and its ERC-8004 feedback call a fixed amount of gas. A transaction sent with too little gas can end differently; the replay assumes enough.
- Unusual tokens
- A token whose balance does not grow by exactly the amount sent, which the router refuses with PartialFill on a buy.
- Routers
- Router v3 only. Fills from the first two routers stay in the record and are not replayed.
- Unusual blocks
- A block holding an Arbitrum transaction type other than plain transactions and ArbOS's start-of-block transaction before the fill is reported as not rebuilt, not guessed.
A replay at a given block is kept for a day, and so is a past fill's replay that matched; a replay at the head is not kept. Replays that are not kept count against 10 a minute per IP address (per /64 network for IPv6) and a daily limit of their own. Errors follow the record API, plus 422 when router v3 is not deployed at that block, the trade needs too many reads to replay, or a fill is on router v1 or v2 or did not go straight to router v3's execute.