💬 Want to contribute? Join us on Telegram: https://t.me/+DOylgFv1jyJlNzM0
Problem
The accrue_interest() function in contracts/loan_manager/src/lib.rs uses integer division which silently drops fractional interest on every ledger tick. For small loans (e.g. 100 tokens at 12% over 17280 ledgers), the per-ledger interest is less than 1 unit, so every accrual produces 0 and the borrower pays no interest at all. The interest_residual field was added to address this but is not used consistently across all code paths.
Expected Behavior
Fractional interest should accumulate in a residual field and be applied when it crosses a whole unit. All code paths that trigger interest accrual (repay, approve, refinance) should flush the residual.
Suggested Fix
- Confirm
interest_residual is flushed before all repayment and refinance paths
- Add a test with a loan of 50 tokens that accrues over 100 ledgers and assert interest > 0
- Add a test that verifies
interest_residual resets to 0 after full repayment
Location
contracts/loan_manager/src/lib.rs inside accrue_interest()
Problem
The
accrue_interest()function incontracts/loan_manager/src/lib.rsuses integer division which silently drops fractional interest on every ledger tick. For small loans (e.g. 100 tokens at 12% over 17280 ledgers), the per-ledger interest is less than 1 unit, so every accrual produces 0 and the borrower pays no interest at all. Theinterest_residualfield was added to address this but is not used consistently across all code paths.Expected Behavior
Fractional interest should accumulate in a residual field and be applied when it crosses a whole unit. All code paths that trigger interest accrual (repay, approve, refinance) should flush the residual.
Suggested Fix
interest_residualis flushed before all repayment and refinance pathsinterest_residualresets to 0 after full repaymentLocation
contracts/loan_manager/src/lib.rsinsideaccrue_interest()