Skip to content

Feature/escrow balance invariant#144

Merged
Cybermaxi7 merged 9 commits intoMarketXpress:mainfrom
Abrahamojobo:feature/escrow-balance-invariant
Mar 28, 2026
Merged

Feature/escrow balance invariant#144
Cybermaxi7 merged 9 commits intoMarketXpress:mainfrom
Abrahamojobo:feature/escrow-balance-invariant

Conversation

@Abrahamojobo
Copy link
Copy Markdown
Contributor

Closes #123

Description

This PR guarantees the mathematical invariant that the smart contract's token balance must inherently be perfectly tracked and always strictly greater than or equal to TotalFundedAmount minus TotalReleasedAmount.

Changes Included

  • Bug Fix (create_escrow): Detached the superficial increment to TotalFundedAmount out of the constructor bounds so it doesn't inflate stats before tokens arrive.
  • State Updates (fund_escrow): Safely moved TotalFundedAmount increments squarely into the token_client.transfer bounds.
  • Volume Egress Tracking (release_escrow, release_item, resolve_dispute): Implemented persistent tracking for TotalReleasedAmount globally across all endpoints that distribute tokens out of the smart contract's canonical local map.
  • Math Testing (test_contract_balance_invariant): Extended the integration environment to repeatedly evaluate the bounds equation across multi-party disputes and dynamic resolution paths to mathematically affirm 0 token bleeds natively.

Review Guide

Reviewers should specifically review contracts/marketx/src/lib.rs endpoints:

  • fund_escrow
  • release_escrow
  • release_item
  • resolve_dispute

@Cybermaxi7 Cybermaxi7 merged commit 58dbfcf into MarketXpress:main Mar 28, 2026
0 of 3 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.

Assert Contract Balance Equals Active Escrows

3 participants