-
Notifications
You must be signed in to change notification settings - Fork 6
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
Loan offer #194
Merged
Merged
Loan offer #194
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ffbbb8f
Remove empty module
da-kami c7e248a
Change comment to TODO
da-kami c28c07e
Adhere to dprint changes
da-kami 110a872
UI plugged into loan offer from Bobtimus
da-kami f94a30f
Use loan offer for loan request
da-kami 90130e4
Fix error messages
da-kami f366dd9
Loan due date using current block height
da-kami 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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,52 @@ | ||
use crate::{LiquidUsdt, Rate}; | ||
use elements::bitcoin::Amount; | ||
use rust_decimal::Decimal; | ||
|
||
#[derive(Debug, Clone, serde::Serialize)] | ||
pub struct LoanOffer { | ||
// TODO: Potentially add an id if we want to track offers - for now we just check if an incoming request is acceptable | ||
pub rate: Rate, | ||
|
||
#[serde(with = "::elements::bitcoin::util::amount::serde::as_sat")] | ||
pub fee_sats_per_vbyte: Amount, | ||
|
||
#[serde(serialize_with = "LiquidUsdt::serialize_to_nominal")] | ||
pub min_principal: LiquidUsdt, | ||
#[serde(serialize_with = "LiquidUsdt::serialize_to_nominal")] | ||
pub max_principal: LiquidUsdt, | ||
|
||
/// The maximum LTV that defines at what point the lender liquidates | ||
/// | ||
/// LTV ... loan to value | ||
/// LTV = principal_amount/loan_value | ||
/// where: | ||
/// principal_amount: the amount lent out | ||
/// loan_value: the amount of collateral | ||
/// | ||
/// Simple Example (interest / fees not taken into account): | ||
/// | ||
/// The borrower takes out a loan at: | ||
/// max_ltv = 0.7 (70%) | ||
/// rate: 1 BTC = $100 | ||
/// principal_amount: $100 | ||
/// collateral: 2 BTC = $200 (over-collateralized by 200%) | ||
/// current LTV = 100 / 200 = 0.5 (50%) | ||
/// Since the actual LTV 0.5 < 0.7, so all is good. | ||
/// | ||
/// Let's say Bitcoin value falls to $70: | ||
/// LTV = 100 / 2 * 70 => 100 / 140 = 0.71 | ||
/// The actual LTV 0.71 > 0.7 so the lender liquidates. | ||
/// | ||
/// The max_ltv protects the lender from Bitcoin falling too much. | ||
pub max_ltv: Decimal, | ||
|
||
pub interest: Vec<Interest>, | ||
} | ||
|
||
#[derive(Debug, Clone, serde::Serialize)] | ||
pub struct Interest { | ||
/// Timelock in blocks | ||
pub timelock: u32, | ||
/// Interest rate in percent | ||
pub interest_rate: Decimal, | ||
} |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains 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
This file contains 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
This file contains 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
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
100% correct would be
principal_amount+interest_rate/loan_value
but let's ignore that for now.