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:
- A
Loanis deleted only byLoanDelete. - A
Loanis created only byLoanSet. - If
Loan.PaymentRemaining = 0, thenLoan.NextPaymentDueDateis absent or0. lsfLoanImpairedchanges only inLoanManageorLoanPay.lsfLoanDefaultchanges only inLoanManage, and is never cleared once set.lsfLoanOverpaymentnever changes.- The
LoanBrokerreferenced byLoan.LoanBrokerIDexists, and theVaultreferenced by that broker'sVaultIDexists. Loan.TotalValueOutstanding - Loan.PrincipalOutstanding - Loan.ManagementFeeOutstandingis not negative. For an IOU asset, a value of-1unit atLoan.LoanScaleis tolerated, because the three fields are rounded separately.- If a
LoanPaytransaction succeeds andLoan.PaymentRemainingis not0after it:Loan.PrincipalOutstandingdoes not increase.Loan.TotalValueOutstandingdoes not increase.- At least one of
Loan.PrincipalOutstandingandLoan.TotalValueOutstandingdecreases. Loan.PaymentRemainingdecreases.Loan.NextPaymentDueDateincreases by a positive multiple ofLoan.PaymentInterval.
3.2 Ledger Entry: LoanBroker¶
3.2.1 Invariants¶
Under LendingProtocolV1_1, the following are added to parent §3.1.8:
- At most one
LoanBrokeris deleted per transaction. - A
LoanBrokeris deleted only byLoanBrokerDelete. - Before deletion,
LoanBroker.OwnerCount = 0. - Before deletion,
LoanBroker.DebtTotalis0, or rounds toward zero to0at the precision of the Vault'sAssetsTotal. 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.