Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
33c5244e53
commit
77f0fd82fd
6 changed files with 1095 additions and 6 deletions
|
|
@ -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).
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue