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

Avoid first epoch rebalance #169

Merged
merged 7 commits into from
Oct 24, 2024
Merged

Avoid first epoch rebalance #169

merged 7 commits into from
Oct 24, 2024

Conversation

kinrezC
Copy link
Collaborator

@kinrezC kinrezC commented Oct 24, 2024

No description provided.

@kinrezC kinrezC requested a review from kadenzipfel October 24, 2024 17:54
@kinrezC kinrezC linked an issue Oct 24, 2024 that may be closed by this pull request
Copy link
Collaborator

@kadenzipfel kadenzipfel left a 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;
Copy link
Collaborator

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;
Copy link
Collaborator

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

Copy link
Collaborator Author

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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this reuse 🔥

@kinrezC kinrezC merged commit 7374069 into main Oct 24, 2024
1 check passed
@clemlak clemlak deleted the fix/avoid-first-epoch-rebalance branch November 5, 2024 06:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Epoch issues
2 participants