-
Notifications
You must be signed in to change notification settings - Fork 6
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
Avoid first epoch rebalance #169
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice solution 👏
src/Doppler.sol
Outdated
@@ -877,84 +879,53 @@ contract Doppler is BaseHook { | |||
function _unlockCallback(bytes calldata data) internal override returns (bytes memory) { | |||
CallbackData memory callbackData = abi.decode(data, (CallbackData)); | |||
(PoolKey memory key,, int24 tick) = (callbackData.key, callbackData.sender, callbackData.tick); | |||
int256 accumulatorDelta = _getMaxTickDeltaPerEpoch() * 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* 1
here is redundant
src/Doppler.sol
Outdated
@@ -877,84 +879,53 @@ contract Doppler is BaseHook { | |||
function _unlockCallback(bytes calldata data) internal override returns (bytes memory) { | |||
CallbackData memory callbackData = abi.decode(data, (CallbackData)); | |||
(PoolKey memory key,, int24 tick) = (callbackData.key, callbackData.sender, callbackData.tick); | |||
int256 accumulatorDelta = _getMaxTickDeltaPerEpoch() * 1; | |||
state.tickAccumulator = state.tickAccumulator + accumulatorDelta; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
imo it doesn't really make sense dutch auction before any epochs have actually passed. Instead, I think the tickAccumulator
should stay as 0 at this point
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with you, but if you don't DA then it seems that the state at epoch 2 will be the same as the state in epoch 1. Since we set lastEpoch
to 1 in order to avoid triggering the rebalance in the first epoch, we will then trigger a rebalance in epoch 2. In this case we multiply epochsPassed
(in this case this value will be 1) by the max DA. So by leaving the state.tickAccumulator to 0, the DA in the first epoch will lead to the tickAccumulator going from 0 -> max DA, which is the same implied tickAccumulator as is in the unlockCallback
.
for (uint256 i; i < priceDiscoverySlugs.length; ++i) { | ||
newPositions[2 + i] = Position({ | ||
tickLower: priceDiscoverySlugs[i].tickLower, | ||
tickUpper: priceDiscoverySlugs[i].tickUpper, | ||
liquidity: priceDiscoverySlugs[i].liquidity, | ||
salt: uint8(3 + i) | ||
}); | ||
} | ||
|
||
_update(newPositions, sqrtPriceCurrent, sqrtPriceNext, key); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this reuse 🔥
No description provided.