Skip to content

feat(invoice): add get_funding_terms to consolidate three CPI calls i… - #512

Merged
K1NGD4VID merged 6 commits into
TrusTrove:mainfrom
Oyintarede:issue-278-get-funding-terms
Sep 7, 2026
Merged

feat(invoice): add get_funding_terms to consolidate three CPI calls i…#512
K1NGD4VID merged 6 commits into
TrusTrove:mainfrom
Oyintarede:issue-278-get-funding-terms

Conversation

@Oyintarede

Copy link
Copy Markdown
Contributor

…nto one

Closes #278

Summary

Add get_funding_terms(invoice_id) -> (u32, u128, u32) to the invoice contract, returning (status, face_value, discount_bps) in a single cross-contract invocation. Migrate the pools fund_invoicefunction to call it once instead of making three separateinvoke_contract calls (get_status+get_face_value+get_discount_bps`).

Changes

contracts/invoice/src/lib.rs

  • Add get_funding_terms public function with full rustdoc (# Arguments, # Auth, # Panics, # Returns)
  • Fetches the invoice once from storage and destructures the three fields, saving two redundant storage reads

contracts/pool/src/lib.rs

  • Replace three separate invoke_contract calls with a single get_funding_terms call in fund_invoice
  • Tuple destructuring extracts status, face_value, and discount_bps into local variables
  • Behaviour is unchanged: status check (Listed == 1) and funded_amount calculation remain identical

contracts/invoice/src/test.rs

Test snapshots

  • Remove three stale pool test snapshots whose diagnostic event stream changed due to the consolidated CPI call

Acceptance Criteria

  • Add get_funding_terms on the invoice contract
  • Pool calls it once instead of three times
  • Tests added for new function (positive + negative)
  • Old pool snapshots removed (will regenerate on next test run)

Definition of Done

  • PR links to this issue with Closes #278
  • New behaviour covered by positive and negative tests
  • Rustdoc documents Arguments, Auth, Panics, Returns
  • CI: cargo fmt, clippy, and tests pass (pending CI run)

Linked Issue

Closes #

Summary

Changes

Test Coverage

  • Positive path test added
  • Negative path test added (where applicable)
  • All existing tests pass

Checklist

  • cargo fmt --all --check passes
  • cargo clippy --all-targets -- -D warnings passes
  • cargo test --workspace passes
  • Documentation updated (if applicable)
  • CHANGELOG.md updated (if applicable)

Screenshots

N/A

…nto one

Closes TrusTrove#278

## Summary

Add `get_funding_terms(invoice_id) -> (u32, u128, u32)` to the invoice
contract, returning (status, face_value, discount_bps) in a single
cross-contract invocation. Migrate the pool`s `fund_invoice` function
to call it once instead of making three separate `invoke_contract`
calls (`get_status` + `get_face_value` + `get_discount_bps`).

## Changes

### contracts/invoice/src/lib.rs
- Add `get_funding_terms` public function with full rustdoc
  (# Arguments, # Auth, # Panics, # Returns)
- Fetches the invoice once from storage and destructures
the three fields, saving two redundant storage reads

### contracts/pool/src/lib.rs
- Replace three separate `invoke_contract` calls with a
single `get_funding_terms` call in `fund_invoice`
- Tuple destructuring extracts status, face_value, and
discount_bps into local variables
- Behaviour is unchanged: status check (Listed == 1) and
funded_amount calculation remain identical

### contracts/invoice/src/test.rs
- Positive test: `test_get_funding_terms_returns_correct_values`
  verifies all three returned fields match expected values
- Negative test: `test_get_funding_terms_unknown_panics` verifies
  NotFound (TrusTrove#2) panic for a non-existent invoice

### Test snapshots
- Remove three stale pool test snapshots whose diagnostic
event stream changed due to the consolidated CPI call

## Acceptance Criteria

- [x] Add get_funding_terms on the invoice contract
- [x] Pool calls it once instead of three times
- [x] Tests added for new function (positive + negative)
- [x] Old pool snapshots removed (will regenerate on next test run)

## Definition of Done

- [x] PR links to this issue with `Closes TrusTrove#278`
- [x] New behaviour covered by positive and negative tests
- [x] Rustdoc documents Arguments, Auth, Panics, Returns
- [ ] CI: cargo fmt, clippy, and tests pass (pending CI run)
@Oyintarede
Oyintarede requested a review from K1NGD4VID as a code owner July 29, 2026 14:48
@drips-wave

drips-wave Bot commented Jul 29, 2026

Copy link
Copy Markdown

@Oyintarede Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

…ng-terms

# Conflicts:
#	contracts/invoice/src/lib.rs
#	contracts/invoice/src/test.rs
#	contracts/pool/test_snapshots/test/test_fund_invoice_fails_asset_mismatch.1.json
#	contracts/pool/test_snapshots/test/test_fund_invoice_fails_when_insufficient_liquidity.1.json
#	contracts/pool/test_snapshots/test/test_fund_invoice_reduces_available_liquidity.1.json
@mergekeeper

mergekeeper Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

MergeKeeper merge status

Status: blocked
PR state: open
Mergeability: unknown
Checked commit: fa38e8d42aed572830ff491713188381ac55313b.

Reason:
GitHub pull request merge request failed with 403: Resource not accessible by integration

Next steps:
GitHub rejected this as a permissions/ruleset problem, not a review problem — a maintainer merge override cannot force this through.

  1. Confirm the MergeKeeper GitHub App has Contents: Read & write and Pull requests: Read & write permissions for this repository.
  2. If this repository uses a ruleset, add the MergeKeeper GitHub App as a Bypass actor on it (Settings → Rules → Rulesets → the ruleset → Bypass list) — this is what the "bypass rules" checkbox on GitHub's merge button represents, and MergeKeeper can only do the same once it's listed there.
  3. Retry the merge once either is fixed.

mergekeeper[bot]
mergekeeper Bot previously approved these changes Aug 26, 2026

@mergekeeper mergekeeper Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved

Maintainer-authorized dependency-bot merge.

…ng-terms

Resolve modify/delete conflicts on three stale pool fund_invoice test
snapshots by keeping their removal: the consolidated get_funding_terms
CPI call changed the diagnostic event stream, and the branch's tests use
should_panic/assert assertions rather than snapshot comparison. The
snapshots regenerate on the next test run.

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
Oyintarede and others added 2 commits September 7, 2026 11:47
…ng-terms

Resolve conflicts with upstream's latest pool/invoice/registry changes:
- Keep fund_invoice's single get_funding_terms cross-contract call, adopting
  upstream's checked_mul overflow guard (TrusTrove#585) for the unbounded face_value.
- Keep the three stale fund_invoice snapshots deleted (tests use
  should_panic/assert assertions, not snapshot comparison).
- Add get_funding_terms to MockHugeFaceInvoice and attest before
  list_for_financing in the invoice test (upstream now requires attestation).

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
@K1NGD4VID
K1NGD4VID merged commit 00494c7 into TrusTrove:main Sep 7, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Low] refactor(pool): share invoice-listing lookup CPIs behind a single call

2 participants