Skip to content

Fix/settlement finality unification 146#149

Merged
Obiajulu-gif merged 3 commits into
Chainmove:mainfrom
Alaka-ibr:fix/settlement-finality-unification-146
Jul 27, 2026
Merged

Fix/settlement finality unification 146#149
Obiajulu-gif merged 3 commits into
Chainmove:mainfrom
Alaka-ibr:fix/settlement-finality-unification-146

Conversation

@Alaka-ibr

Copy link
Copy Markdown
Contributor

Summary

Closes #146 by unifying settlement finality states across Paystack payments, bank transfers, internal ledger entries, and Stellar transactions into a canonical state machine.

Key Changes

  • Canonical State Machine: Added SettlementRecord model and transition engine covering initiated, provider-pending, observed, provisionally_credited, confirmed, reversed, disputed, failed, and expired states.
  • Balance Bucket Separation: Extended User schema with distinct availableBalance, pendingBalance, heldBalance, and reversedBalance fields so payout/investment operations depend strictly on confirmed funds.
  • Reversal Journals: Standardized reversals through counter-debit journal entries rather than in-place edits, preserving complete audit trails without creating negative available balances.
  • Causal Links & Idempotency: Established 1:1 cross-rail correlation across provider references, Stellar hashes, ledger journals, pool investments, and user transactions.
  • Operator Timeline & API: Added operator timeline diagnostics and administrative remediation endpoints at /api/admin/settlement/timeline.

Verification

  • Added test suite in __tests__/lib/settlement/settlement.test.ts covering out-of-order webhooks, delayed transfers, Stellar failures, reversals, duplicate references, timeouts, and concurrent processing.

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.

[HARD][SETTLEMENT FINALITY] Unify pending, confirmed, reversed, and disputed states across Paystack and Stellar

2 participants