-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Lending Protocol: Fix Overpayment ValueChange calculation #6114
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
base: ximinez/lending-XLS-66-ongoing
Are you sure you want to change the base?
Lending Protocol: Fix Overpayment ValueChange calculation #6114
Conversation
cb69f06 to
cf33c9d
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## ximinez/lending-XLS-66-ongoing #6114 +/- ##
================================================================
Coverage ? 79.1%
================================================================
Files ? 839
Lines ? 71385
Branches ? 8320
================================================================
Hits ? 56476
Misses ? 14909
Partials ? 0
🚀 New features to boost your workflow:
|
| hypotheticalValueOutstanding - deltas.managementFee; | ||
| // The value change is derived from the reduction in interest due to | ||
| // the lower principal. | ||
| auto const valueChange = -deltas.interest; |
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.
Has the implementation deviated from the specs? Even the original implementation looks different. Should the specs be updated?
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.
The rationale behind this change is as follows:
An overpayment decreases the principal outstanding value, which in turn reduces the future interest of the loan. Thus the loan value decreases by the difference between the current interest due, and the new interest due (excluding management fee).
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.
Sure, but shouldn't the specs be updated?
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, of course!
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.
Please update!
gregtatcam
left a comment
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
| // Value change includes both the reduction from paying down | ||
| // principal | ||
| // (negative) and any untracked interest penalties (positive, e.g., | ||
| // if | ||
| // the overpayment itself incurs a fee) |
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.
Could you reformat this comment so it doesn't look so choppy?
| // Fee paid includes both the reduction in tracked management fees | ||
| // and | ||
| // any untracked fees on the overpayment itself |
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.
Could you reformat this comment so it doesn't look so choppy?
src/test/app/LendingHelpers_test.cpp
Outdated
| TenthBips16 managementFeeRate{20'000}; // 10% | ||
| TenthBips32 loanInterestRate{10'000}; // 20% |
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.
The comments on these values are switched.
src/test/app/LendingHelpers_test.cpp
Outdated
| std::cout << loanProperites.periodicPayment << std::endl; | ||
| std::cout << loanProperites.loanState.valueOutstanding << std::endl; | ||
| std::cout << loanProperites.loanState.interestOutstanding() | ||
| << std::endl; |
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.
Please change std::cout to log so the messages can be suppressed at runtime if the caller doesn't want to see them.
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.
Oooops. this wasn't suppose to be there. Removed!
src/test/app/LendingHelpers_test.cpp
Outdated
| BEAST_EXPECT(ret); | ||
|
|
||
| auto const& [actualPaymentParts, newLoanProperties] = *ret; | ||
| auto const newState = newLoanProperties.loanState; |
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.
| auto const newState = newLoanProperties.loanState; | |
| auto const& newState = newLoanProperties.loanState; |
| void | ||
| testBasicMath() | ||
| { | ||
| // Test the functions defined in LendingHelpers.h | ||
| testcase("Basic Math"); | ||
|
|
||
| pass(); | ||
| } |
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.
Woops. That one slipped through the cracks. LOL.
…verpayment-value-change
…verpayment-value-change
…verpayment-value-change
Fixes two bugs in overpayment: