Skip to content

Integrate merchant accounts and fee events#159

Open
chigozirim007 wants to merge 1 commit intoShadeProtocol:mainfrom
chigozirim007:feat/fee-events-merchant-accounts
Open

Integrate merchant accounts and fee events#159
chigozirim007 wants to merge 1 commit intoShadeProtocol:mainfrom
chigozirim007:feat/fee-events-merchant-accounts

Conversation

@chigozirim007
Copy link

@chigozirim007 chigozirim007 commented Feb 26, 2026

PR Description

Summary

This PR completes the assigned issues by wiring merchant account deployment into registration, adding a fee collected event with breakdown, implementing time-locked fee updates, and introducing a simple volume-based fee discount system. It also updates the test suite to cover the new behaviors.

Linked Issues

Key Changes

Merchant account deployment and registration

  • initialize now accepts an account WASM hash and stores it in contract storage.
  • register_merchant deploys a MerchantAccount contract and stores the account address in the Merchant record and via get_merchant_account.
  • Merchant records now include an account: Address field.
  • Account factory includes a test-only deployment path to avoid deployer/wasm complexity in unit tests.

Fee collection event + breakdown

  • Added fee_collected_event with fields fee, token, and merchant_account.
  • Emitted on successful invoice payments and subscription charges.
  • Tests assert fee event presence and exact amounts.

Time-locked fee updates

  • First-time fee set is immediate.
  • Subsequent fee updates are delayed by 1 hour (3600 seconds) per token.
  • get_fee applies pending fee once activation time has passed.
  • Tests confirm fee updates are not immediate and only apply after the delay.

Fee discount system

  • Simple volume tiers (per merchant):
    • >= 1,000,000 total volume: fee is halved
    • >= 10,000,000 total volume: fee is quartered
  • Volume is tracked on successful invoice payments and subscription charges.
  • Tests validate discount application after threshold.

Behavior Notes / Breaking Changes

  • Breaking: initialize signature changed to initialize(env, admin, account_wasm_hash).
  • Merchant data now includes a required account field; tests and callers updated accordingly.
  • Time-locked fee updates introduce delayed fee effectiveness on updates (initial set remains immediate).

Files Touched (Highlights)

  • contracts/shade/src/shade.rs
  • contracts/shade/src/interface.rs
  • contracts/shade/src/types.rs
  • contracts/shade/src/components/merchant.rs
  • contracts/shade/src/components/account_factory.rs
  • contracts/shade/src/components/admin.rs
  • contracts/shade/src/components/invoice.rs
  • contracts/shade/src/components/subscription.rs
  • contracts/shade/src/events.rs
  • contracts/shade/src/tests/test_account_factory.rs
  • contracts/shade/src/tests/test_payment.rs
  • contracts/shade/src/tests/test_fees.rs

Testing

  • Not run (not requested).

Migration / Usage Notes

  • Callers must pass a valid MerchantAccount WASM hash during initialization.
  • Fee updates now require waiting 1 hour before taking effect.
  • Fee discounts apply automatically as merchant volume increases.

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

Labels

None yet

Projects

None yet

2 participants