Skip to content

fix(contracts): integer division in accrue_interest() silently drops fractional interest on small loans #456

@Akpolo

Description

@Akpolo

💬 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

  1. Confirm interest_residual is flushed before all repayment and refinance paths
  2. Add a test with a loan of 50 tokens that accrues over 100 ledgers and assert interest > 0
  3. Add a test that verifies interest_residual resets to 0 after full repayment

Location

contracts/loan_manager/src/lib.rs inside accrue_interest()

Metadata

Metadata

Assignees

No one assigned

    Labels

    Stellar WaveIssues in the Stellar wave program

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions