From 6b77a493a2f4b1da5f18ab06c066b6d1da06b98b Mon Sep 17 00:00:00 2001 From: openhands Date: Wed, 11 Mar 2026 04:11:02 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20address=20review=20feedback=20=E2=80=94?= =?UTF-8?q?=20update=20stale=20comments=20and=20tighten=20test=20guard=20(?= =?UTF-8?q?#543)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - _scrapePositions natspec: 'ETH inflow' → 'ETH outflow / price fell or at bootstrap' - Inline comment above VWAP block: remove inverted 'KRK sold out / ETH inflow' rationale, replace with a neutral forward-reference to recenter() where the direction logic lives - VWAPFloorProtection.t.sol: remove unused Kraiken and forge-std/Test.sol imports (both are already provided by UniSwapHelper) - test_floorConservativeAfterBuyOnlyAttack: add assertFalse(token0isWeth) guard so a future change to the setUp parameter cannot silently invert the gap-direction assertion Co-Authored-By: Claude Sonnet 4.6 --- onchain/src/LiquidityManager.sol | 5 ++--- onchain/test/VWAPFloorProtection.t.sol | 10 +++++----- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/onchain/src/LiquidityManager.sol b/onchain/src/LiquidityManager.sol index 6efda70..b6d24eb 100644 --- a/onchain/src/LiquidityManager.sol +++ b/onchain/src/LiquidityManager.sol @@ -211,7 +211,7 @@ contract LiquidityManager is ThreePositionStrategy, PriceOracle { } /// @notice Removes all positions and collects fees - /// @param recordVWAP Whether to record VWAP (only when net ETH inflow since last recenter) + /// @param recordVWAP Whether to record VWAP (only when net ETH outflow / price fell since last recenter, or at bootstrap) function _scrapePositions(bool recordVWAP) internal { uint256 fee0 = 0; uint256 fee1 = 0; @@ -239,8 +239,7 @@ contract LiquidityManager is ThreePositionStrategy, PriceOracle { } // Transfer fees and record volume for VWAP - // Only record VWAP when net ETH inflow (KRK sold out) — prevents sell-back - // activity from diluting the price memory of original KRK distribution. + // VWAP is recorded only on sell events (price fell) or at bootstrap — see recenter(). // Skip transfer when feeDestination is self — fees accrue as deployable liquidity. if (feeDestination != address(this)) { if (fee0 > 0) { diff --git a/onchain/test/VWAPFloorProtection.t.sol b/onchain/test/VWAPFloorProtection.t.sol index b1f9331..20d099f 100644 --- a/onchain/test/VWAPFloorProtection.t.sol +++ b/onchain/test/VWAPFloorProtection.t.sol @@ -17,12 +17,8 @@ pragma solidity ^0.8.19; import { LiquidityManager } from "../src/LiquidityManager.sol"; import { ThreePositionStrategy } from "../src/abstracts/ThreePositionStrategy.sol"; -import { Kraiken } from "../src/Kraiken.sol"; -import "../src/interfaces/IWETH9.sol"; import { TestEnvironment } from "./helpers/TestBase.sol"; import { UniSwapHelper } from "./helpers/UniswapTestBase.sol"; -import "@uniswap-v3-core/interfaces/IUniswapV3Pool.sol"; -import "forge-std/Test.sol"; contract VWAPFloorProtectionTest is UniSwapHelper { address constant RECENTER_CALLER = address(0x7777); @@ -128,6 +124,11 @@ contract VWAPFloorProtectionTest is UniSwapHelper { try lm.recenter() { } catch { } } + // This test is written for token0isWeth=false (set in setUp via setupEnvironment(false,...)). + // For !token0isWeth: buying KRK pushes tick UP (WETH/KRK price rises), so floor must be + // BELOW (lower tick than) the inflated current tick. + assertFalse(token0isWeth, "test assumes token0isWeth=false; update gap logic if changed"); + // Read floor and current tick (, int24 currentTick,,,,,) = pool.slot0(); (, int24 floorTickLower, int24 floorTickUpper) = @@ -135,7 +136,6 @@ contract VWAPFloorProtectionTest is UniSwapHelper { int24 floorCenter = floorTickLower + (floorTickUpper - floorTickLower) / 2; - // For !token0isWeth buying pushes tick UP (KRK more expensive). // The floor must be BELOW the current inflated tick by a substantial margin — // at minimum the anchor spacing plus some additional buffer from VWAP anchoring. // We assert that the gap is at least 400 ticks (two tick spacings).