Bug
`contracts/invoice/src/lib.rs` or `contracts/pool/src/lib.rs` — if invoices support partial funding (multiple lenders funding portions of an invoice), the `funded_amount` field in the `Invoice` struct may not be updated correctly after each partial funding event. The field may remain at zero or only reflect the last funding amount rather than the cumulative total.
Impact
- UI shows incorrectly funded amount on invoice detail page
- Outstanding balance calculations based on `funded_amount` are wrong
- Collateral ratio checks use wrong reference amount
- Events emitting `funded_amount` contain incorrect data
Fix
Update `funded_amount` using checked addition on every funding:
```rust
pub fn fund_invoice(env: Env, invoice_id: u64, amount: i128) {
let mut invoice = get_invoice(&env, invoice_id)?;
// ... checks ...
invoice.funded_amount = invoice.funded_amount
.checked_add(amount)
.ok_or(PoolError::AmountOverflow)?;
save_invoice(&env, invoice_id, &invoice);
// ... interactions ...
}
```
Acceptance Criteria
References
- `contracts/invoice/src/lib.rs` — `Invoice` struct, `funded_amount` field
- `contracts/pool/src/lib.rs` — `fund_invoice()`
Bug
`contracts/invoice/src/lib.rs` or `contracts/pool/src/lib.rs` — if invoices support partial funding (multiple lenders funding portions of an invoice), the `funded_amount` field in the `Invoice` struct may not be updated correctly after each partial funding event. The field may remain at zero or only reflect the last funding amount rather than the cumulative total.
Impact
Fix
Update `funded_amount` using checked addition on every funding:
```rust
pub fn fund_invoice(env: Env, invoice_id: u64, amount: i128) {
let mut invoice = get_invoice(&env, invoice_id)?;
// ... checks ...
invoice.funded_amount = invoice.funded_amount
.checked_add(amount)
.ok_or(PoolError::AmountOverflow)?;
save_invoice(&env, invoice_id, &invoice);
// ... interactions ...
}
```
Acceptance Criteria
References