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: Add unchecked amount support #1368
Conversation
) -> DispatchResult { | ||
let who = ensure_signed(origin)?; | ||
|
||
let (amount, _count) = Self::update_active_loan(pool_id, loan_id, |loan| { | ||
Self::ensure_loan_borrower(&who, loan.borrower())?; | ||
loan.repay(amount) | ||
loan.repay(amount, unchecked_amount) | ||
})?; |
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.
We should add unchecked_amount: T::Balance
as the last parameter to the Repaid
event.
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.
Makes sense!
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.
Actually, I see what's happening now, the amount
logged in the event will include the unchecked amount. I fear an indexing layer needs to be able to know what the checked vs unchecked amount was.
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.
Maybe Loan::repay
can return separate amount and unchecked amounts, rather than adding them together?
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.
Yes, In fact, I think Loan::repay
shouldn't do anything with unchecked
except stores it.
a8cc59a
to
838813a
Compare
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.
LGTM!
COLLATERAL_VALUE, | ||
),); | ||
|
||
// Nothing repaid with unchecked amount, |
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.
Good straightforward test to check this behaviour 👍
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.
LGTM!
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 not fully onboard with the context but the code and changes LGTM based on the PR description.
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 think it would be good to update the comment above the repay
extrinsic. Something like from
/// The origin must be the borrower of the loan.
/// If the repaying amount is more than current debt, only current debt
/// is transferred. The borrow action should fulfill the borrow
/// restrictions configured at [`types::LoanRestrictions`]. The `amount`
/// will be transferred from borrower to pool reserve. The portfolio
/// valuation of the pool is updated to reflect the new present value of
/// the loan.
to
/// The origin must be the borrower of the loan.
/// The repay action should fulfill the repay restrictions
/// configured at [`types::RepayRestrictions`].
/// If the repaying `amount` is more than current debt, only current debt
/// is transferred. This does not apply to `unchecked_amount`, which
/// can be used to repay more than the outstanding debt.
/// The portfolio valuation of the pool is updated to reflect the new
/// present value of the loan.
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.
Missed the integration tests beforehand 😅 Thanks for the fix and docs improvement!
Description
unchecked_amount
inrepay()
extrinsictotal_repaid_unchecked
toActiveLoan
struct.Fixes #1352