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

Fix Doppler Fee Disbursement #331

Merged
merged 9 commits into from
Feb 5, 2025

Conversation

saucepoint
Copy link
Contributor

@saucepoint saucepoint commented Feb 4, 2025

Doppler was collecting fees during rebalancing and NOT using them towards new slugs. Additionally, only the last set of slugs were transferred in migration

This lead to unaccounted for fees during migrations, leaving tokens in Airlock that were unrecoverable

Closes #321, #325, #314

@saucepoint saucepoint marked this pull request as ready for review February 4, 2025 04:59
@saucepoint saucepoint changed the title DRAFT: Fix Doppler Fee Disbursement Fix Doppler Fee Disbursement Feb 4, 2025
src/Doppler.sol Outdated
Comment on lines 1292 to 1305
uint256 extraBalance0 = poolKey.currency0.balanceOfSelf();
uint256 extraBalance1 = poolKey.currency1.balanceOfSelf();
poolKey.currency0.transfer(recipient, extraBalance0);
poolKey.currency1.transfer(recipient, extraBalance1);

(sqrtPriceX96,,,) = poolManager.getSlot0(poolKey.toId());
token0 = Currency.unwrap(poolKey.currency0);
token1 = Currency.unwrap(poolKey.currency1);

// No need to safe cast since these amounts will always be positive
fees0 = uint128(totalFeesAccrued.amount0());
balance0 = uint128(totalCallerDelta.amount0());
balance0 = uint128(slugCallerDelta.amount0()) + extraBalance0.toUint128();
fees1 = uint128(totalFeesAccrued.amount1());
balance1 = uint128(totalCallerDelta.amount1());
balance1 = uint128(slugCallerDelta.amount1()) + extraBalance1.toUint128();
Copy link
Contributor Author

@saucepoint saucepoint Feb 4, 2025

Choose a reason for hiding this comment

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

@clemlak @0xleastwood

Im a slightly worried about the extraBalance.toUint128() -- if it reverts on overflow, were gonna brick migrations and have stuck capital

the question is -- is there a scenario where the unaccounted for balances (i.e. rebalanced slug dust, accrued fees, excess tokens, etc would exceed uint128.max 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the safety precaution might be to set balance0 = uint128.max if its gonna overflow, so that migrations can still happen?

Copy link
Collaborator

Choose a reason for hiding this comment

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

It seems to be an edge case but I think it's best to cover it just in case.

@saucepoint
Copy link
Contributor Author

@clemlak ready for review again, i think tests are failing since im not apart of the repo

@clemlak
Copy link
Collaborator

clemlak commented Feb 5, 2025

@clemlak ready for review again, i think tests are failing since im not apart of the repo

Yes, these tests are failing due to a missing RPC in your fork, everything looks good on my end 👌

@clemlak clemlak merged commit 54cfeb3 into whetstoneresearch:main Feb 5, 2025
1 check failed
@clemlak clemlak linked an issue Feb 5, 2025 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants