fix: Backtesting #6: Baseline strategies (HODL, full-range, fixed-width) + reporting (#320)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
openhands 2026-02-27 13:08:53 +00:00
parent 33c5244e53
commit 77f0fd82fd
6 changed files with 1095 additions and 6 deletions

View file

@ -238,6 +238,42 @@ contract PositionTracker {
_openPosition(2, newPos.discLiq, newPos.discLo, newPos.discHi, sqrtPriceX96, blockNum, timestamp);
}
// -------------------------------------------------------------------------
// View: final computed metrics (consumed by Reporter)
// -------------------------------------------------------------------------
struct FinalData {
int256 finalIL;
int256 finalNetPnL;
uint256 finalFeesToken0;
uint256 rebalances;
uint256 blocksInRange;
uint256 totalBlocks;
}
/**
* @notice Compute final aggregate metrics including open-position IL.
* Returns the same values that logFinalSummary() logs.
*/
function getFinalData() external view returns (FinalData memory d) {
(uint160 sqrtPriceX96,,,,,,) = pool.slot0();
d.finalIL = totalILToken0;
d.finalNetPnL = totalNetPnLToken0;
d.finalFeesToken0 = totalFeesToken0;
d.rebalances = rebalanceCount;
d.blocksInRange = blocksAnchorInRange;
d.totalBlocks = blocksChecked;
for (uint8 i = 0; i < 3; i++) {
OpenPosition storage pos = openPositions[i];
if (!pos.active) continue;
(uint256 exitAmt0, uint256 exitAmt1) = _positionAmounts(pos.liquidity, pos.tickLower, pos.tickUpper, sqrtPriceX96);
int256 il = _computeIL(pos.entryAmount0, pos.entryAmount1, exitAmt0, exitAmt1, sqrtPriceX96);
d.finalIL += il;
d.finalNetPnL += il; // no fees for unclosed positions
}
}
/**
* @notice Log the final aggregate summary. Call once at the end of replay.
* @param blockNum Final block number (for context in the summary line).