Skip to content

Asset Balance Reconciliation Engine #535

Description

@Kingsman-99

Description

After batch invoice payments, the SDK's internal accounting of sent amounts can drift from on-chain balances due to failed operations, fee deductions, or claimable balance unclaims. A reconciliation engine should compare the SDK's internal PaymentRecord ledger against actual on-chain balances fetched from Horizon and surface any discrepancies as typed reconciliation findings.

Technical Context

Add src/reconciliationEngine.ts. Fetches actual balances via @stellar/stellar-sdk Server.loadAccount(). Reads PaymentRecord[] from src/recorder.ts. Computes expected vs actual balance deltas per asset per account. Adds ReconciliationFinding and ReconciliationReport to src/types.ts. Integrates with src/complianceExporter.ts to include reconciliation findings in compliance exports.

Acceptance Criteria

  • ReconciliationEngine.reconcile(accountId, assetCode, dateRange): Promise<ReconciliationReport> compares internal records to Horizon for the given date range
  • ReconciliationReport.findings lists each ReconciliationFinding with { expectedDelta, actualDelta, discrepancy, severity: 'info' | 'warning' | 'critical' }
  • Discrepancies attributable to fees alone are tagged severity: 'info'; unexplained discrepancies above a configurable threshold are 'critical'
  • ReconciliationReport.isBalanced is true only when all findings have zero discrepancy
  • Unit tests fabricate payment records and mock Horizon balances to assert that a missing payment surfaces as a 'critical' finding
  • All CI checks (npm test, npm run build, ESLint/TypeScript) pass and the branch has no merge conflicts

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions