💬 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
- Add
DataKey::TotalOutstanding(token) to instance storage
- Increment it when a loan is approved, decrement on repayment or default
- In
approve_loan(), validate available - outstanding >= loan.amount
- Add tests covering concurrent loan approvals that would exceed pool capacity
Location
contracts/loan_manager/src/lib.rs inside approve_loan()
Problem
approve_loan()incontracts/loan_manager/src/lib.rschecks 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 checkpool_balance - total_outstanding >= loan.amountbefore approving.Suggested Fix
DataKey::TotalOutstanding(token)to instance storageapprove_loan(), validateavailable - outstanding >= loan.amountLocation
contracts/loan_manager/src/lib.rsinsideapprove_loan()