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

Feat: decrease debt #1857

Merged
merged 2 commits into from
Jun 5, 2024
Merged

Feat: decrease debt #1857

merged 2 commits into from
Jun 5, 2024

Conversation

mustermeiszer
Copy link
Collaborator

Description

Allows issuers to decrease the debt of any loan without actually repaying to the pool. Mostly useful for ensuring offchain cash is reflected accurately. This is basically an expense in most cases, should be covered by fees, but is a good increase of flexibility.

NOTE:

  • The deployed capital ratio of the tranches will decrease during the next epoch close but until then the tranches expect to generate the same revenue as of before - i.e. with a higher deployed capital ratio

Changes and Descriptions

  • adds extrinsic fn decrease_debt(..) - same as fn repay(..) but without moving tokens to the pool

Checklist:

  • I have added Rust doc comments to structs, enums, traits and functions
  • I have made corresponding changes to the documentation
  • I have performed a self-review of my code
  • I have added tests that prove my fix is effective or that my feature works

@mustermeiszer mustermeiszer requested a review from hieronx June 4, 2024 11:08
@mustermeiszer mustermeiszer added the D0-ready Pull request can be merged without special precaution and notification. label Jun 4, 2024
Copy link

codecov bot commented Jun 4, 2024

Codecov Report

Attention: Patch coverage is 85.71429% with 1 line in your changes missing coverage. Please review.

Project coverage is 46.65%. Comparing base (4b9e47e) to head (4395ff8).

Files Patch % Lines
pallets/loans/src/lib.rs 85.71% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1857      +/-   ##
==========================================
+ Coverage   46.52%   46.65%   +0.12%     
==========================================
  Files         167      167              
  Lines       13105    13112       +7     
==========================================
+ Hits         6097     6117      +20     
+ Misses       7008     6995      -13     

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

@mustermeiszer
Copy link
Collaborator Author

Subquery ticket: centrifuge/api#187

@mustermeiszer mustermeiszer requested a review from lemunozm June 4, 2024 12:43
/// of the pool is updated to reflect the new present value of the loan.
#[pallet::weight(T::WeightInfo::increase_debt(T::MaxActiveLoansPerPool::get()))]
#[pallet::call_index(14)]
pub fn decrease_debt(
Copy link
Contributor

@wischli wischli Jun 4, 2024

Choose a reason for hiding this comment

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

CR: Add unit test(s) for this. We must not merge PRs which add/alter code without adding/updating tests.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not adding new logic IMO, just sparing the T::Pool::repay(..) which will be mocked. So pub fn repay(..) should already cover everything.

If you disagree, can still add a test.

Copy link
Contributor

@lemunozm lemunozm Jun 5, 2024

Choose a reason for hiding this comment

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

There is a super simple fn increase_debt_does_not_withdraw() test for the increase_debt() case, maybe we can create a similar one in tests/repay_loan.rs checking that nothing goes to the pool. Of course, paranoid mode-on just ensuring future refactors does not break the invariant here

Copy link
Contributor

@lemunozm lemunozm left a comment

Choose a reason for hiding this comment

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

Apart from my suggestion above, LGTM!


assert_ok!(Loans::borrow(
assert_ok!(Loans::increase_debt(
Copy link
Contributor

@lemunozm lemunozm Jun 5, 2024

Choose a reason for hiding this comment

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

Yes, amazing test haha. I had this modified in the cashflows. This is an example of how to not test correctly 😆

Copy link
Contributor

@lemunozm lemunozm left a comment

Choose a reason for hiding this comment

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

Thanks for tackling the suggestions!

@mustermeiszer mustermeiszer merged commit 6e50915 into main Jun 5, 2024
12 checks passed
@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
D0-ready Pull request can be merged without special precaution and notification.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants