Skip to content

fix: invoice funded_amount field not updated on partial funding — shows zero #796

Description

@sanmipaul

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

  • `funded_amount` accumulates correctly across multiple partial fundings
  • Unit test: two partial fundings → `funded_amount == sum of both`
  • Unit test: full single funding → `funded_amount == invoice amount`
  • No use of `saturating_add` for `funded_amount` accumulation
  • `get_invoice()` returns correct `funded_amount` after each funding

References

  • `contracts/invoice/src/lib.rs` — `Invoice` struct, `funded_amount` field
  • `contracts/pool/src/lib.rs` — `fund_invoice()`

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingsmart-contractSoroban/Rust contract work

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions