Skip to content

Commit b8966ee

Browse files
authored
CVF-3, CVF-4, CVF-5, CVF-11, CVF-12 (#181)
1 parent 53b487f commit b8966ee

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/Doppler.sol

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {FixedPoint96} from "v4-periphery/lib/v4-core/src/libraries/FixedPoint96.
1717
import {TransientStateLibrary} from "v4-periphery/lib/v4-core/src/libraries/TransientStateLibrary.sol";
1818
import {FixedPointMathLib} from "solady/utils/FixedPointMathLib.sol";
1919
import {ProtocolFeeLibrary} from "v4-periphery/lib/v4-core/src/libraries/ProtocolFeeLibrary.sol";
20+
import {SafeCastLib} from "solady/utils/SafeCastLib.sol";
2021

2122
struct SlugData {
2223
int24 tickLower;
@@ -52,6 +53,8 @@ contract Doppler is BaseHook {
5253
using TransientStateLibrary for IPoolManager;
5354
using BalanceDeltaLibrary for BalanceDelta;
5455
using ProtocolFeeLibrary for *;
56+
using SafeCastLib for int256;
57+
using SafeCastLib for uint256;
5558

5659
bytes32 constant LOWER_SLUG_SALT = bytes32(uint256(1));
5760
bytes32 constant UPPER_SLUG_SALT = bytes32(uint256(2));
@@ -372,7 +375,7 @@ contract Doppler is BaseHook {
372375
int24 tauTick = startingTick + int24(state.tickAccumulator / 1e18);
373376

374377
// Safe from overflow since the result is <= gamma which is an int24 already
375-
int24 computedRange = int24(_getGammaShare() * gamma / 1e18);
378+
int24 computedRange = (_getGammaShare() * gamma / 1e18).toInt24();
376379
int24 upperSlugRange = computedRange > key.tickSpacing ? computedRange : key.tickSpacing;
377380

378381
// The expectedTick is where the upperSlug.tickUpper is/would be placed in the previous epoch
@@ -407,7 +410,7 @@ contract Doppler is BaseHook {
407410
}
408411

409412
currentTick =
410-
_alignComputedTickWithTickSpacing(upSlug.tickLower + int24(accumulatorDelta / 1e18), key.tickSpacing);
413+
_alignComputedTickWithTickSpacing(upSlug.tickLower + (accumulatorDelta / 1e18).toInt24(), key.tickSpacing);
411414

412415
(int24 tickLower, int24 tickUpper) = _getTicksBasedOnState(newAccumulator, key.tickSpacing);
413416

@@ -523,7 +526,7 @@ contract Doppler is BaseHook {
523526

524527
/// @notice Computes the gamma share for a single epoch, used as a measure for the upper slug range
525528
function _getGammaShare() internal view returns (int256) {
526-
return int256(FullMath.mulDiv(epochLength, 1e18, (endingTime - startingTime)));
529+
return FullMath.mulDiv(epochLength, 1e18, (endingTime - startingTime)).toInt256();
527530
}
528531

529532
/// @notice If offset == 0, retrieves the expected amount sold by the end of the last epoch
@@ -602,7 +605,7 @@ contract Doppler is BaseHook {
602605
view
603606
returns (int24 lower, int24 upper)
604607
{
605-
int24 accumulatorDelta = int24(accumulator / 1e18);
608+
int24 accumulatorDelta = (accumulator / 1e18).toInt24();
606609
int24 adjustedTick = startingTick + accumulatorDelta;
607610
lower = _alignComputedTickWithTickSpacing(adjustedTick, tickSpacing);
608611

@@ -784,7 +787,7 @@ contract Doppler is BaseHook {
784787
/// @param num The numerator
785788
/// @param denom The denominator
786789
function _computeTargetPriceX96(uint256 num, uint256 denom) internal pure returns (uint160) {
787-
return uint160(FullMath.mulDiv(num, FixedPoint96.Q96, denom));
790+
return FullMath.mulDiv(num, FixedPoint96.Q96, denom).toUint160();
788791
}
789792

790793
/// @notice Computes the single sided liquidity amount for a given price range and amount of tokens

0 commit comments

Comments
 (0)