Skip to content

feat(invoice-escrow): implement complete dispute resolution lifecycle with timeout and default fallback #378

Description

@chizzy192

Context & Problem Statement

Commercial trade invoices occasionally experience invoice disputes regarding deliverable quality, delivery delays, or billing discrepancies. Without an on-chain dispute state machine, escrows remain locked in Funded state until the overdue deadline lapses, which can trigger an unfair automatic refund to the buyer.

This issue implements an on-chain dispute state machine with formal transitions (Funded -> Disputed -> Settled/Refunded), dispute metadata tracking, admin resolution with favor assignment, and an automated timeout fallback mechanism.

Architectural Motivation & Technical Requirements

  • In contracts/invoice-escrow/src/types.rs:
    • Add EscrowStatus::Disputed variant.
    • Add DisputeData { raiser: Address, reason: Bytes, raised_at: u64, resolved: bool }.
    • Add dispute_timeout_secs: u64 to Config (default: 604800s / 7 days).
  • In contracts/invoice-escrow/src/lib.rs:
    • Implement raise_dispute(env, caller: Address, invoice_id: Symbol, reason: Bytes):
      • Asserts escrow is in Funded status.
      • Transitions status to Disputed and records DisputeData.
      • Emits DisputeRaised event.
    • Implement resolve_dispute(env, admin: Address, invoice_id: Symbol, favour: Symbol):
      • If favour == 'seller', settles funds to seller.
      • If favour == 'buyer', refunds funds to buyer.
      • If called after dispute_timeout_secs, executes default fallback (refund to buyer).
  • In contracts/invoice-escrow/src/errors.rs:
    • Add NotDisputed, AlreadyResolved, DisputeTimedOut.
  • In contracts/invoice-escrow/src/test.rs:
    • Test dispute raise by buyer/seller.
    • Test resolution in favor of seller and buyer.
    • Test timeout expiration triggering default refund.

Acceptance Criteria

  • Full dispute lifecycle implemented with all state transitions.
  • Timeout fallback behavior verified.
  • Unauthorized dispute resolution attempts rejected.
  • cargo test -p invoice-escrow passes.

Target Branch: dev
Estimated Effort: 13–24 hours | Delivery: 6–7 days
Difficulty: Hard

Activity

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

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions