Skip to content

refactor: Move verifyAndAdjustLPTokenBalance onto AMMEntry - #8435

Open
mvadari wants to merge 3 commits into
mvadari/rearch/amm-initializeFeeAuctionVotefrom
mvadari/rearch/amm-verifyAndAdjustLPTokenBalance
Open

mvadari wants to merge 3 commits into
mvadari/rearch/amm-initializeFeeAuctionVotefrom
mvadari/rearch/amm-verifyAndAdjustLPTokenBalance

Conversation

@mvadari

@mvadari mvadari commented Sep 30, 2026

Copy link
Copy Markdown
Contributor

High Level Overview of Change

Moves verifyAndAdjustLPTokenBalance(sb, lpTokens, ammSle, account) onto the wrapper as the writable member AMMEntry::verifyAndAdjustLPTokenBalance(lpTokens, account) (gated by requires Base::kIsWritable). The member calls isOnlyLiquidityProvider with the entry's own view and calls update() on itself, as before. The body is in AMMEntry.cpp. AMMHelpers.h no longer uses AMMEntry.h, so that include is gone.

Context of Change

Part of the Wrapped SLEs migration (design: step 2/3 of #7886). The compiler now rejects a call on a read-only entry, and a caller cannot pass a view that does not match the entry. Pure refactor: no amendment, no behavior change; any observable difference is a bug.

Stacked on #8434; review only the last commit.

Both callers (AMMWithdraw, AMMClawback) already built the entry over the same Sandbox that they passed as sb.

This PR was fully written by AI (Claude Code) under human direction; the human author reviewed the diff.

API Impact

  • libxrpl change (any change that may affect libxrpl or dependents of libxrpl)

Test Plan

Compile-checked (clang++ -fsyntax-only with the project flags) every changed .cpp and every .cpp that includes AMMEntry.h or AMMHelpers.h, directly or through another header (31/31 pass). clang-tidy is clean on all changed .cpp and .h files. No new tests in this PR. CI runs the full unit test suite.

🤖 Generated with Claude Code

@ripple-ai-reviewer ripple-ai-reviewer Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pure refactor moving verifyAndAdjustLPTokenBalance from a free function taking (Sandbox&, ..., AMMEntryW&, ...) to a writable member AMMEntry::verifyAndAdjustLPTokenBalance(lpTokens, account). The body logic is copied verbatim (isOnlyLiquidityProvider check, relative-distance tolerance check, setFieldAmount + update()), just swapping the passed-in Sandbox/ammSle for this->applyView()/this. Both call sites (AMMWithdraw, AMMClawback) are updated consistently and still check the [[nodiscard]] std::expected result the same way as before. No changed-code correctness, security, or style issues stood out; the one behavioral assumption (that this->applyView() is equivalent to the Sandbox previously passed in) is asserted by the PR author and can't be verified from this diff alone, but I have no concrete evidence it's wrong.

@codecov

codecov Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.66667% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/libxrpl/ledger/entries/AMMEntry.cpp 90.0% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@mvadari
mvadari force-pushed the mvadari/rearch/amm-verifyAndAdjustLPTokenBalance branch from 9e5a3d0 to bb9a65d Compare September 30, 2026 17:48
@mvadari
mvadari added this pull request to stack #8445 September 30, 2026 17:48

@ripple-ai-reviewer ripple-ai-reviewer Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is a clean, mechanical refactor that moves verifyAndAdjustLPTokenBalance from a free function in AMMHelpers onto AMMEntry as a writable-only member. The new member method preserves the original logic exactly (same tolerance check, same LPTokenBalance update, same error path), just substituting this->applyView()/this->update()/Base::operator->() for the old sb/ammSle.update()/ammSle-> parameters. Call sites in AMMWithdraw.cpp and AMMClawback.cpp are updated consistently, and the now-unused AMMEntry.h include was correctly dropped from AMMHelpers.h. No behavioral change is evident in the diff, and the header declaration correctly gates the member with requires Base::kIsWritable, matching the existing pattern used by initializeFeeAuctionVote in the same class.

@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown

This PR has conflicts, please resolve them in order for the PR to be reviewed.

@mvadari
mvadari force-pushed the mvadari/rearch/amm-verifyAndAdjustLPTokenBalance branch from bb9a65d to 0696761 Compare October 5, 2026 13:45
@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown

All conflicts have been resolved. Assigned reviewers can now start or resume their review.

@mvadari
mvadari force-pushed the mvadari/rearch/amm-verifyAndAdjustLPTokenBalance branch from 0696761 to 115c4ae Compare October 5, 2026 13:50

@ripple-ai-reviewer ripple-ai-reviewer Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Clean, mechanical refactor that moves the free function verifyAndAdjustLPTokenBalance into a writable-only member of AMMEntry, replacing the Sandbox&/AMMEntryW& parameters with this->applyView()/this. The function body logic (isOnlyLiquidityProvider check, tolerance check, setFieldAmount, update) is preserved verbatim, both call sites (AMMWithdraw, AMMClawback) are updated consistently, and the now-unused AMMEntry.h include is correctly dropped from AMMHelpers.h. New includes added to AMMEntry.cpp (Number.h, Issue.h) match the newly-needed symbols. No behavioral change is evident in the diff.

@mvadari
mvadari force-pushed the mvadari/rearch/amm-verifyAndAdjustLPTokenBalance branch from 115c4ae to e0b5eab Compare November 9, 2026 17:46

@ripple-ai-reviewer ripple-ai-reviewer Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found.

Replace the free verifyAndAdjustLPTokenBalance(sb, lpTokens, ammSle,
account) with the writable member
AMMEntry::verifyAndAdjustLPTokenBalance(lpTokens, account). The member
checks the LP through the entry's own view, which both callers already
built over the same Sandbox.

AMMHelpers.h no longer uses AMMEntry.h, so drop that include.
@github-actions

Copy link
Copy Markdown

This PR has conflicts, please resolve them in order for the PR to be reviewed.

@mvadari
mvadari force-pushed the mvadari/rearch/amm-verifyAndAdjustLPTokenBalance branch from e0b5eab to 97db006 Compare November 10, 2026 02:30

@ripple-ai-reviewer ripple-ai-reviewer Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found.

@github-actions

Copy link
Copy Markdown

All conflicts have been resolved. Assigned reviewers can now start or resume their review.

…ri/rearch/amm-verifyAndAdjustLPTokenBalance

# Conflicts:
#	src/libxrpl/ledger/helpers/AMMHelpers.cpp

This branch has not been deployed

No deployments
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.

1 participant