Skip to content

refactor: Use AMMEntry everywhere - #8363

Open
mvadari wants to merge 4 commits into
developfrom
mvadari/rearch/amm-entry
Open

mvadari wants to merge 4 commits into
developfrom
mvadari/rearch/amm-entry

Conversation

@mvadari

@mvadari mvadari commented Sep 30, 2026

Copy link
Copy Markdown
Contributor

High Level Overview of Change

Replace raw AMM SLE pointers with AMMEntryR/AMMEntryW in the AMM transactors, AMMHelpers, BookStep, StepChecks.h, TrustSet, and the LPToken checks in View.cpp and TokenHelpers.cpp. Helpers that take an AMM SLE (ammHolds, ammLPHolds, getTradingFee, initializeFeeAuctionVote, verifyAndAdjustLPTokenBalance, and the private AMMWithdraw/AMMClawback members) now take AMMEntryR const& or AMMEntryW&. No helper moves onto the wrapper in this PR.

Context of Change

Part of the Wrapped SLEs migration (design: step 2/3 of #7886). The AMM parameters are now typed, so the compiler rejects an SLE of the wrong type and enforces read-only vs. writable access. Pure refactor: no amendment, no behavior change; any observable difference is a bug.

AMMInfo and the jtx AMM helper wrap their existing SLE to match the new ammLPHolds signature. TheoreticalQuality_test no longer uses a const PaymentSandbox, because read-only entries peek() through an ApplyView (see SLEBase.h); BookStep now reads the AMM through AMMEntryR.

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) every changed .cpp and every includer of the changed headers (26 files), ran clang-tidy on the changed .cpp files, and ran pre-commit. No new tests. 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.

This is a large, mechanical refactor swapping raw AMM SLE pointers for the AMMEntryR/AMMEntryW wrapper types across the AMM transactors, AMMHelpers, BookStep, StepChecks, TrustSet, and the LPToken checks in View.cpp/TokenHelpers.cpp. I checked every changed call site for argument-order swaps (asset vs asset2), lost update()/insert()/erase() calls, wrong AMMEntryR/AMMEntryW construction overloads, and lifetime issues with the if-init-statement patterns (BookStep, AMMCreate) — all are consistent 1:1 replacements of the prior SLE-based logic. Field access (ammSle[sfX] -> (*ammSle)[sfX]) and mutation flows (setField... followed by .update()) match the original control flow exactly. No behavioral divergence was found in the visible diff; the mechanical nature of the change and the author's stated compile/clang-tidy verification are consistent with what I observed.

@codecov

codecov Bot commented Sep 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copilot AI 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.

Copilot review overview

🔵 Needs a closer look

The broad refactor touches consensus-critical AMM transaction and payment-path processing and warrants final human validation.

Review effort: Balanced
Findings: None

What changed in this PR

Refactors AMM ledger access to use typed AMMEntryR/AMMEntryW wrappers across transaction processing, payment paths, ledger helpers, RPC, and tests.

Changes:

  • Replaces raw AMM SLE reads and writes with typed wrappers.
  • Updates AMM helper and transactor interfaces accordingly.
  • Adjusts test and RPC call sites for the new interfaces.
File Description
src/​xrpld/​rpc/​handlers/​orderbook/​AMMInfo.cpp Wraps AMM entries for LP balance lookup.
src/​test/​jtx/​impl/​AMM.cpp Updates AMM test helpers.
src/​test/​app/​TheoreticalQuality_test.cpp Makes the sandbox mutable for wrapper reads.
src/​libxrpl/​tx/​transactors/​token/​TrustSet.cpp Uses typed AMM lookup.
src/​libxrpl/​tx/​transactors/​dex/​AMMWithdraw.cpp Migrates withdrawal processing to typed entries.
src/​libxrpl/​tx/​transactors/​dex/​AMMVote.cpp Migrates voting reads and updates.
src/​libxrpl/​tx/​transactors/​dex/​AMMDeposit.cpp Migrates deposit reads and updates.
src/​libxrpl/​tx/​transactors/​dex/​AMMDelete.cpp Uses typed AMM lookup.
src/​libxrpl/​tx/​transactors/​dex/​AMMCreate.cpp Uses typed AMM creation and insertion.
src/​libxrpl/​tx/​transactors/​dex/​AMMClawback.cpp Migrates clawback processing.
src/​libxrpl/​tx/​transactors/​dex/​AMMBid.cpp Migrates bidding reads and updates.
src/​libxrpl/​tx/​paths/​BookStep.cpp Uses typed AMM access during path construction.
src/​libxrpl/​ledger/​View.cpp Uses typed AMM lookup for LP transfers.
src/​libxrpl/​ledger/​helpers/​TokenHelpers.cpp Uses typed AMM lookup for token checks.
src/​libxrpl/​ledger/​helpers/​AMMHelpers.cpp Updates helper implementations and mutations.
include/​xrpl/​tx/​transactors/​dex/​AMMWithdraw.h Updates withdrawal interfaces.
include/​xrpl/​tx/​transactors/​dex/​AMMClawback.h Updates clawback interfaces.
include/​xrpl/​tx/​paths/​detail/​StepChecks.h Uses typed AMM lookup in freeze checks.
include/​xrpl/​ledger/​helpers/​AMMHelpers.h Exposes typed helper signatures.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@mvadari mvadari mentioned this pull request Sep 30, 2026
1 task done
@mvadari
mvadari force-pushed the mvadari/rearch/amm-entry branch from b8ef34e to c46c5c8 Compare September 30, 2026 17:33

