From f3ddec9427dce9186fc16c92dfcf976974b6934e Mon Sep 17 00:00:00 2001 From: openhands Date: Sat, 14 Mar 2026 01:40:41 +0000 Subject: [PATCH] fix: Other clamped params lack named constants (#703) Co-Authored-By: Claude Sonnet 4.6 --- onchain/src/IOptimizer.sol | 8 ++++---- onchain/src/LiquidityManager.sol | 10 +++++++--- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/onchain/src/IOptimizer.sol b/onchain/src/IOptimizer.sol index 5c110be..d7dc264 100644 --- a/onchain/src/IOptimizer.sol +++ b/onchain/src/IOptimizer.sol @@ -20,10 +20,10 @@ struct OptimizerInput { interface IOptimizer { /** * @notice Returns the four liquidity parameters used by LiquidityManager.recenter(). - * @return capitalInefficiency Capital buffer level (0..1e18). CI=0 is safest. - * @return anchorShare Fraction of non-floor ETH in anchor (0..1e18). - * @return anchorWidth Anchor position width in tick units (uint24); max 100 ticks, enforced by LiquidityManager. - * @return discoveryDepth Discovery liquidity density (0..1e18). + * @return capitalInefficiency Capital buffer level (0..1e18, clamped to MAX_PARAM_SCALE). CI=0 is safest. + * @return anchorShare Fraction of non-floor ETH in anchor (0..1e18, clamped to MAX_PARAM_SCALE). + * @return anchorWidth Anchor position width in tick units (uint24); max 100 ticks (MAX_ANCHOR_WIDTH), enforced by LiquidityManager. + * @return discoveryDepth Discovery liquidity density (0..1e18, clamped to MAX_PARAM_SCALE). */ function getLiquidityParams() external diff --git a/onchain/src/LiquidityManager.sol b/onchain/src/LiquidityManager.sol index 50649f5..e1fbe84 100644 --- a/onchain/src/LiquidityManager.sol +++ b/onchain/src/LiquidityManager.sol @@ -38,6 +38,10 @@ contract LiquidityManager is ThreePositionStrategy, PriceOracle { /// Any optimizer-returned value above this ceiling is silently clamped down. uint24 internal constant MAX_ANCHOR_WIDTH = 100; + /// @notice Upper bound (inclusive) for scale-1 optimizer parameters: capitalInefficiency, + /// anchorShare, and discoveryDepth. Values above this ceiling are silently clamped. + uint256 internal constant MAX_PARAM_SCALE = 10 ** 18; + /// @notice Immutable contract references address private immutable factory; IWETH9 private immutable weth; @@ -224,10 +228,10 @@ contract LiquidityManager is ThreePositionStrategy, PriceOracle { try optimizer.getLiquidityParams() returns (uint256 capitalInefficiency, uint256 anchorShare, uint24 anchorWidth, uint256 discoveryDepth) { // Clamp parameters to valid ranges PositionParams memory params = PositionParams({ - capitalInefficiency: (capitalInefficiency > 10 ** 18) ? 10 ** 18 : capitalInefficiency, - anchorShare: (anchorShare > 10 ** 18) ? 10 ** 18 : anchorShare, + capitalInefficiency: (capitalInefficiency > MAX_PARAM_SCALE) ? MAX_PARAM_SCALE : capitalInefficiency, + anchorShare: (anchorShare > MAX_PARAM_SCALE) ? MAX_PARAM_SCALE : anchorShare, anchorWidth: (anchorWidth > MAX_ANCHOR_WIDTH) ? MAX_ANCHOR_WIDTH : anchorWidth, - discoveryDepth: (discoveryDepth > 10 ** 18) ? 10 ** 18 : discoveryDepth + discoveryDepth: (discoveryDepth > MAX_PARAM_SCALE) ? MAX_PARAM_SCALE : discoveryDepth }); _setPositions(currentTick, params);