Skip to content

feat(escrow): add raise_dispute and resolve_dispute#352

Merged
mikewheeleer merged 1 commit into
Talenttrust:mainfrom
Agbasimere:feature/dispute-lifecycle
May 27, 2026
Merged

feat(escrow): add raise_dispute and resolve_dispute#352
mikewheeleer merged 1 commit into
Talenttrust:mainfrom
Agbasimere:feature/dispute-lifecycle

Conversation

@Agbasimere
Copy link
Copy Markdown
Contributor

Closes: #315

Summary

Implements the escrow dispute lifecycle for arbiter-backed contracts.

What changed

  • Added raise_dispute(contract_id, caller) for client/freelancer escalation from Funded and PartiallyFunded
  • Added resolve_dispute(contract_id, arbiter, resolution) for arbiter settlement
  • Added DisputeResolution with:
    • FullRefund
    • PartialRefund (fixed 70/30 split favoring client)
    • FullPayout
    • Split(client_amount, freelancer_amount)
  • Added arbiter-aware contract creation via create_contract_with_arbiter(...)
  • Enforced dispute state-machine guards so milestone release is blocked while disputed
  • Enforced post-resolution accounting:
    • released_amount + refunded_amount == total_deposited
    • existing check_accounting_invariant still holds
  • Updated dispute documentation to match the shipped API and resolution behavior

Security Notes

  • raise_dispute requires authenticated caller and restricts access to client/freelancer only
  • resolve_dispute requires authenticated caller and exact match with stored contract.arbiter
  • Arbiter-less contracts fail closed and cannot enter dispute flow
  • Custom Split rejects negative values and rejects totals that do not match the remaining escrow balance
  • Resolution uses checked arithmetic and revalidates accounting invariants before persisting
  • Paused/emergency states block both dispute entrypoints
  • No new persistent dispute metadata storage was introduced, so there is no added TTL surface

Testing

Covered in unit tests:

  • client can raise dispute
  • freelancer can raise dispute on partially funded contract
  • non-party cannot raise dispute
  • contract without arbiter cannot raise dispute
  • full refund resolution
  • partial refund 70/30 resolution on remaining balance
  • custom split resolution
  • invalid split rejection
  • non-arbiter cannot resolve
  • non-disputed contract cannot resolve
  • release is blocked while disputed
  • pause blocks both dispute entrypoints

Validation

  • Passed: cargo check -p escrow --tests
  • Could not complete on this machine: cargo test -p escrow

Reason:

  • Windows GNU toolchain fails while linking the contract cdylib due to export ordinal limits
  • Installed MSVC toolchain is missing link.exe

@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented May 26, 2026

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

@mikewheeleer mikewheeleer merged commit 26ccb4c into Talenttrust:main May 27, 2026
1 check 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.

Implement dispute lifecycle: raise_dispute and resolve_dispute with arbiter payouts

2 participants