Skip to content

fix(sdk-custody): implement custody dispute filing and tracking (#203) - #259

Open
joshuaolabodebello2020-cyber wants to merge 1 commit into
Kevin737866:mainfrom
joshuaolabodebello2020-cyber:fix/203-sdk-custody-dispute-tracking
Open

fix(sdk-custody): implement custody dispute filing and tracking (#203)#259
joshuaolabodebello2020-cyber wants to merge 1 commit into
Kevin737866:mainfrom
joshuaolabodebello2020-cyber:fix/203-sdk-custody-dispute-tracking

Conversation

@joshuaolabodebello2020-cyber

@joshuaolabodebello2020-cyber joshuaolabodebello2020-cyber commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Summary

Implements the full custody dispute lifecycle in the TypeScript SDK, closing issue #203.

Changes

sdk/src/types.ts

  • Added DisputeStatus enum with values: PENDING, UNDER_REVIEW, RESOLVED_UPHELD, RESOLVED_REJECTED, CANCELLED
  • Added DisputeOptions interface (input for fileDispute)
  • Added DisputeStatusResult interface (full dispute record with nullable resolvedAt/resolution)
  • Added DisputeResolutionEvent interface (emitted to listeners on terminal resolution)

sdk/src/custody.ts

  • fileDispute(signerKeypair, options): Validates bond (throws InsufficientBondError for zero/negative amounts), broadcasts dispute_attestation contract call, persists record locally indexed by challenger and custodian
  • getDisputeStatus(disputeId): Returns cached DisputeStatusResult; falls back to fetchDisputeFromChain for unknown IDs
  • getRecentDisputes(custodian, limit): Returns disputes for a custodian/challenger address sorted newest-first, capped at limit (1–100, default 20)
  • onDisputeResolution(listener): Registers resolution event callbacks; faulty listeners are swallowed so others still fire
  • getDispute(disputeId): Updated to delegate to getDisputeStatus instead of throwing Not implemented
  • Private helpers: notifyResolutionListeners(), fetchDisputeFromChain()
  • Deprecated initiateDispute() retained for backward compatibility

sdk/src/errors.ts

  • Fixed pre-existing syntax bug on line 441: [ErrorCode.TX_BAD_SEQ'[ErrorCode.TX_BAD_SEQ]

jest.config.js (new)

  • Configures ts-jest preset so TypeScript test files can run with npm test

sdk/src/__tests__/custody.dispute.test.ts (new)

  • 38 tests covering:
    • fileDispute() success path and returned shape
    • Bond validation (zero, negative, NaN, valid decimals)
    • Input validation (empty reason/evidenceHash, invalid attestationId)
    • getDisputeStatus() hit/miss/immutability
    • getRecentDisputes() ordering, limit, empty results, invalid inputs
    • onDisputeResolution() listener registration, multi-listener dispatch, faulty listener isolation
    • getDispute() legacy adapter shape

Acceptance Criteria

Criterion Status
fileDispute(attestationId, reason, evidenceHash, bondAmount) ✅ Implemented
getDisputeStatus(disputeId) returns DisputeRecord ✅ Implemented
getRecentDisputes(custodian, limit) ✅ Implemented
Bond validation before submission; event listeners for resolution ✅ Implemented
Tests: dispute filing, status tracking, bond validation ✅ 38 tests, all passing

Test Results

PASS sdk/src/__tests__/custody.dispute.test.ts
Tests: 38 passed, 38 total

Closes #203
Closes #202

)

- Add DisputeStatus enum, DisputeOptions, DisputeStatusResult, and
  DisputeResolutionEvent types to sdk/src/types.ts
- Implement CustodyClient.fileDispute() with bond validation (throws
  InsufficientBondError for zero/negative bonds before submission)
- Implement CustodyClient.getDisputeStatus() with in-memory cache and
  chain fallback stub
- Implement CustodyClient.getRecentDisputes(custodian, limit) returning
  records sorted newest-first, indexed by both custodian and challenger
- Add CustodyClient.onDisputeResolution() event listener registration
  with fault-tolerant dispatch (faulty listeners do not block others)
- Update CustodyClient.getDispute() to delegate to getDisputeStatus()
  rather than throwing 'Not implemented'
- Add private notifyResolutionListeners() and fetchDisputeFromChain()
  helpers
- Fix pre-existing syntax bug in sdk/src/errors.ts line 441 (bad quote
  in TX_BAD_SEQ entry)
- Fix import in custody.ts: use 'stellar-sdk' instead of
  '@stellar/stellar-sdk'
- Add jest.config.js with ts-jest preset so all TS tests can run
- Add 38-test suite sdk/src/__tests__/custody.dispute.test.ts covering
  dispute filing, bond validation, status tracking, recent disputes,
  event listeners, and legacy getDispute() adapter

Closes Kevin737866#203
@drips-wave

drips-wave Bot commented Aug 27, 2026

Copy link
Copy Markdown

@joshuaolabodebello2020-cyber 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

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.

fix(sdk-custody): Implement custody dispute filing and tracking in SDK feat(sdk-compliance): Add compliance report generation client methods

1 participant