Fix late fee accrual after principal is fully repaid#507
Fix late fee accrual after principal is fully repaid#507feromoneth wants to merge 3 commits intoLabsCrypt:mainfrom
Conversation
|
hey @feromoneth, the late fee accrual fix looks relevant but there are no CI checks running on the once CI is green I'll review the diff. |
|
No CI checks are running on this branch. Please push a commit to trigger the CI workflows — even a small formatting change will do. We need contracts and backend to be green before this can be reviewed for merge. |
ogazboiz
left a comment
There was a problem hiding this comment.
hey @feromoneth, the late fee accrual fix is a single-file change which is nice and focused. no CI checks ran though.
could you push an empty commit to trigger CI?
git commit --allow-empty -m "chore: trigger CI"
git pushonce builds are green we'll review and merge!
|
The codebase issues on main have been resolved and all CI checks are passing now. Please rebase your branch to pull in the latest changes before continuing. Thanks for your patience. |
ogazboiz
left a comment
There was a problem hiding this comment.
The fix itself is correct and minimal. Moving the early-return guard to check `remaining_principal <= 0` instead of `remaining_debt` properly stops late fee accrual once principal is fully repaid. Good catch.
Two things before this can merge:
-
CI needs to run. No checks have been reported on this branch. Please push an empty commit to trigger CI: `git commit --allow-empty -m "trigger CI" && git push`
-
Add a regression test. Set up a loan where `principal_paid == loan.amount` with non-zero `accrued_interest`, advance ledgers past the grace period, and assert that `accrue_late_fee` returns 0. This prevents the bug from coming back.
The code change is solid once CI confirms it passes and the test is added.
|
Friendly reminder to rebase your branch onto the latest main and address the review feedback when you get a chance. The codebase had some fixes recently so a rebase is needed before we can move forward. Let me know if you need help. |
|
heads up, a few important changes just landed on main that affect your PR:
please rebase on latest main: git fetch upstream
git rebase upstream/main
git push --force-with-lease |
7ba2a0d to
b56edf1
Compare
Summary
Closes #462.
Late fees continued to accrue after
principal_paid == loan.amount, allowing additional late fee growth even when the principal was fully repaid.2. Root Cause
In
accrue_late_fee(contracts/loan_manager/src/lib.rs), the stop condition checkedremaining_debt(principal + accrued interest) instead of checking remaining principal directly.As a result, if interest remained, late fee accrual continued.
3. Fix Implemented
remaining_principal <= 0before calculating any new late fee delta.4. Testing Performed
clippywith warnings denied