Skip to content
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 7 commits into from
Aug 2, 2021
Merged

Loan offer #194

merged 7 commits into from
Aug 2, 2021

Conversation

da-kami
Copy link
Member

@da-kami da-kami commented Jul 28, 2021

Fixes #187

We are reaching a mergeable state given what is descibed in the ticket.
Overall the lending feature is still a bit brittle. Id say we record tickets for specific "bugs" rather than keep extending this PR.

Comment on lines 263 to 267
/// Handle Alice's loan offer request
///
/// We return the possible loan terms that we offer to Alice
/// Alice can then request a loan that is within the parameters that were offered
pub async fn handle_loan_offer_request(&mut self) -> Result<LoanOffer> {
Copy link
Member

Choose a reason for hiding this comment

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

At some point we should remove the name "Alice" (and "Bob") from bobtimus and replace it with "borrower" (and "lender" respectively).

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, good to keep it in mind, I started doing it now (i.e. where I touched code that contains Alice/Bob I change it where needed) but I did not clean up all instances. Might be a bit tricky - in a protocol context we will want to leave it I suppose.

bobtimus/src/lib.rs Outdated Show resolved Hide resolved
pub max_principal: LiquidUsdt,

/// The minimum ltv that is acceptable in percent
pub min_ltv: Decimal, // TODO: is u64 appropriate here - how is ltv depicted internally?
Copy link
Member

Choose a reason for hiding this comment

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

I thought I point this out:

LTV => Loan To Value
Since we want to over-collateralize the loan the LTV ratio will be smaller than 0.

e.g.

  • current rate: 1 BTC = $100
  • principal amount = $100
  • collateral amount = 2 BTC
    --> LTV = 100 / 2*100 = 0.5

The higher this value is the higher the risk for the lender.

which means LTV value should be a floating point number and a max.

Note: In the loan contract the liquidation is decided according to the exchange rate (https://github.com/comit-network/baru/blob/a7743b538c91ff3f055c3a1f22a14502be7e275b/src/loan.rs#L68) (cc @luckysori ).
We will need to derive the value we need to put into liquidation function from the agreed max LTV ratio.

@da-kami da-kami force-pushed the loan-offer branch 2 times, most recently from c5a3e77 to 892322e Compare July 29, 2021 04:48
@da-kami da-kami changed the base branch from master to bobtimus-is-dead-long-live-bobtimus July 29, 2021 04:49
@da-kami da-kami force-pushed the loan-offer branch 3 times, most recently from 8e4fb03 to df76ae4 Compare July 30, 2021 04:33
@da-kami da-kami marked this pull request as ready for review July 30, 2021 04:34
@da-kami
Copy link
Member Author

da-kami commented Jul 30, 2021

Should have run the tests first... those still need some fixing / extending.

@bonomat bonomat force-pushed the bobtimus-is-dead-long-live-bobtimus branch from 45ea181 to 8a520b6 Compare July 30, 2021 05:25
@da-kami da-kami requested a review from bonomat July 30, 2021 06:11
@da-kami da-kami changed the base branch from bobtimus-is-dead-long-live-bobtimus to e2e-tests July 30, 2021 07:19
Copy link
Member

@bonomat bonomat left a comment

Choose a reason for hiding this comment

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

Cool, definitely well seen changes :)

/// The maximum LTV that defines at what point the lender liquidates
///
/// LTV ... loan to value
/// LTV = principal_amount/loan_value
Copy link
Member

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.

) -> Result<JsValue, JsValue> {
let collateral = map_err_from_anyhow!(parse_to_bitcoin_amount(collateral))?;
// TODO: Change the UI to handle SATs not BTC
Copy link
Member

Choose a reason for hiding this comment

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

I agree with this. Shall we record a ticket for this?

Copy link
Member Author

Choose a reason for hiding this comment

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

@@ -225,10 +225,22 @@ pub async fn make_sell_create_swap_payload(
pub async fn make_loan_request(
wallet_name: String,
collateral: String,
fee_rate: String,
timeout: String,
Copy link
Member

Choose a reason for hiding this comment

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

What do you think of changing the API in a way that we always deal with days until we get back the loan response. Thatway Bobtimus has to the calculation to actual blockheight and we only need to confirm it again in the UI when we sign it?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes! I should have done that in the first place. The absolute timelock being decided at the very start is not optimal, because the relative time may already decline while the user is still deciding on the loan. This calculating the timelock upon taking that is not an issue anymore :)

Copy link
Member Author

Choose a reason for hiding this comment

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

will do this in a follow-up that includes baru upgrades (because to do this properly some minor changes in baru will be needed that I'll just do on the way)

extension/src/components/OpenLoans.tsx Outdated Show resolved Hide resolved
Copy link
Member

@bonomat bonomat left a comment

Choose a reason for hiding this comment

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

Only change request from me is on renaming the error to debug .

Base automatically changed from e2e-tests to bobtimus-is-dead-long-live-bobtimus August 2, 2021 01:45
Base automatically changed from bobtimus-is-dead-long-live-bobtimus to master August 2, 2021 01:59
da-kami added 4 commits August 2, 2021 13:18
This requires changes and is not just a comment that explains the piece of code.
Get rid of this warning

```
WARNING: .dprintrc.json will be deprecated soon. Please rename it to dprint.json
```
The UI now properly display the values given by Bobtimus.
When taking a loan the UI values are not sent yet though, it still uses hardcoded values from within the extension wallet.
@da-kami da-kami dismissed bonomat’s stale review August 2, 2021 03:24

all done :)

@da-kami da-kami merged commit edac99e into master Aug 2, 2021
@da-kami da-kami deleted the loan-offer branch August 2, 2021 03:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Waves] Lending feature in UI
2 participants