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

Fix: linear accrual not overpassing maturity #1842

Merged
merged 3 commits into from
May 23, 2024

Conversation

lemunozm
Copy link
Contributor

Description

slack thread

We need to avoid computing points in the line of linear accrual if the time overpass the maturity time, instead, we want to clamp the value to notional (which is the same when the time is just maturity)

@lemunozm lemunozm added I2-bug The code fails to follow expected behaviour. P7-asap Issue should be addressed in the next days. labels May 22, 2024
@lemunozm lemunozm self-assigned this May 22, 2024
Copy link

codecov bot commented May 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 46.78%. Comparing base (e2dd3ca) to head (859dbfb).

Additional details and impacted files
@@                  Coverage Diff                   @@
##           fix/linear-pricing    #1842      +/-   ##
======================================================
- Coverage               48.48%   46.78%   -1.71%     
======================================================
  Files                     170      170              
  Lines                   13398    13385      -13     
======================================================
- Hits                     6496     6262     -234     
- Misses                   6902     7123     +221     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -359,7 +359,8 @@ impl<T: Config> ActiveLoan<T> {
inner.adjust(Adjustment::Increase(amount.balance()?))?
}
ActivePricing::External(inner) => {
inner.adjust(Adjustment::Increase(amount.external()?), Zero::zero())?
let when = T::Time::now();
Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess maturity not being passed already is checked by the ensure_can_borrw()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But not in repay()

Comment on lines 849 to 850
// We must never overpass madurity date
assert_eq!(active_loan.maturity_date(), settlement_price_updated);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we also check, that the linear pricing actually clamps with giving the notional baack?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@lemunozm
Copy link
Contributor Author

BTW, I did the fix quite bad 😆. I'm redoing the fix implementation

@lemunozm lemunozm force-pushed the fix/linear-pricing-maturity branch from d14ca3e to 78b83b8 Compare May 22, 2024 10:14
@lemunozm lemunozm force-pushed the fix/linear-pricing-maturity branch from 78b83b8 to 01d0200 Compare May 22, 2024 10:14
Comment on lines +165 to +167
(min(price_last_updated, maturity), price),
(maturity, self.info.notional),
T::Time::now(),
min(T::Time::now(), maturity),
Copy link
Contributor Author

@lemunozm lemunozm May 22, 2024

Choose a reason for hiding this comment

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

I've re-done the implementation. We do not need to modify the settlement_price_updated. Actually, we want to know when the last repayment was done. Instead, we can trick just the call to y_coord_in_rect() to never exceed maturity, which is less invasive

Copy link
Contributor

@wischli wischli left a comment

Choose a reason for hiding this comment

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

I really like the low invasion! AFAICT, this is sound!

@lemunozm lemunozm merged commit 9265bbb into fix/linear-pricing May 23, 2024
12 checks passed
@lemunozm
Copy link
Contributor Author

Your migration should work without any change after rebasing @wischli 🤞🏻

NOTIONAL
);
});
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would still like to test the case where

last_updated_price and T::Time::now() are both equal to maturity. I think that is an edge case worth testing

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's tested currently

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, it is repaid with one DAY of overdue, and the expected value is notional

@lemunozm lemunozm deleted the fix/linear-pricing-maturity branch May 23, 2024 08:12
@wischli wischli added this to the Centrifuge 1029 milestone Jun 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I2-bug The code fails to follow expected behaviour. P7-asap Issue should be addressed in the next days.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants