Skip to content

feat(invoice-escrow): add custom fee schedule per invoice category - #269

Open
richardgittest wants to merge 1 commit into
StellarState:devfrom
richardgittest:feature/invoice-escrow-category-fee-schedule
Open

feat(invoice-escrow): add custom fee schedule per invoice category#269
richardgittest wants to merge 1 commit into
StellarState:devfrom
richardgittest:feature/invoice-escrow-category-fee-schedule

Conversation

@richardgittest

@richardgittest richardgittest commented Jul 27, 2026

Copy link
Copy Markdown

Summary

Implements custom fee schedule per invoice category in contracts/invoice-escrow.

Closes the linked issue.

Changes

types.rs

  • Added InvoiceCategory enum: Standard, Factoring, Reverse, Government
  • Added CategoryFeeSchedule { fee_bps: u32 } struct
  • Added StorageKey::CategoryFee(InvoiceCategory) variant
  • Added category: InvoiceCategory and effective_fee_bps: u32 fields to EscrowData

errors.rs

  • Fixed pre-existing duplicate discriminant bug (InvalidPayer was = 15, same as Paused) — bumped to 16, InvalidDueDate to 17
  • Added CategoryFeeNotFound = 19

storage.rs

  • Added get_category_fee, set_category_fee, remove_category_fee helpers (instance storage)
  • Merged upstream TTL management and buyer whitelist helpers

events.rs

  • Added category_fee_set(category, old_fee_bps, new_fee_bps) event
  • Extended escrow_created signature with category (as u32) and effective_fee_bps
  • Merged upstream escrow_status_changed event

lib.rs

  • set_category_fee — admin-only, validates fee_bps ≤ 10_000, emits cat_fee_set
  • get_category_fee_schedule — view returning schedule or CategoryFeeNotFound
  • create_escrow — accepts new category: InvoiceCategory param; resolves and stamps effective_fee_bps (category override > global default)
  • record_payment — uses data.effective_fee_bps (immutable, stamped at creation)
  • Merged upstream whitelist enforcement in fund_escrow and escrow_status_changed calls

test.rs

  • All 54 existing create_escrow call-sites updated with new category param
  • Event tuple assertions updated to reflect new 11-field escrow_created data
  • 19 new tests added covering: set_category_fee (success, auth, invalid bps, max/zero, overwrite, event), get_category_fee_schedule (not found, independence), fee resolution (global fallback, override, precedence, all 4 categories), record_payment with category fee (immutability after creation, zero-fee), event field verification

What was tested

  • All 54 existing create_escrow call-sites compile with the new category parameter
  • 19 new unit tests cover every new code path and edge case
  • Merged cleanly with upstream/dev (whitelist feature + TTL management)

Closes #76

- Add InvoiceCategory enum (Standard, Factoring, Reverse, Government)
- Add CategoryFeeSchedule struct with fee_bps field
- Add StorageKey::CategoryFee(InvoiceCategory) for per-category storage
- Add EscrowData.category and EscrowData.effective_fee_bps fields
- Add set_category_fee (admin-only) and get_category_fee_schedule (view)
- Resolve effective_fee_bps at create_escrow time: category override > global
- record_payment now uses data.effective_fee_bps (immutable after creation)
- Add CategoryFeeNotFound = 19 error variant
- Fix pre-existing duplicate discriminant bug (InvalidPayer was 15 = Paused)
- Extend escrow_created event with category and effective_fee_bps fields
- Add category_fee_set event emitted on set_category_fee
- Add 19 new unit tests covering all new code paths
- Update all existing test call-sites with new category parameter
- Merge upstream/dev additions: whitelist, TTL management, escrow_status_changed
@drips-wave

drips-wave Bot commented Jul 27, 2026

Copy link
Copy Markdown

@richardgittest 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

@chizzy192

Copy link
Copy Markdown
Contributor

@richardgittest
FIX MERGE CONFLICTS PLS

@chizzy192

Copy link
Copy Markdown
Contributor

Hi @richardgittest! 👋 Thanks for your PR. CI checks are failing (2 failing checks). Please check the test failures and update your branch.

@chizzy192

Copy link
Copy Markdown
Contributor

Hi @richardgittest, please rebase on dev to resolve conflicts in contracts/invoice-escrow/src/fee.rs. Verify that custom fee category calculations handle boundary fee basis points (0 BPS and 10,000 BPS max) cleanly in cargo test.

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.

[CONTRACTS] Invoice Escrow: Add Custom Fee Schedule per Invoice Category

2 participants