feat: reconcile pending settlements against Horizon#344
Merged
greatest0fallt1me merged 2 commits intoMay 27, 2026
Merged
Conversation
|
@samueloyibodevv 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! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
This PR adds an on-chain settlement-status sync flow so pending developer payouts are reconciled against the configured Horizon network and eventually transition to
completedorfailed. It closes the payout loop by polling Horizon for each pending settlementtx_hash, retrying transient Horizon failures with backoff, and settingcompleted_atonly after on-chain confirmation.Related Issue
Closes #310
Changes
⚙️ Settlement Reconciliation
[MODIFY]
src/services/revenueSettlementService.tsAdded
reconcilePendingSettlements()to query pending settlements and reconcile eachtx_hashagainst Horizon.Reused
withRetry(...)fromsrc/lib/retry.tsfor transient Horizon failures.Updated payout flow so successful submission leaves settlements in
pendingwith a transaction hash until confirmation.Ensured
completed_atis set only when Horizon confirms the transaction.[ADD]
src/services/settlementStatusSyncJob.tsAdded a background sync job that periodically runs settlement reconciliation.
Prevents overlapping reconciliation runs and logs failures without crashing the app.
🌐 Runtime Wiring
src/index.tsSTELLAR_NETWORKHorizon configuration viaconfig.stellar.horizonUrl.🧱 Store and Model Updates
[MODIFY]
src/types/developer.tsAdded
completed_atto the settlement shape.Extended
SettlementStorewithgetPendingSettlements()for reconciliation.[MODIFY]
src/services/settlementStore.tsAdded pending-settlement reads to the in-memory store.
Updated status transitions so
completed_atis populated only on confirmed completion.🧪 Tests
[MODIFY]
src/__tests__/revenueSettlementService.test.tsAdded coverage for Horizon-confirmed settlement completion.
Added coverage for unsuccessful Horizon transactions.
Added coverage for missing Horizon transactions.
Added coverage for retryable Horizon errors succeeding after backoff.
Added coverage for exhausted transient Horizon errors leaving status unchanged.
[MODIFY]
tests/integration/billing.test.tsUpdated the integration-test
SettlementStorehelper to support pending-settlement queries.🔧 Configuration and Docs
[MODIFY]
src/config/env.tsAdded environment validation for settlement sync interval and request timeout.
[MODIFY]
src/config/index.tsAdded settlement sync config values to the exported runtime config.
[MODIFY]
.env.exampleAdded
SETTLEMENT_STATUS_SYNC_INTERVAL_MS.Added
SETTLEMENT_STATUS_SYNC_TIMEOUT_MS.[MODIFY]
README.mdDocumented the new Horizon-based settlement reconciliation flow.
Documented the new environment variables and the pending-with-tx-hash lifecycle.
[MODIFY]
src/data/developerData.tsUpdated fixture validation to allow pending settlements with a non-empty transaction hash after payout submission.
Verification Results
completed_atis set only on confirmationSTELLAR_NETWORKconfigurationHow to Test
Screenshots
✅ Revenue settlement service tests pass
A screenshot of:
npm test -- src/__tests__/revenueSettlementService.test.ts