fix: address AI review feedback for #317 event replay
- Cache pool.tickSpacing() as immutable in EventReplayer constructor to avoid a repeated external call per _replayMint() invocation - Rename driftCount → driftCheckpoints for consistency with log label - Add sqrtDriftBps to the per-checkpoint progress log line, using the now-live lastExpectedSqrtPrice field (previously written but never read) - Guard _replaySwap(): skip and count events where amountSpecified ≤ 0, which would silently flip exact-input into exact-output mode - Add a final drift sample after the while-loop for trailing events not covered by the last LOG_INTERVAL checkpoint - Move EventReplayer construction outside the broadcast block in BacktestRunner (it uses vm.* cheat codes incompatible with real RPC) - Change second vm.closeFile() from try/catch to a direct call so errors surface rather than being silently swallowed Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
a884f8a5c9
commit
cd065275be
2 changed files with 112 additions and 50 deletions
|
|
@ -88,11 +88,13 @@ contract BacktestRunner is Script {
|
|||
// Deploy factory + pool and initialise at the resolved price.
|
||||
ShadowPool memory sp = ShadowPoolDeployer.deploy(address(tokenA), address(tokenB), sqrtPriceX96);
|
||||
|
||||
// Deploy the event replayer with the canonical token ordering from the pool.
|
||||
EventReplayer replayer = new EventReplayer(sp.pool, MockToken(sp.token0), MockToken(sp.token1));
|
||||
|
||||
vm.stopBroadcast();
|
||||
|
||||
// Instantiate EventReplayer outside the broadcast block: it uses Foundry cheat codes
|
||||
// (vm.readLine, vm.roll, vm.warp) that only work in the forge simulation context and
|
||||
// must not be sent as real transactions to the RPC endpoint.
|
||||
EventReplayer replayer = new EventReplayer(sp.pool, MockToken(sp.token0), MockToken(sp.token1));
|
||||
|
||||
// Query pool state (view calls, no broadcast needed).
|
||||
(uint160 slot0SqrtPrice, int24 tick,,,,,) = sp.pool.slot0();
|
||||
uint128 liquidity = sp.pool.liquidity();
|
||||
|
|
@ -129,8 +131,8 @@ contract BacktestRunner is Script {
|
|||
l = vm.readLine(eventsFile);
|
||||
}
|
||||
}
|
||||
// Reset again before the replay pass.
|
||||
try vm.closeFile(eventsFile) {} catch {}
|
||||
// Reset before the replay pass; we know the file is open after the count loop.
|
||||
vm.closeFile(eventsFile);
|
||||
|
||||
console2.log("\n=== Starting Event Replay ===");
|
||||
console2.log("Events file: ", eventsFile);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue