Feature/issues 1 2 3 4 invoice treasury - #528
Open
Freezyyy-arch wants to merge 4 commits into
Open
Conversation
…EELBACK#1) Callers previously had no on-chain way to list a merchant's invoices and had to know invoice IDs ahead of time, forcing the backend indexer to reconstruct merchant->invoice mappings off-chain (which drifts during reorgs). Adds get_invoices_by_merchant(merchant, start_after, limit) to the invoice contract, following the same start_after/limit pagination shape as the treasury contract's get_pending_settlements, with limit capped at 100. Also bumps the pinned soroban-sdk version (20.0.0 -> 22.0.0) across the contracts workspace and fixes two pre-existing compile errors this uncovered in the invoice contract (ContractError::Overflow and ::AddressBlocked were referenced but never defined in the enum) — the contract did not actually compile on main prior to this change. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Merchants integrating with COMEBACKHERE had no free-form field to reconcile on-chain invoices with their own order/reference IDs, forcing them to maintain a separate off-chain mapping table. Adds an optional `reference: Option<String>` field (bounded to 64 bytes, rejected with a new ContractError::ReferenceTooLong otherwise) to the Invoice struct and as an optional trailing parameter on create_invoice. Wires it through the backend: POST /invoices accepts an optional `reference` (validated to <=64 UTF-8 bytes), persists it on the invoice record, and abis/invoice.json is regenerated via scripts/generate_abi_metadata.py to reflect the current contract interface (see docs/abi-snapshot-workflow.md). Also removes an orphaned, duplicate InvoiceStatus/InvoiceRecord/ InvoiceSearchFilter block in comebackhere-backend/src/db/mongo.ts left over from an earlier merge, which was causing duplicate-identifier compile errors and blocking the backend's TypeScript build entirely. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
) The minimum amount check (10,000,000 stroops / 1 USDC) added in WHEELBACK#11 had tests for values above and below the threshold, but nothing asserting the boundary value itself. Adds: - a test creating an invoice with amount == 10_000_000, asserting success - a test with 10_000_000 - 1, asserting AmountPrecision is returned The WHEELBACK#11 check itself was never actually present in the current invoice contract — it only ever existed in an old, abandoned contract layout (contracts/invoice/src/lib.rs) that predates the current COMEBACKHERE-contracts/contracts/invoice/src/lib.rs rewrite, so it was silently dropped. Re-adds MIN_AMOUNT_USDC validation (rejecting create_invoice with a new ContractError::AmountPrecision) so the boundary tests have something to assert against, and bumps existing tests' hardcoded amounts above the new minimum. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
…HEELBACK#4) Signers previously had no way to know whether execute_settlement would succeed without submitting the real transaction. Adds a read-only simulate_settlement(settlement_id) function to the treasury contract that performs the same checks execute_settlement does (quorum reached, treasury balance sufficient) without mutating any storage, returning a SettlementSimulation with the current approval weight/threshold and the projected post-settlement treasury balance. Wires this through the backend as POST /api/treasury/simulate-settlement (comebackhere-backend/ src/routes/treasury.ts), so the frontend (SettlementDetail) can preview outcome and USDC balance impact before a signer commits. Along the way, fixes several pre-existing bugs in the treasury contract that blocked it from compiling/testing at all under a supported soroban-sdk version: missing DataKey::SignerList and TreasuryError variants (ThresholdExceedsWeight, InvalidPagination) referenced but never defined, a missing total_signer_weight helper used by update_threshold, a use-after-move on update_settlement_merchant, and outdated testutils API usage in the pre-existing pagination/benchmark tests (get_pending_settlements' client method already unwraps on success — tests were calling .unwrap() on the unwrapped value and comparing against Ok(..)/Err(..) instead of using try_ get_pending_settlements for the error case). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
|
@Freezyyy-arch 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! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #398
Closes #399
Closes #401
Closes #403
SUMMARY
Commit 1 —
get_invoices_by_merchant(#1):** Added the paginated lookup function to the invoice contract (start_after/limit, capped at 100), matching treasury'sget_pending_settlementsshape, with 4 tests. Also bumped the pinnedsoroban-sdk20→22 and fixed two pre-existing compile errors (ContractError::Overflow/::AddressBlockedwere referenced but never defined) — the invoice contract didn't build onmainbefore this.Commit 2 — optional
referencefield (#3):** Addedreference: Option<String>(64-byte cap, newReferenceTooLongerror) to the invoice struct andcreate_invoice, wired through the backend (POST /invoicesaccepts it, schema-validated, persisted), and regeneratedabis/invoice.jsonvia the realgenerate_abi_metadata.py. Also removed an orphaned duplicateInvoiceStatus/InvoiceRecordblock inmongo.tsleft from a bad merge — it was blocking the backend's TS build entirely.Commit 3 — minimum-amount boundary tests (#2):** Found that the
AmountPrecision/10,000,000-stroop check from #11 was never actually present in the current contract (only in an old, abandoned contract layout). Re-addedMIN_AMOUNT_USDCvalidation plus the two requested boundary tests (exactly-at-minimum succeeds, one-below fails).Commit 4 —
simulate_settlement(#4):** Added the read-only preview function to the treasury contract (same quorum/balance checks asexecute_settlement, no state mutation) and wiredPOST /api/treasury/simulate-settlementin the backend. Fixed several pre-existing treasury bugs blocking compilation (missingSignerList/ThresholdExceedsWeight/InvalidPagination, a missingtotal_signer_weighthelper, a use-after-move, and stale test API usage).