Skip to content

fix(contracts): approve_loan() does not account for already-approved outstanding loans in liquidity check #455

@Akpolo

Description

@Akpolo

💬 Want to contribute? Join us on Telegram: https://t.me/+DOylgFv1jyJlNzM0

Problem

approve_loan() in contracts/loan_manager/src/lib.rs checks if the pool balance exceeds the requested loan amount, but does not account for already-approved loans that have not yet been repaid. If the pool has 10,000 tokens and two pending loans of 6,000 each are approved in sequence, both pass the liquidity check but only the first can actually be disbursed. The second will panic at the token transfer step.

Expected Behavior

The contract should track total committed (approved but outstanding) liquidity separately from available liquidity. approve_loan() should check pool_balance - total_outstanding >= loan.amount before approving.

Suggested Fix

  1. Add DataKey::TotalOutstanding(token) to instance storage
  2. Increment it when a loan is approved, decrement on repayment or default
  3. In approve_loan(), validate available - outstanding >= loan.amount
  4. Add tests covering concurrent loan approvals that would exceed pool capacity

Location

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

Metadata

Metadata

Assignees

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