@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 mechanical, well-scoped refactor swapping raw AMM SLE pointers for AMMEntryR/AMMEntryW across the AMM transactors, AMMHelpers, BookStep, StepChecks.h, TrustSet, and the LPToken checks in View.cpp/TokenHelpers.cpp. All the dereference/access patterns ((*ammSle)[...], ammSle->...) are used consistently with the new wrapper types, and the changed call sites line up with the updated header signatures (ammHolds, ammLPHolds, getTradingFee, initializeFeeAuctionVote, verifyAndAdjustLPTokenBalance, and the AMMWithdraw/AMMClawback private helpers). No SQL/command injection, hardcoded secrets, or obvious logic inversions were found in the added lines. The one spot worth a second look is the new mutableRawSle() / dirLink interaction in AMMCreate.cpp, flagged below as a low-confidence note rather than a confirmed bug, since AMMEntryW's internals aren't part of this diff.

@mvadari
mvadari added this pull request to stack #8445 September 30, 2026 17:48
@mvadari
mvadari force-pushed the mvadari/rearch/amm-entry branch from c46c5c8 to f0c32fa Compare October 5, 2026 12:55

@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 careful, mechanical refactor swapping raw AMM SLE pointers for the typed AMMEntryR/AMMEntryW wrapper across the AMM transactors, AMMHelpers, BookStep, StepChecks, TrustSet, and the LP-token checks in View.cpp/TokenHelpers.cpp. Call sites consistently preserve existing control flow (null checks, update()/insert()/erase() calls map 1:1 to the old sb.update/insert/erase calls), and the signature changes (SLE const& -> AMMEntryR const&, SLE::pointer& -> AMMEntryW&) are threaded consistently through headers and .cpp files with no mismatched overloads spotted. The one place worth a sanity check (not flagged as a confident bug) is AMMCreate.cpp's new ammSle.mutableRawSle() copy passed into dirLink, which the author already called out in a comment as relying on shared_ptr aliasing rather than pointer reseating — worth confirming dirLink's actual signature doesn't reassign the pointer, but given the explicit comment and the author's stated compile/clang-tidy verification, I don't have enough signal to assert this is wrong. No changed line otherwise shows a logic inversion, resource leak, or security issue; the diff reads as behavior-preserving as claimed.

@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.

Replace raw AMM SLE pointers with AMMEntryR/AMMEntryW in the AMM
transactors, AMMHelpers, the payment path steps, TrustSet, and the
LPToken checks in View.cpp and TokenHelpers.cpp. Helpers that take an
AMM SLE (ammHolds, ammLPHolds, getTradingFee, initializeFeeAuctionVote,
verifyAndAdjustLPTokenBalance, and the AMMWithdraw/AMMClawback private
members) now take AMMEntryR const& or AMMEntryW& and stay where they
are.

AMMInfo and the jtx AMM helper wrap their existing SLE to match the new
ammLPHolds signature. TheoreticalQuality_test no longer uses a const
PaymentSandbox, because read-only entries peek() through an ApplyView.

No behavior change.
@mvadari
mvadari force-pushed the mvadari/rearch/amm-entry branch from f0c32fa to b255632 Compare November 9, 2026 22:33
@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown

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

@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.

@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.

Copilot AI 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.

🟢 Approval recommended

No active review issues remain for the migration to explicit read-only and writable AMM entry wrappers.

No open issues 🎉

Review effort: Balanced

@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.

Copilot AI 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.

🔵 Needs a closer look

Read-only AMM lookups now inherit SLEBase’s const_cast-based ApplyView::peek resolution, requiring human validation of const-view usage and behavior equivalence in public helpers and consensus path construction.

No open issues 🎉

Review effort: Balanced

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.

2 participants