-
Notifications
You must be signed in to change notification settings - Fork 41
Lending Protocol #156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
oeggert
wants to merge
29
commits into
main
Choose a base branch
from
lending-protocol
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Lending Protocol #156
Changes from 11 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
3ff8d35
rebase to main
oeggert 597eb9b
add diagram and reviewer suggestions for concept topic
oeggert 233895d
update reference docs for loanbroker transactions.
oeggert 40039e9
update to latest spec
oeggert 401be5f
fix sidebar
oeggert 847b991
Update docs/xls-66d-lending-protocol/concepts/lending-protocol.md
oeggert 31bf7ed
remove loandraw transaction
oeggert 813ee97
fix references to assetsavailable and startdate
oeggert a24c79a
update loanbrokerset with modifiable fields
oeggert adc90e9
add totalvalueoutstanding and princpalrequested fields to loan ledger…
oeggert 3e34cca
Update sidebars.yaml
amarantha-k c11634b
Fix link to docs
amarantha-k b446e7e
updated loanpay with loanoverpayment flag
oeggert b563b4e
add loan payment psuedo code
oeggert 1badaa0
highlight configurability in concept intro
oeggert e4ef7b5
add use case doc
oeggert 2f2c335
update based on recent spec
oeggert 05fd8de
update to latest spec
oeggert 14f5e97
add info for signature_target field
oeggert 8f508fe
add reviewer suggestions
oeggert 7e9f003
add reviewer suggestions
oeggert 22e93a4
add @maria-robobug suggestions
oeggert 4190eed
clean up up formatting on late payment formula
oeggert f6f11d3
Update docs/xls-66d-lending-protocol/reference/ledger-data/loan.md
oeggert 36e143d
Update docs/xls-66d-lending-protocol/reference/ledger-data/loanbroker.md
oeggert fa78247
Update docs/xls-66d-lending-protocol/use-cases/institutional-credit-f…
oeggert 9264e88
Update docs/xls-66d-lending-protocol/reference/transactions/loanbroke…
oeggert 95c9d70
Update docs/xls-66d-lending-protocol/reference/transactions/loanbroke…
oeggert cfbdc67
update internal data type name
oeggert File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
164 changes: 164 additions & 0 deletions
164
docs/xls-66d-lending-protocol/concepts/lending-protocol.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,164 @@ | ||
| --- | ||
| 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 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.svg" /%}](./lending-protocol.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 and are liquidated in the event of loan defaults. The liquidated capital is placed into the vault to cover some of the 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`. | ||
| - `CoverRateLiquiditation`: The maximum percentage of the minimum required cover _(DebtTotal x CoverRateMinimum)_ that will be liquidated to cover a loan default. | ||
|
|
||
| Whenever the available cover falls below the minimum required: | ||
|
|
||
| - The lender can't issue new loans. | ||
| - The lender can't receive lender fees. All fees are added to the First-Loss Capital to cover the deficit. | ||
|
|
||
| Below is an example of how first-loss capital is liquidated 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 (IOU 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`. | ||
oeggert marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| #### Freeze | ||
|
|
||
| Freezing is a mechanism by which an asset issuer (IOU 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. | ||
oeggert marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| {% 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. | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.