Skip to content

[backend] Fix Loan Repayment Rounding: Amounts Always Rounded Down #412

Description

@ExcelDsigN-tech

[backend] Fix Loan Repayment Rounding: Amounts Always Rounded Down

Description: Loan repayment calculations in backend/src/services/loanController.ts use Math.floor() causing systematic underpayment. Borrowers pay less than owed; lenders lose interest over time.

Impact: Financial discrepancy accumulates across all loans; regulatory compliance issue; trust erosion.

Suggested Fix:

  1. Replace Math.floor() with banker's rounding (Math.round()) or configurable rounding mode
  2. Add rounding policy constant in backend/src/config/money.ts
  3. Write property-based tests for rounding edge cases
  4. Create migration to recalculate outstanding balances
  5. Add audit log for rounding adjustments

Points: 200
Type: bug

Definition of Done

  • Bug reproduced and root cause identified
  • Fix implemented with configurable rounding policy
  • Property-based tests cover edge cases (0.5, negative, large values)
  • Migration script recalculates outstanding balances
  • Audit logging for rounding adjustments
  • No regression introduced
  • All necessary CI checks passed

📋 Before working on this issue, please read our Contributing Guidelines — it covers branching, commits, PR standards, testing, and style guides.

Join our Telegram community to connect with other contributors, ask questions, and stay updated:

💬 Telegram: https://t.me/+eRqhka27TVo0NzM8

All official decisions, reviews, and coordination happen right here on GitHub. The Telegram group is a space for informal discussion and peer support.

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave program

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions