Skip to content
Open
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
3ff8d35
rebase to main
oeggert May 15, 2025
597eb9b
add diagram and reviewer suggestions for concept topic
oeggert Aug 27, 2025
233895d
update reference docs for loanbroker transactions.
oeggert Aug 28, 2025
40039e9
update to latest spec
oeggert Sep 5, 2025
401be5f
fix sidebar
oeggert Sep 5, 2025
847b991
Update docs/xls-66d-lending-protocol/concepts/lending-protocol.md
oeggert Sep 25, 2025
31bf7ed
remove loandraw transaction
oeggert Sep 25, 2025
813ee97
fix references to assetsavailable and startdate
oeggert Sep 25, 2025
a24c79a
update loanbrokerset with modifiable fields
oeggert Sep 25, 2025
adc90e9
add totalvalueoutstanding and princpalrequested fields to loan ledger…
oeggert Oct 16, 2025
3e34cca
Update sidebars.yaml
amarantha-k Oct 22, 2025
c11634b
Fix link to docs
amarantha-k Oct 22, 2025
b446e7e
updated loanpay with loanoverpayment flag
oeggert Oct 23, 2025
b563b4e
add loan payment psuedo code
oeggert Oct 23, 2025
1badaa0
highlight configurability in concept intro
oeggert Oct 23, 2025
e4ef7b5
add use case doc
oeggert Oct 23, 2025
2f2c335
update based on recent spec
oeggert Oct 28, 2025
05fd8de
update to latest spec
oeggert Oct 30, 2025
14f5e97
add info for signature_target field
oeggert Oct 31, 2025
8f508fe
add reviewer suggestions
oeggert Nov 3, 2025
7e9f003
add reviewer suggestions
oeggert Nov 4, 2025
22e93a4
add @maria-robobug suggestions
oeggert Nov 4, 2025
4190eed
clean up up formatting on late payment formula
oeggert Nov 4, 2025
f6f11d3
Update docs/xls-66d-lending-protocol/reference/ledger-data/loan.md
oeggert Nov 5, 2025
36e143d
Update docs/xls-66d-lending-protocol/reference/ledger-data/loanbroker.md
oeggert Nov 5, 2025
fa78247
Update docs/xls-66d-lending-protocol/use-cases/institutional-credit-f…
oeggert Nov 5, 2025
9264e88
Update docs/xls-66d-lending-protocol/reference/transactions/loanbroke…
oeggert Nov 5, 2025
95c9d70
Update docs/xls-66d-lending-protocol/reference/transactions/loanbroke…
oeggert Nov 5, 2025
cfbdc67
update internal data type name
oeggert Nov 5, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions docs/_snippets/common-links.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
[ACCOUNT_ZERO]: https://xrpl.org/docs/concepts/accounts/addresses#special-addresses
[AccountID]: https://xrpl.org/docs/references/protocol/binary-format/#accountid-fields
[AccountDelete]: https://xrpl.org/docs/references/protocol/transactions/types/accountdelete
[Address]: https://xrpl.org/docs/references/protocol/data-types/basic-data-types#addresses
[amendment]: https://xrpl.org/docs/concepts/networks-and-servers/amendments
[common fields]: https://xrpl.org/docs/references/protocol/transactions/common-fields/
[common ledger entry fields]: https://xrpl.org/docs/references/protocol/ledger-data/common-fields/
[credentials]: https://xrpl.org/docs/concepts/decentralized-storage/credentials
[EscrowFinish]: https://xrpl.org/docs/references/protocol/transactions/types/escrowfinish
[`flags` field]: https://xrpl.org/docs/references/protocol/transactions/common-fields#flags-field
[Hash]: https://xrpl.org/docs/references/protocol/data-types/basic-data-types#hashes
[Internal Type]: https://xrpl.org/docs/references/protocol/binary-format/
[ledger entry ID]: https://xrpl.org/docs/references/protocol/ledger-data/common-fields/
Expand All @@ -14,19 +16,18 @@
[ledger index]: https://xrpl.org/docs/references/protocol/data-types/basic-data-types/#ledger-index
[PaymentChannelClaim]: https://xrpl.org/docs/references/protocol/transactions/types/paymentchannelclaim
[Payment]: https://xrpl.org/docs/references/protocol/transactions/types/payment
[PermissionedDomain entry]: /docs/xls-80d-permissioned-domains/permissioneddomain.md
[PermissionedDomainSet transaction]: /docs/xls-80d-permissioned-domains/permissioneddomainset.md
[PermissionedDomainDelete transaction]: /docs/xls-80d-permissioned-domains/permissioneddomaindelete.md
[reserve requirement]: https://xrpl.org/docs/concepts/accounts/reserves
[seconds since the Ripple Epoch]: https://xrpl.org/docs/references/protocol/data-types/basic-data-types#specifying-time
[SHA-512Half]: https://xrpl.org/docs/references/protocol/data-types/basic-data-types#hashes
[Specifying Ledgers]: https://xrpl.org/docs/references/protocol/data-types/basic-data-types/#specifying-ledgers
[standard format]: https://xrpl.org/docs/references/http-websocket-apis/api-conventions/response-formatting/
[transaction result codes]: https://xrpl.org/docs/references/protocol/transactions/transaction-results
[universal error types]: https://xrpl.org/docs/references/http-websocket-apis/api-conventions/error-formatting#universal-errors

