Skip to content

Fix HookAPI Expected and Refactor Enum classes#729

Open
tequdev wants to merge 35 commits intoXahau:devfrom
tequdev:fix-refactor-HookAPI-Expected
Open

Fix HookAPI Expected and Refactor Enum classes#729
tequdev wants to merge 35 commits intoXahau:devfrom
tequdev:fix-refactor-HookAPI-Expected

Conversation

@tequdev
Copy link
Copy Markdown
Member

@tequdev tequdev commented Apr 14, 2026

High Level Overview of Change

Context of Change

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • Refactor (non-breaking change that only restructures code)

RichardAH and others added 28 commits February 24, 2026 16:07
* Add AMM bid/create/deposit/swap/withdraw/vote invariants:
  - Deposit, Withdrawal invariants: `sqrt(asset1Balance * asset2Balance) >= LPTokens`.
  - Bid: `sqrt(asset1Balance * asset2Balance) > LPTokens` and the pool balances don't change.
  - Create: `sqrt(asset1Balance * assetBalance2) == LPTokens`.
  - Swap: `asset1BalanceAfter * asset2BalanceAfter >= asset1BalanceBefore * asset2BalanceBefore`
     and `LPTokens` don't change.
  - Vote: `LPTokens` and pool balances don't change.
  - All AMM and swap transactions: amounts and tokens are greater than zero, except on withdrawal if all tokens
    are withdrawn.
* Add AMM deposit and withdraw rounding to ensure AMM invariant:
  - On deposit, tokens out are rounded downward and deposit amount is rounded upward.
  - On withdrawal, tokens in are rounded upward and withdrawal amount is rounded downward.
* Add Order Book Offer invariant to verify consumed amounts. Consumed amounts are less than the offer.
* Fix Bid validation. `AuthAccount` can't have duplicate accounts or the submitter account.
Due to rounding, the LPTokenBalance of the last LP might not match the LP's trustline balance. This was fixed for `AMMWithdraw` in `fixAMMv1_1` by adjusting the LPTokenBalance to be the same as the trustline balance. Since `AMMClawback` is also performing a withdrawal, we need to adjust LPTokenBalance as well in `AMMClawback.`

This change includes:
1. Refactored `verifyAndAdjustLPTokenBalance` function in `AMMUtils`, which both`AMMWithdraw` and `AMMClawback` call to adjust LPTokenBalance.
2. Added the unit test `testLastHolderLPTokenBalance` to test the scenario.
3. Modify the existing unit tests for `fixAMMClawbackRounding`.
Backport of XRPLF/rippled#6325. The python version runs ~80x faster.
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 29, 2026

Codecov Report

❌ Patch coverage is 72.82609% with 50 lines in your changes missing coverage. Please review.
✅ Project coverage is 66.62%. Comparing base (9b50b68) to head (1ffd525).

Files with missing lines Patch % Lines
src/xrpld/app/hook/detail/applyHook.cpp 41.30% 25 Missing and 2 partials ⚠️
src/xrpld/app/hook/HookAPI.h 89.76% 11 Missing and 2 partials ⚠️
src/xrpld/app/hook/detail/HookAPI.cpp 9.09% 9 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev     #729      +/-   ##
==========================================
+ Coverage   66.56%   66.62%   +0.05%     
==========================================
  Files         837      837              
  Lines       78540    78525      -15     
  Branches    44600    44614      +14     
==========================================
+ Hits        52283    52314      +31     
+ Misses      17861    17841      -20     
+ Partials     8396     8370      -26     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread src/xrpld/app/hook/detail/applyHook.cpp Outdated
Comment thread src/xrpld/app/hook/detail/applyHook.cpp Outdated
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.

6 participants