XRP Ledger Standards
XLS-66.4.3 Draft Amendment

Loan Invariants

Adds Loan and LoanBroker invariants on creation, deletion, flags and payments

Author
Vytautas Vito Tumas
Created
2026-11-25
Updated
2026-11-25
Discussion
XRPLF/XRPL-Standards/discussions/190
Amendment
LendingProtocolV1_1
Patch of
XLS-0066: Lending Protocol

66.4.3 Loan Invariants

1. Abstract

Under LendingProtocolV1_1, the protocol checks more invariants on Loan and LoanBroker ledger entries. Only LoanSet creates a Loan and only LoanDelete deletes one. Only LoanBrokerDelete deletes a LoanBroker, and only when it has no Loans and no debt. Loan flags change only through the transactions that own them, and a successful LoanPay must make progress on the Loan.

2. Motivation

The parent invariants check each Loan's balances in isolation. They do not check which transaction changed a Loan or a LoanBroker, so a defect in an unrelated transaction could create, delete or flag a Loan without failing. The added invariants bound each lending object to the transactions that are allowed to change it.

3. Specification

This patch adds to the parent XLS-66 invariants in §3.1.8 and §3.2.7. All other parent behavior is unchanged.

3.1 Ledger Entry: Loan

3.1.1 Invariants

Under LendingProtocolV1_1, the parent §3.2.7 invariants apply to each Loan the transaction created or modified, but not to a Loan it deleted. The parent check that lsfLoanOverpayment does not change is replaced by the unmodifiable-field check below. The following are added:

  1. A Loan is deleted only by LoanDelete.
  2. A Loan is created only by LoanSet.
  3. If Loan.PaymentRemaining = 0, then Loan.NextPaymentDueDate is absent or 0.
  4. lsfLoanImpaired changes only in LoanManage or LoanPay.
  5. lsfLoanDefault changes only in LoanManage, and is never cleared once set.
  6. lsfLoanOverpayment never changes.
  7. The LoanBroker referenced by Loan.LoanBrokerID exists, and the Vault referenced by that broker's VaultID exists.
  8. Loan.TotalValueOutstanding - Loan.PrincipalOutstanding - Loan.ManagementFeeOutstanding is not negative. For an IOU asset, a value of -1 unit at Loan.LoanScale is tolerated, because the three fields are rounded separately.
  9. If a LoanPay transaction succeeds and Loan.PaymentRemaining is not 0 after it:
    • Loan.PrincipalOutstanding does not increase.
    • Loan.TotalValueOutstanding does not increase.
    • At least one of Loan.PrincipalOutstanding and Loan.TotalValueOutstanding decreases.
    • Loan.PaymentRemaining decreases.
    • Loan.NextPaymentDueDate increases by a positive multiple of Loan.PaymentInterval.

3.2 Ledger Entry: LoanBroker

3.2.1 Invariants

Under LendingProtocolV1_1, the following are added to parent §3.1.8:

  1. At most one LoanBroker is deleted per transaction.
  2. A LoanBroker is deleted only by LoanBrokerDelete.
  3. Before deletion, LoanBroker.OwnerCount = 0.
  4. Before deletion, LoanBroker.DebtTotal is 0, or rounds toward zero to 0 at the precision of the Vault's AssetsTotal. The Vault must exist.

4. Rationale

LoanBrokerDelete accepts a DebtTotal that rounds to zero at the Vault precision; the deletion invariant uses the same test so that it never rejects a deletion the transaction allows. The tolerance on a Loan's interest due follows from the separate rounding of the three tracked fields at the Loan scale.

5. Security Considerations

These invariants do not change the result of a correct transaction. They turn a defect that would corrupt a Loan or LoanBroker into a failed transaction.