Skip to content

Fix late fee accrual after principal is fully repaid#507

Open
feromoneth wants to merge 3 commits intoLabsCrypt:mainfrom
feromoneth:fix/late-fee-accrual-after-principal-paid
Open

Fix late fee accrual after principal is fully repaid#507
feromoneth wants to merge 3 commits intoLabsCrypt:mainfrom
feromoneth:fix/late-fee-accrual-after-principal-paid

Conversation

@feromoneth
Copy link
Copy Markdown

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 checked remaining_debt (principal + accrued interest) instead of checking remaining principal directly.

As a result, if interest remained, late fee accrual continued.

3. Fix Implemented

  • Updated the accrual guard to stop when remaining_principal <= 0 before calculating any new late fee delta.
  • Existing late fee cap logic remains unchanged.

4. Testing Performed

  • Ran contract formatting check
  • Ran clippy with warnings denied
  • Ran contract test suite

@ogazboiz
Copy link
Copy Markdown
Contributor

hey @feromoneth, the late fee accrual fix looks relevant but there are no CI checks running on the fix/late-fee-accrual-after-principal-paid branch. it looks like the CI workflow might not have triggered. try pushing a small change to re-trigger it, or close and reopen the PR.

once CI is green I'll review the diff.

@ogazboiz
Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
Contributor

@ogazboiz ogazboiz left a comment

Choose a reason for hiding this comment

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

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 push

once builds are green we'll review and merge!

@ogazboiz
Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
Contributor

@ogazboiz ogazboiz left a comment

Choose a reason for hiding this comment

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

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:

  1. 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`

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

@ogazboiz
Copy link
Copy Markdown
Contributor

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.

@ogazboiz
Copy link
Copy Markdown
Contributor

heads up, a few important changes just landed on main that affect your PR:

  1. axios pinned to 1.13.5 - there's an active supply chain attack on axios 1.14.1 (pulls in confirmed malware). we added overrides in all package.json files to block it.

  2. CI now runs a supply chain audit before backend/frontend jobs. if your lockfile has a compromised package, CI will fail with a clear error.

  3. backend test fixes - loanEndpoints tests now use valid Stellar addresses and base64 strings. if your PR was failing backend CI but you didn't touch backend code, this should fix it after rebase.

please rebase on latest main:

git fetch upstream
git rebase upstream/main
git push --force-with-lease

@feromoneth feromoneth force-pushed the fix/late-fee-accrual-after-principal-paid branch from 7ba2a0d to b56edf1 Compare April 2, 2026 16:37
@feromoneth feromoneth requested a review from ogazboiz April 2, 2026 16:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(contracts): late fee accrual continues after principal is fully repaid with no cap

2 participants