Skip to content

feat(invoice-escrow): implement category-specific fee schedules with per-category BPS storage #377

Description

@chizzy192

Context & Problem Statement

The platform currently applies a uniform fee BPS across all escrow transactions. Different commercial invoicing sectors (e.g. factoring, reverse factoring, government contracts, standard trade credit) operate on vastly different margin profiles and risk parameters, necessitating distinct platform fee schedules per invoice category.

This issue implements an InvoiceCategory enum, persistent category fee storage, admin configuration methods, and dynamic fee lookups during escrow creation.

Architectural Motivation & Technical Requirements

  • In contracts/invoice-escrow/src/types.rs:
    • Define InvoiceCategory enum: Standard, Factoring, Reverse, Government.
    • Define CategoryFeeSchedule { fee_bps: u32 }.
    • Add category: InvoiceCategory to EscrowData.
    • Add StorageKey::CategoryFee(InvoiceCategory).
  • In contracts/invoice-escrow/src/lib.rs:
    • Implement set_category_fee(env, admin, category: InvoiceCategory, fee_bps: u32) (admin only, bounds 0..=10000).
    • Update create_escrow to accept category: Option<InvoiceCategory> (defaulting to Standard).
    • Retrieve and apply the corresponding category fee rate during fee deduction.
  • In contracts/invoice-escrow/src/test.rs:
    • Test fee lookups for each category.
    • Test default fallback when no category fee is configured.
    • Test boundary validation (0 BPS and 10000 BPS max).
    • Test unauthorized configuration attempts.

Acceptance Criteria

  • All 4 categories independently configurable by admin.
  • create_escrow calculates fees based on category rate.
  • Fee boundary checks (0 to 10000 BPS) enforced.
  • cargo test -p invoice-escrow passes cleanly.

Target Branch: dev
Estimated Effort: 5–12 hours | Delivery: 3–5 days
Difficulty: Medium

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions