Merge pull request 'fix: Dead code branch: lastRecenterTick==0 with cumulativeVolume>0 (#568)' (#628) from fix/issue-568 into master

This commit is contained in:
johba 2026-03-12 21:09:40 +01:00
commit 7883b5ae12
2 changed files with 1 additions and 31 deletions

View file

@ -186,14 +186,11 @@ contract LiquidityManager is ThreePositionStrategy, PriceOracle {
if (cumulativeVolume == 0) {
// No VWAP data yet always bootstrap to prevent vwapX96=0 fallback
shouldRecordVWAP = true;
} else if (lastRecenterTick != 0) {
} else {
// token0isWeth: tick UP = price down in KRK terms = sells = ETH outflow
// !token0isWeth: tick DOWN = price down in KRK terms = sells = ETH outflow
// Only record when price falls VWAP stays anchored to historical levels during buy attacks.
shouldRecordVWAP = token0isWeth ? (currentTick > lastRecenterTick) : (currentTick < lastRecenterTick);
} else {
// First recenter no reference point, record conservatively
shouldRecordVWAP = true;
}
lastRecenterTick = currentTick;

View file

@ -1084,33 +1084,6 @@ contract LiquidityManagerTest is UniSwapHelper {
assertGt(anchorLiq, 0, "ANCHOR position should have been created with fallback params");
}
/**
* @notice VWAP else branch: cumulativeVolume > 0 AND lastRecenterTick == 0
* Reached by re-deploying a fresh LM (lastRecenterTick = 0) and setting
* cumulativeVolume via vm.store before the first recenter.
*/
function testVWAPElseBranch() public {
// Re-deploy fresh protocol so lastRecenterTick starts at 0
deployProtocolWithTokenOrder(DEFAULT_TOKEN0_IS_WETH);
// Preconditions: fresh LM has lastRecenterTick == 0 and cumulativeVolume == 0
assertEq(lm.lastRecenterTick(), 0, "precondition: lastRecenterTick must be 0");
assertEq(lm.cumulativeVolume(), 0, "precondition: cumulativeVolume must be 0");
// Set cumulativeVolume to non-zero (storage slot 1 in VWAPTracker).
// This creates the state: cumulativeVolume > 0 AND lastRecenterTick == 0,
// which triggers the else branch (line 170) on the first recenter.
vm.store(address(lm), bytes32(uint256(1)), bytes32(uint256(1e18)));
assertEq(lm.cumulativeVolume(), 1e18, "cumulativeVolume should be 1e18 after vm.store");
// Call recenter hits the else branch, sets lastRecenterTick, then sets positions
vm.prank(RECENTER_CALLER);
lm.recenter();
// Verify lastRecenterTick was updated from the recenter
assertTrue(lm.lastRecenterTick() != 0, "lastRecenterTick should have been updated after recenter");
}
/**
* @notice When feeDestination == address(lm), recenter must not transfer fees externally
* and _getOutstandingSupply must not double-subtract LM-held KRK.