Skip to content

Modifier shuffle#157

Merged
jubeira merged 39 commits intoreclamm-2.1from
dev/modifier-shuffle
Mar 6, 2026
Merged

Modifier shuffle#157
jubeira merged 39 commits intoreclamm-2.1from
dev/modifier-shuffle

Conversation

@EndymionJkb
Copy link
Collaborator

@EndymionJkb EndymionJkb commented Mar 2, 2026

Description

I seem to remember being the one to introduce and argue for the onlyWithinTargetRange, modifier, but I think it's more trouble than it's worth. It was only used once, required a bunch of helpers, caused multiple redundant calls, and had a bug besides.

In particular, several ReClamm view functions used the Vault’s last live balances (getPoolTokenInfo). For rate-bearing tokens, those balances become stale between interactions as rates accrue, causing isPoolWithinTargetRange and computeCurrentPoolCenteredness to report outdated results. Now everything uses current real and virtual balances.

We routed setCenterednessMargin through _updateVirtualBalances() to ensure centeredness checks are performed against freshly updated virtual balances/timestamp and live balances, reducing duplication and potential drift.

We removed the redundant isPoolWithinTargetRangeUsingCurrentVirtualBalances and updated interface docs/tests accordingly. Hopefully this isn't being used? If it is, we can keep it as a deprecated wrapper I guess.

One extraneous thing (could separate if too annoying)... I wanted to check the medusa tests, and made a fix there.

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Dependency changes
  • Code refactor / cleanup
  • Optimization: [ ] gas / [ ] bytecode
  • Documentation or wording changes
  • Other

Checklist:

  • The diff is legible and has no extraneous changes
  • Complex code has been commented, including external interfaces
  • Tests have 100% code coverage
  • The base branch is either main, or there's a description of how to merge

Issue Resolution

@EndymionJkb EndymionJkb changed the title Dev/modifier shuffle Modifier shuffle Mar 2, 2026
@EndymionJkb EndymionJkb requested a review from jubeira March 3, 2026 02:56
Base automatically changed from dev/fix-hooks to reclamm-2.1 March 3, 2026 12:05
Copy link
Contributor

@jubeira jubeira left a comment

Choose a reason for hiding this comment

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

First pass done.
I have some doubts about pool balances now that we're zooming in though.

…he for performance; for consistency, use current live balances in _updateVirtualBalances, to prevent rate drift; computeCurrentPoolCenteredness should call _computeCurrentVirtualBalances, like all other view functions; also address stale interface comments
@EndymionJkb EndymionJkb mentioned this pull request Mar 4, 2026
12 tasks
Copy link
Contributor

@jubeira jubeira left a comment

Choose a reason for hiding this comment

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

LGTM!
Just a few minor comments and questions; otherwise it's good to go.

Comment on lines +1708 to +1709
vm.prank(admin);
ReClammPool(pool).setDailyPriceShiftExponent(_DEFAULT_DAILY_PRICE_SHIFT_EXPONENT);
Copy link
Contributor

Choose a reason for hiding this comment

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

why is this needed here? Time has already been skipped at this point

(uint256 storedA, ) = ReClammPool(pool).getLastVirtualBalances();
uint256 diffFromLive = storedA > expectedFromLive ? storedA - expectedFromLive : expectedFromLive - storedA;
uint256 diffFromStale = storedA > expectedFromStale ? storedA - expectedFromStale : expectedFromStale - storedA;
assertLt(diffFromLive, diffFromStale, "Stored virtual balance A is closer to stale than to live");
Copy link
Contributor

Choose a reason for hiding this comment

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

I think I don't get what we're trying to prove here. Could you please clarify?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added comments to explain


function computeAddLiquidity(uint256 exactBptOut) public {
uint256 oldTotalSupply = ReClammPool(address(pool)).totalSupply();
if (oldTotalSupply < 1e18) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This came from trying to get the reverts down to 0 (from 100). It was an early attempt that didn't work (hypothesis that turned out to be wrong), and it turns out I don't need it.

@EndymionJkb EndymionJkb requested a review from jubeira March 5, 2026 22:14
Copy link
Contributor

@jubeira jubeira left a comment

Choose a reason for hiding this comment

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

Just a few final suggestions (comments only); LGTM!
Looks much more consistent than before now, thanks for pushing this @EndymionJkb.

@jubeira jubeira merged commit c12ea25 into reclamm-2.1 Mar 6, 2026
3 checks passed
@jubeira jubeira deleted the dev/modifier-shuffle branch March 6, 2026 13:24
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.

2 participants