Skip to content

Conversation

@Tapanito
Copy link
Collaborator

@Tapanito Tapanito commented Dec 5, 2025

Fixes two bugs in overpayment:

  • Fixes overpayment calculation, adds tests and refactors tryOverpayment to be without side effects.
  • Adds missing management fee to overpayments.

@Tapanito Tapanito requested a review from ximinez December 5, 2025 12:34
@Tapanito Tapanito requested a review from a team as a code owner December 5, 2025 12:34
@Tapanito Tapanito force-pushed the tapanito/lending-overpayment-value-change branch from cb69f06 to cf33c9d Compare December 8, 2025 10:30
@Tapanito Tapanito changed the title draft: Lending protocol overpayment Lending Protocol: Fix Overpayment ValueChange calculation Dec 8, 2025
@codecov
Copy link

codecov bot commented Dec 8, 2025

Codecov Report

❌ Patch coverage is 93.84615% with 4 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (ximinez/lending-XLS-66-ongoing@40c29bb). Learn more about missing BASE report.

Files with missing lines Patch % Lines
src/xrpld/app/misc/detail/LendingHelpers.cpp 96.6% 2 Missing ⚠️
src/xrpld/app/tx/detail/LoanSet.cpp 71.4% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@                       Coverage Diff                        @@
##             ximinez/lending-XLS-66-ongoing   #6114   +/-   ##
================================================================
  Coverage                                  ?   79.1%           
================================================================
  Files                                     ?     839           
  Lines                                     ?   71385           
  Branches                                  ?    8320           
================================================================
  Hits                                      ?   56476           
  Misses                                    ?   14909           
  Partials                                  ?       0           
Files with missing lines Coverage Δ
src/xrpld/app/misc/LendingHelpers.h 95.0% <ø> (ø)
src/xrpld/app/misc/detail/LendingHelpers.cpp 90.1% <96.6%> (ø)
src/xrpld/app/tx/detail/LoanSet.cpp 91.4% <71.4%> (ø)

Impacted file tree graph

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Tapanito Tapanito requested a review from gregtatcam December 9, 2025 15:17
hypotheticalValueOutstanding - deltas.managementFee;
// The value change is derived from the reduction in interest due to
// the lower principal.
auto const valueChange = -deltas.interest;
Copy link
Collaborator

@gregtatcam gregtatcam Dec 9, 2025

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?

Copy link
Collaborator Author

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).

Copy link
Collaborator

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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, of course!

Copy link
Collaborator

Choose a reason for hiding this comment

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

Please update!

Copy link
Collaborator

@gregtatcam gregtatcam left a comment

Choose a reason for hiding this comment

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

LGTM

Comment on lines 544 to 548
// 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)
Copy link
Collaborator

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?

Comment on lines 551 to 553
// Fee paid includes both the reduction in tracked management fees
// and
// any untracked fees on the overpayment itself
Copy link
Collaborator

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?

Comment on lines 649 to 650
TenthBips16 managementFeeRate{20'000}; // 10%
TenthBips32 loanInterestRate{10'000}; // 20%
Copy link
Collaborator

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.

Comment on lines 666 to 669
std::cout << loanProperites.periodicPayment << std::endl;
std::cout << loanProperites.loanState.valueOutstanding << std::endl;
std::cout << loanProperites.loanState.interestOutstanding()
<< std::endl;
Copy link
Collaborator

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.

Copy link
Collaborator Author

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!

BEAST_EXPECT(ret);

auto const& [actualPaymentParts, newLoanProperties] = *ret;
auto const newState = newLoanProperties.loanState;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
auto const newState = newLoanProperties.loanState;
auto const& newState = newLoanProperties.loanState;

Comment on lines -4469 to -4476
void
testBasicMath()
{
// Test the functions defined in LendingHelpers.h
testcase("Basic Math");

pass();
}
Copy link
Collaborator

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.

@Tapanito Tapanito requested a review from ximinez December 15, 2025 12:32
@Tapanito Tapanito added the Ready to merge *PR author* thinks it's ready to merge. Has passed code review. Perf sign-off may still be required. label Dec 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ready to merge *PR author* thinks it's ready to merge. Has passed code review. Perf sign-off may still be required.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants