Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CVF-3, CVF-4, CVF-5, CVF-11, CVF-12 #181

Merged
merged 5 commits into from
Nov 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions src/Doppler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -370,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
Expand Down Expand Up @@ -405,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);

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -600,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);

Expand Down Expand Up @@ -782,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
Expand Down