From a5c6ec4b22cb00d692f2a9a7ade662abf48494e8 Mon Sep 17 00:00:00 2001 From: clemlak Date: Sat, 2 Nov 2024 14:24:44 +0400 Subject: [PATCH 1/5] fix: import and use Solady SafeCastLib --- src/Doppler.sol | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Doppler.sol b/src/Doppler.sol index 182c99d9..85a32616 100644 --- a/src/Doppler.sol +++ b/src/Doppler.sol @@ -17,6 +17,7 @@ import {FixedPoint96} from "v4-periphery/lib/v4-core/src/libraries/FixedPoint96. import {TransientStateLibrary} from "v4-periphery/lib/v4-core/src/libraries/TransientStateLibrary.sol"; import {FixedPointMathLib} from "solady/utils/FixedPointMathLib.sol"; import {ProtocolFeeLibrary} from "v4-periphery/lib/v4-core/src/libraries/ProtocolFeeLibrary.sol"; +import {SafeCastLib} from "solady/utils/SafeCastLib.sol"; struct SlugData { int24 tickLower; @@ -52,6 +53,8 @@ contract Doppler is BaseHook { using TransientStateLibrary for IPoolManager; using BalanceDeltaLibrary for BalanceDelta; using ProtocolFeeLibrary for *; + using SafeCastLib for int256; + using SafeCastLib for uint256; bytes32 constant LOWER_SLUG_SALT = bytes32(uint256(1)); bytes32 constant UPPER_SLUG_SALT = bytes32(uint256(2)); @@ -521,7 +524,7 @@ contract Doppler is BaseHook { /// @notice Computes the gamma share for a single epoch, used as a measure for the upper slug range function _getGammaShare() internal view returns (int256) { - return int256(FullMath.mulDiv(epochLength, 1e18, (endingTime - startingTime))); + return FullMath.mulDiv(epochLength, 1e18, (endingTime - startingTime)).toInt256(); } /// @notice If offset == 0, retrieves the expected amount sold by the end of the last epoch From 2d7868f36f6a5afc8b3c7c22b8ee24afffc8b006 Mon Sep 17 00:00:00 2001 From: clemlak Date: Sun, 3 Nov 2024 17:16:18 +0400 Subject: [PATCH 2/5] fix: use SafeCasting for accumulator --- src/Doppler.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Doppler.sol b/src/Doppler.sol index 85a32616..15596804 100644 --- a/src/Doppler.sol +++ b/src/Doppler.sol @@ -603,7 +603,7 @@ contract Doppler is BaseHook { view returns (int24 lower, int24 upper) { - int24 accumulatorDelta = int24(accumulator / 1e18); + int24 accumulatorDelta = (accumulator / 1e18).toInt24(); int24 adjustedTick = startingTick + accumulatorDelta; lower = _alignComputedTickWithTickSpacing(adjustedTick, tickSpacing); From d3b70b1c5d8e7749a26d881ca11b2ffacbbd7f77 Mon Sep 17 00:00:00 2001 From: clemlak Date: Sun, 3 Nov 2024 17:19:05 +0400 Subject: [PATCH 3/5] fix: use safe casting for _computeTargetPriceX96 returned value --- src/Doppler.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Doppler.sol b/src/Doppler.sol index 15596804..c9d072bf 100644 --- a/src/Doppler.sol +++ b/src/Doppler.sol @@ -785,7 +785,7 @@ contract Doppler is BaseHook { /// @param num The numerator /// @param denom The denominator function _computeTargetPriceX96(uint256 num, uint256 denom) internal pure returns (uint160) { - return uint160(FullMath.mulDiv(num, FixedPoint96.Q96, denom)); + return FullMath.mulDiv(num, FixedPoint96.Q96, denom).toUint160(); } /// @notice Computes the single sided liquidity amount for a given price range and amount of tokens From e3a094ee9772196fc45c5a7eee6b0cd4eea5d77b Mon Sep 17 00:00:00 2001 From: clemlak Date: Sun, 3 Nov 2024 18:04:10 +0400 Subject: [PATCH 4/5] fix: use safe casting for computedRange --- src/Doppler.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Doppler.sol b/src/Doppler.sol index c9d072bf..8a321b12 100644 --- a/src/Doppler.sol +++ b/src/Doppler.sol @@ -373,7 +373,7 @@ contract Doppler is BaseHook { int24 tauTick = startingTick + int24(state.tickAccumulator / 1e18); // Safe from overflow since the result is <= gamma which is an int24 already - int24 computedRange = int24(_getGammaShare() * gamma / 1e18); + int24 computedRange = (_getGammaShare() * gamma / 1e18).toInt24(); int24 upperSlugRange = computedRange > key.tickSpacing ? computedRange : key.tickSpacing; // The expectedTick is where the upperSlug.tickUpper is/would be placed in the previous epoch From 670e636932fa89e84fc23c1c2e9488631ae4c29f Mon Sep 17 00:00:00 2001 From: clemlak Date: Sun, 3 Nov 2024 18:05:36 +0400 Subject: [PATCH 5/5] fix: use safe casting for accumulatorDelta --- src/Doppler.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Doppler.sol b/src/Doppler.sol index 8a321b12..6f326f12 100644 --- a/src/Doppler.sol +++ b/src/Doppler.sol @@ -408,7 +408,7 @@ contract Doppler is BaseHook { } currentTick = - _alignComputedTickWithTickSpacing(upSlug.tickLower + int24(accumulatorDelta / 1e18), key.tickSpacing); + _alignComputedTickWithTickSpacing(upSlug.tickLower + (accumulatorDelta / 1e18).toInt24(), key.tickSpacing); (int24 tickLower, int24 tickUpper) = _getTicksBasedOnState(newAccumulator, key.tickSpacing);