Skip to content

(Release 3.1) Lending protocol - ongoing work - XLS-66#6156

Merged
ximinez merged 26 commits intorelease-3.1from
ximinez/lending-3.1
Jan 12, 2026
Merged

(Release 3.1) Lending protocol - ongoing work - XLS-66#6156
ximinez merged 26 commits intorelease-3.1from
ximinez/lending-3.1

Conversation

@ximinez
Copy link
Collaborator

@ximinez ximinez commented Dec 18, 2025

High Level Overview of Change

This PR is to apply the same code changes as are in #6102, to the release-3.1 branch.

This PR continues the work started in #5270 and #6093. All new code changes that affect Lending should be done in this branch. That includes PRs.

Implement the Lending Protocol as described in XLS-66

Context of Change

Note: A lot of the changes in this branch are going to be cherry-picked from develop or ximinez/lending-XLS-66-ongoing. That branch has had some significant refactors, in particular, renaming from rippled to xrpld. I'm not going to make any significant effort to undo name changes that don't affect the build. Specifically, that will means strings, such as in XRPL_ASSERTs.

Type of Change

  • New feature (non-breaking change which adds functionality)
  • Refactor (non-breaking change that only restructures code)
  • Tests (you added tests for code that already exists, or your new feature included in this PR)

API Impact

  • Public API: New feature (new methods and/or new fields)
  • Public API: Breaking change (in general, breaking changes should only impact the next api_version)
  • libxrpl change (any change that may affect libxrpl or dependents of libxrpl)
  • Peer protocol change (must be backward compatible or bump the peer protocol version)

Tapanito and others added 14 commits December 18, 2025 11:20
- Originally defined as uint64_t, but the testIssuerLoan() test called
  it with a negative number, causing an overflow to a very large number
  that in some circumstances could be silently cast back to an int64_t,
  but might not be. I believe this is UB, and we don't want to rely on
  that.
- Adds additional unit tests to cover math calculations.
- Removes unused methods.
- add nodiscard to unimpairLoan, and check result in LoanPay
- add a check to verify that issuer exists
- improve LoanManage error code for dust amounts
- In overpayment results, the management fee was being calculated twice:
  once as part of the value change, and as part of the fees paid.
  Exclude it from the value change.
Co-authored-by: Shawn Xie <35279399+shawnxie999@users.noreply.github.com>
- Round the initial total value computation upward, unless there is
  0-interest.
- Rename getVaultScale to getAssetsTotalScale, and convert one incorrect
  computation to use it.
- Use adjustImpreciseNumber for LossUnrealized.
- Add some logging to computeLoanProperties.
@codecov
Copy link

codecov bot commented Dec 18, 2025

Codecov Report

❌ Patch coverage is 96.15385% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.3%. Comparing base (418ce68) to head (96f8550).
⚠️ Report is 1 commits behind head on release-3.1.

Files with missing lines Patch % Lines
src/xrpld/app/misc/detail/LendingHelpers.cpp 97.1% 3 Missing ⚠️
src/xrpld/app/tx/detail/LoanSet.cpp 92.0% 2 Missing ⚠️
src/libxrpl/ledger/View.cpp 97.1% 1 Missing ⚠️
src/xrpld/app/tx/detail/LoanBrokerDelete.cpp 75.0% 1 Missing ⚠️
src/xrpld/app/tx/detail/LoanPay.cpp 96.0% 1 Missing ⚠️
src/xrpld/rpc/handlers/LedgerEntry.cpp 0.0% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@              Coverage Diff              @@
##           release-3.1   #6156     +/-   ##
=============================================
+ Coverage         79.3%   79.3%   +0.1%     
=============================================
  Files              837     837             
  Lines            71432   71444     +12     
  Branches          8295    8243     -52     
=============================================
+ Hits             56611   56667     +56     
+ Misses           14821   14777     -44     
Files with missing lines Coverage Δ
include/xrpl/ledger/View.h 100.0% <ø> (ø)
include/xrpl/protocol/detail/ledger_entries.macro 100.0% <ø> (ø)
src/libxrpl/ledger/Credit.cpp 100.0% <ø> (ø)
src/xrpld/app/misc/LendingHelpers.h 95.0% <100.0%> (+0.3%) ⬆️
src/xrpld/app/paths/Flow.cpp 94.3% <ø> (ø)
src/xrpld/app/paths/detail/DirectStep.cpp 80.6% <ø> (ø)
src/xrpld/app/paths/detail/StrandFlow.h 89.5% <ø> (ø)
src/xrpld/app/paths/detail/XRPEndpointStep.cpp 82.8% <ø> (ø)
...rc/xrpld/app/tx/detail/LoanBrokerCoverClawback.cpp 97.8% <100.0%> (+<0.1%) ⬆️
src/xrpld/app/tx/detail/LoanBrokerCoverDeposit.cpp 94.8% <100.0%> (ø)
... and 12 more

... and 4 files with indirect coverage changes

Impacted file tree graph

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Tapanito and others added 4 commits December 19, 2025 13:02
- Adds loan state to LoanProperties.
- Cleans up computeLoanProperties.
- Fixes missing management fee from overpayment.
* Replace accountHolds with accountSpendable when checking
for account funds in VaultDeposit and LoanBrokerCoverDeposit
- Updates or fixes a couple of things I noticed while reviewing changes
  to the spec.
- Rename sfPreviousPaymentDate to sfPreviousPaymentDueDate.
- Make the vault asset cap check added in #6124 a little more robust:
  1. Check in preflight if the vault is _already_ over the limit.
  2. Prevent overflow when checking with the loan value. (Subtract
     instead of adding, in case the values are near maxint. Both return
     the same result. Also add a unit test so each case is covered.
Tapanito and others added 3 commits January 8, 2026 18:37
- Fixes LoanManage tfBAD_LEDGER case by capping the amount of FLC to use to cover a loss at the amount of cover available.
- Check if the Vault pseudo-account is frozen in LoanBrokerSet
…6117)

- Check the trust line limit is not exceeded for a withdraw to a third party Destination account.
…nez/lending-3.1

* mywork/ximinez/vault-fix-3.1:
  VaultClawback: Burn shares of an empty vault (6120)
  fix: Inner batch transactions never have valid signatures (6069)
  fix: Reorder Batch Preflight Errors (6176)
- Add minimum grace period validation (#6133)
- VaultClawback: Burn shares of an empty vault (#6120)
- LoanSet transaction added in #6120 failed the minimum grace period
  added by #6133.
@ximinez ximinez force-pushed the ximinez/lending-3.1 branch from 6ea71f9 to 8fc2551 Compare January 11, 2026 04:25
@ximinez
Copy link
Collaborator Author

ximinez commented Jan 11, 2026

Do not merge until after #6203

- Reduce code duplication in LoanBrokerDelete
- Reorder "canWithdraw" parameters to put "view" first
- Combine accountSpendable into accountHolds
- Avoid copies by taking a reference for the claw amount
- Return function results directly
- Fix typo for "parseLoan" in ledger_entry RPC
- Improve some comments and unused variables
- No need for late payment components lambda
- Add explanatory comment for computeLoanProperties
- Add comment linking computeRawLoanState to spec
- Fix typo: TrueTotalPrincipalOutstanding
- Fix missed ripple -> xrpl update
- Remove unnecessary "else"s.
- Clean up std::visit in accountHolds.
@ximinez ximinez merged commit 91d239f into release-3.1 Jan 12, 2026
26 checks passed
@ximinez ximinez deleted the ximinez/lending-3.1 branch January 12, 2026 23:08
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.

5 participants