-
Notifications
You must be signed in to change notification settings - Fork 91
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
Loans: borrow & repay method using pricing-based principal #1455
Conversation
@mustermeiszer Because we are in a hurry, the main implementation can already be reviewed (it's finished) while I adapt/add tests. 🙌🏻 Currently |
Now it's ready for a final review 👐🏻 |
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.
I am approving as I spot nothing bad. Just would want to get feedback from Dennis regarding naming and am curious for the relaxation of the ensure!
-clauses.
#[scale_info(skip_type_params(T))] | ||
pub struct ExternalAmount<T: Config> { | ||
pub quantity: T::Rate, | ||
pub settlement_price: T::Balance, |
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.
Nit pick. Not sure if settlement_price
is the right tearm for when repaying? cc @denniswell
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.
As a note: ExternalAmount
is used for both: borrow & repay. So if changed there, it's changed for both.
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.
From my understanding of what this means, I think the name fits with its purpose.
@@ -46,7 +73,7 @@ impl<T: Config> ExternalPricing<T> { | |||
pub fn validate(&self) -> DispatchResult { | |||
if let MaxBorrowAmount::Quantity(quantity) = self.max_borrow_amount { | |||
ensure!( | |||
quantity.frac().is_zero() && quantity > T::Rate::zero(), | |||
quantity.frac().is_zero() && quantity >= T::Rate::zero(), |
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.
WHy the change here?
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.
You can create a loan that can not be borrowed only to repay later unchecked amounts.
ensure!( | ||
quantity.frac().is_zero(), | ||
Error::<T>::AmountNotMultipleOfPrice | ||
quantity.frac().is_zero() && quantity >= T::Rate::zero(), |
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.
Again, why the change to allow zero
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.
It's totally fine to repay with 0 of quantity if you want, for example, to pay only interest.
Code change of course looks good and clean! :-) |
Merged, if finally disagree with something. I'll add a PR with that tech debt |
Description
Jeroen's Slack introduction to this feature is here
Basically, we want to write the principal in different ways depending on the pricing method. As a schema, instead of always given a
Balance
as principal inborrow()
andrepay()
methods, we want:The core idea is that for external pricing, the amount that is transferred to the pool is
quantity * settlement_price
, and theoutstanding_quantity
is reduced byquantity
.So, with this schema:
quantity * settlement_price
quantity * notional
quantity * current_price
Changes