[PermissionedDomain entry]: /docs/xls-80d-permissioned-domains/permissioneddomain.md
[PermissionedDomainSet transaction]: /docs/xls-80d-permissioned-domains/permissioneddomainset.md
[PermissionedDomainDelete transaction]: /docs/xls-80d-permissioned-domains/permissioneddomaindelete.md
<!-- TODO: replace with link to roadmap page when that's ready -->
[PermissionedDomains amendment]: /docs/xls-80d-permissioned-domains/index.page.tsx
[Single Asset Vault amendment]: https://github.com/XRPLF/XRPL-Standards/tree/master/XLS-0065d-single-asset-vault

[Lending Protocol amendment]: https://github.com/XRPLF/XRPL-Standards/tree/master/XLS-0066d-lending-protocol
[PermissionedDEX amendment]: /docs/xls-81d-permissioned-dexes/index.page.tsx
[PermissionedDomains amendment]: /docs/xls-80d-permissioned-domains/index.page.tsx
[Single Asset Vault amendment]: https://github.com/XRPLF/XRPL-Standards/tree/master/XLS-0065-single-asset-vault
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
198 changes: 198 additions & 0 deletions docs/xls-66d-lending-protocol/concepts/lending-protocol.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
---
seo:
description: The XRPL Lending Protocol enables on-chain, uncollateralized fixed-term loans.
labels:
- Decentralized Finance
- Lending Protocol
---
# Lending Protocol

The Lending Protocol is an XRP Ledger DeFi primitive that enables on-chain, fixed-term, uncollateralized loans using pooled funds from a [Single Asset Vault](https://opensource.ripple.com/docs/xls-65d-single-asset-vault). The protocol is highly configurable, enabling loan brokers to easily tune risk appetite, depostitor protections, and economic incentives.

The implementation relies on off-chain underwriting and risk management to assess the creditworthiness of borrowers, but offers peer-to-peer loans without intermediaries like banks or financial institutions. First-loss capital protection is used to help offset losses from loan defaults.

The current implementation of the lending protocol doesn't include automated on-chain collateral and liquidation management, instead focusing on on-chain credit origination.

To ensure compliance needs are met, asset issuers can [claw back](https://xrpl.org/docs/references/protocol/transactions/types/clawback) funds from the vault associated with the lending protocol. Issuers can also [freeze](https://xrpl.org/docs/concepts/tokens/fungible-tokens/freezes) individual accounts or issue a global freeze.

## Protocol Flow

There are three parties involved in the process of creating a loan:

- **Loan Brokers**: Create asset vaults and manage associated loans.
- **Depositors**: Add assets to vaults.
- **Borrowers**: Receive loans, making repayments as defined by their loan terms.

[{% inline-svg file="./lending-protocol-diagram.svg" /%}](./lending-protocol-diagram.svg "Diagram: The lifecycle of a loan.")

The lifecycle of a loan is as follows:

1. A loan broker creates a vault.
2. Depositors add assets to the vault.
3. (Optional) The loan broker deposits first-loss capital.
4. A loan broker and borrower create a loan, defining the terms of the loan, and the requested principal (excluding fees) is transferred to the borrower.
5. If payments are missed, the loan enters a grace period. Once the grace period expires, the loan broker has the option to default the loan.
6. The loan is deleted when matured or defaulted.
7. (Optional) The loan broker can withdraw first-loss capital.
8. After all loans are paid, the loan broker can delete the `LoanBroker` ledger entry, and then the corresponding `Vault` ledger entry.


## Accounting

### Risk Management

#### First-Loss Capital

First-Loss Capital is an optional mechanism to mitigate the risks associated with lending. To protect investors' assets, a loan broker can deposit assets as first-loss capital, which acts as a buffer in the event of loan defaults. The first-loss capital is placed into the vault to cover a percentage of losses from missed payments.

Three parameters control the First-Loss Capital:

- `CoverAvailable`: The total amount of cover deposited by the lending protocol owner.
- `CoverRateMinimum`: The percentage of debt that must be covered by `CoverAvailable`.
- `CoverRateLiquidation`: The maximum percentage of the minimum required cover _(DebtTotal x CoverRateMinimum)_ that will be placed in the asset vault to cover a loan default.

Whenever the available cover falls below the minimum required:

- The loan broker can't issue new loans.
- The loan broker can't receive fees. All fees are added to the First-Loss Capital to cover the deficit.

Below is an example of how first-loss capital is used to cover a loan default:

```
** Initial States **

-- Vault --
AssetsTotal = 100,090 Tokens
AssetsAvailable = 99,000 Tokens
SharesTotal = 100,000 Tokens

-- Lending Protocol --
DebtTotal = 1,090 Tokens
CoverRateMinimum = 0.1 (10%)
CoverRateLiquidation = 0.1 (10%)
CoverAvailable = 1,000 Tokens

-- Loan --
AssetsAvailable = 500 Tokens
PrincipleOutstanding = 1,000 Tokens
InterestOutstanding = 90 Tokens


# First-Loss Capital liquidation maths

DefaultAmount = PrincipleOutstanding + InterestOutstanding - AssetsAvailable
= 1,000 + 90 - 500
= 590

# The amount of the default that the first-loss capital scheme will cover
DefaultCovered = min((DebtTotal x CoverRateMinimum) x CoverRateLiquidation, DefaultAmount)
= min((1,090 * 0.1) * 0.1, 1,090) = min(10.9, 590)
= 10.9 Tokens

Loss = DefaultAmount - DefaultCovered
= 590 - 10.9
= 579.1 Tokens

FundsReturned = DefaultCovered + AssetsAvailable
= 10.9 + 500
= 510.9

# Note: Loss + FundsReturned MUST be equal to PrincipleOutstanding + InterestOutstanding

** State Changes **

-- Vault --
AssetsTotal = AssetsTotal - Loss
= 100,090 - 579.1
= 99,510.9 Tokens

AssetsAvailable = AssetsAvailable + FundsReturned
= 99,000 + 510.9
= 99,510.9 Tokens

SharesTotal = (UNCHANGED)

-- Lending Protocol --
DebtTotal = DebtTotal - PrincipleOutstanding + InterestOutstanding
= 1,090 - (1,000 + 90)
= 0 Tokens

CoverAvailable = CoverAvailable - DefaultCovered
= 1,000 - 10.9
= 989.1 Tokens
```

#### Impairment

If the loan broker discovers a borrower can't make an upcoming payment, impairment allows the loan broker to register a "paper loss" with the vault. The impairment mechanism moves the due date of the next payment to the time the loan is impaired, allowing the loan to default more quickly. However, if the borrower makes a payment before that date, the impairment status is automatically cleared.


### Compliance

#### Clawback

Issuers (trust line token or MPT, not XRP) can claw back funds from First-Loss Capital. To ensure there is always a minimum amount of capital available to protect depositors, issuers can't claw back the entire available amount. Instead, they can claw back up to a minimum amount of First-Loss Capital that the loan broker must maintain for the lending protocol; the minimum amount is calculated as `LoanBroker.DebtTotal * LoanBroker.CoverRateMinimum`.

#### Freeze

Freezing is a mechanism by which an asset issuer (trust line token or MPT, not XRP) prevents an account from sending their issued asset. _Deep freeze_ takes this a step further by preventing an account from sending _and_ receiving issued assets. Issuers can also enact a _global freeze_, which prevents everyone from sending or receiving their issued asset.

{% admonition type="info" name="Note" %}
In all freeze scenarios, assets can be sent back to the issuer.
{% /admonition %}

If a borrower has their account frozen or deep frozen, they can't make loan payments. This doesn't absolve a borrower of their repayment obligations, and they will eventually default on their loan.

Freezing a borrower's account won't affect a loan broker's functions, but it will prevent them from receiving any lending protocol fees. However, issuers can freeze a loan broker's _pseudo-account_ and prevent the loan broker from creating new loans; existing loans won't be affected. A deep freeze on a loan broker's _pseudo-account_ also prevents loans from being repaid.


### Interest Rates

There are three interest rates associated with a loan:

- **Interest Rate**: The regular interest rate based on the principal amount. It is the cost of borrowing funds.
- **Late Interest Rate**: A higher interest rate charged for a late payment.
- **Full Payment Rate**: An interest rate charged for repaying the total loan early.


### Fees

The lending protocol charges a number of fees that the loan broker can configure. The protocol won't charge these fees if the loan broker hasn't deposited enough first-loss capital.

- **Management Fee**: This is a percentage of interest charged by the loan broker. Vault depositors pay this fee.
- **Loan Origination Fee**: A fee paid to the loan broker, taken from the principal amount loaned out.
- **Loan Service Fee**: A fee charged on top of each loan payment.
- **Late Payment Fee**: A fee paid on top of a late payment.
- **Early Payment Fee**: A fee paid on top of an early payment.


## Loan Payment Processing

Loan payments are evaluated and processed around three criteria: amount, timing, and specified flags. The combination of these criteria determine how funds are applied to the loan's principal, interest, and associated fees.

Each payment consists of three components:

- **Principal**: The portion that reduces the outstanding loan principle.
- **Interest**: The portion that covers the cost of borrowing for the period.
- **Fees**: The portion that covers any applicable service fees, management fees, late payment fees, or other charges.

When the loan payment is submitted, the lending protocol then checks these parameters:

- **Timing**: Is the payment on time or late?
- **Amount**: Does the payment amount meet the minimum required amount, or exceed it?

Based on the timing and transaction flags, the lending protocol processes the payment as one of four types:

- **On-Time Payments**: If the payment is on-time, it's further classified into these payment scenarios:
- **Sequential Periodic Payments**: The payment is applied to as many complete payment cycles as possible; cycles are calculated as the amount due each payment period (including fees).
- **Overpayments**: After all possible cycles are fully paid, any remaining amount is treated as an overpayment and applied to the principal. This type of payment requires the `lsfLoanOverpayment` flag to be enabled on the `Loan` ledger entry, as well as the `tfLoanOverpayment` flag to be enabled on the `LoanPay` transaction. If these flags are missing, the excess amount is ignored.
- **Full Early Repayment**: The payment has the `tfLoanFullPayment` flag set, and the amount covers the remainder of the loan (including fees).
- **Late Payments**: The payment is late on a payment cycle. Late payments must be for an exact amount, calculated as:

`totalDue = periodicPayment + loanServiceFee + latePaymentFee + latePaymentInterest`

Overpayments aren't permitted on late payments; any excess amount is ignored.

{% admonition type="info" name="Note" %}
In scenarios where excess payment amounts are "ignored", the transaction succeeds, but the borrower is only charged on the expected amount.
{% /admonition %}
106 changes: 106 additions & 0 deletions docs/xls-66d-lending-protocol/index.page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import * as React from "react";
import {
LandingContainer,
LandingLayout,
FeatureHeader,
FeatureContent
} from "../../components/landing";
import { AmendmentTracker } from "../../components/AmendmentTracker";
import { Button } from "@redocly/theme";
import { Card } from "@redocly/theme/markdoc/components/Cards/Card";
import { Cards } from "@redocly/theme/markdoc/components/Cards/Cards";

export const frontmatter = {
seo: {
title: "XLS-66d Lending Protocol",
description: "An XRP Ledger DeFi primitive that enables loans from a Single Asset Vault."
},
};

export default function Page() {
const KEY_DATE_EVENTS = [
"XLS Spec Live",
"Available to Test on Devnet",
"Open for Voting on Mainnet",
"Vote Consensus"
];

const [keyDates, setKeyDates] = React.useState(
KEY_DATE_EVENTS.map(event => ({ date: "🔄 Loading...", event }))
);

const handleKeyDatesUpdate = React.useCallback((newKeyDates: any[]) => {
setKeyDates(newKeyDates);
}, []);

return (
<LandingLayout>
<LandingContainer>
<FeatureHeader
title="XLS-66d Lending Protocol"
subtitle="An XRP Ledger DeFi primitive that enables loans from a Single Asset Vault."
/>

<FeatureContent
description="The Lending Protocol is an XRP Ledger DeFi primitive that enables on-chain, fixed-term, uncollateralized loans using pooled funds from a Single Asset Vault. The implementation relies on off-chain underwriting and risk management to assess the creditworthiness of borrowers, but offers configurable, peer-to-peer loans without intermediaries like banks or financial institutions."
keyDates={keyDates}
/>

<AmendmentTracker
amendmentId=""
xlsSpecDate=""
onKeyDatesUpdate={handleKeyDatesUpdate}
/>

<Cards columns={2}>
<Card
title="XLS Spec"
to=""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also adding to to-do list before merge

>
<p>
Technical spec for the feature outlining requirements, design,
and implementation details.
</p>
<Button size="large" variant="primary">
Read the XLS Spec
</Button>
</Card>

<Card title="Documentation" to="./docs/xls-66d-lending-protocol/concepts/lending-protocol">
<p>
Explore key concepts, find detailed references, and follow
step-by-step tutorials.
</p>
<Button size="large" variant="primary">
Read the Docs
</Button>
</Card>
</Cards>
<Cards columns={2}>
<Card
title="Blog"
to=""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add this, likely the same as what we have for Single Asset Vault: https://dev.to/ripplexdev/xrp-ledger-lending-protocol-2pla

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add it to the to-do list before merging

>
<p>
An overview of the feature and why it matters to developers, explained in our blog post.
</p>
<Button size="large" variant="primary">
Read the Blog
</Button>
</Card>
<Card
title="Security Audit"
to=""
>
<p>
The security audit performed by third-party security experts, including a link to the full, detailed security audit report.
</p>
<Button size="large" variant="primary">
Read the Security Audit Report
</Button>
</Card>
</Cards>
</LandingContainer>
</LandingLayout>
);
}
Loading