Repository navigation
fix(recon): replace stub with claims and payout reconciliation engine - #995
Open
Ranjeet2063 wants to merge 1 commit into
Open
Ranjeet2063 wants to merge 1 commit into
Ranjeet2063 wants to merge 1 commit into
Conversation
Implement full claims and payout reconciliation against Soroban smart contract events and database records. - Implements 6 discrepancy rules: claimed_on_chain_missing_in_db, db_paid_missing_on_chain, amount_mismatch, claim_for_losing_prediction, duplicate_on_chain_claim, and stale_unclaimed - Uses exact BigInt Stroop arithmetic (7 decimal places) avoiding float inaccuracies - Adds reconciliation_reports and reconciliation_discrepancies tables with migration 0027 - Exposes keyset-paginated admin routes GET /api/admin/reports and GET /api/admin/reports/:id with OpenAPI registry & tests - Updates reconciliationWorker with Prometheus metrics and audit logs - Includes operator runbook and comprehensive unit test suite Closes Predictify-org#980
|
@Ranjeet2063 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! 🚀 |
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
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.
Summary of Changes
Replaced the stub reconciliation implementation with a production-ready Claims and Payout Reconciliation engine that compares on-chain Soroban contract claim events against database payout and prediction records.
Key Capabilities
6 Discrepancy Rules:
claimed_on_chain_missing_in_db: Event recorded on-chain but payout record missing from DB.db_paid_missing_on_chain: DB records payout as settled but no corresponding on-chain claim exists.amount_mismatch: Exact Stroop-level difference between on-chain claim amount and DB recorded payout amount.claim_for_losing_prediction: Claim event references a prediction row whose resolved outcome is 'lost'.duplicate_on_chain_claim: Multiple on-chain claim events emitted for the same prediction ID.stale_unclaimed: Winning prediction unclaimed past configured grace period.Exact Stroop Arithmetic:
parseExactStroopsandformatExactStroopsusing 7-decimal BigInt scaling to prevent floating-point inaccuracies.Database Persistence & Migrations:
reconciliation_reportsandreconciliation_discrepancieswith migrationdrizzle/0027_add_reconciliation_reports.sql.Admin Endpoints & OpenAPI Contract:
GET /api/admin/reports(keyset pagination cursor, status filter, limit).GET /api/admin/reports/:id(report metadata with joined discrepancies array).requireScopedAdmin(ADMIN_SCOPES.REPORT_READ).npm run openapi:check.Worker & Observability Integration:
reconciliationWorkerupdates Prometheus metrics:reconciliation_discrepancies_total{kind}.x-request-id,x-correlation-id).Documentation:
docs/runbook-reconciliation.mddetailing severity classifications and step-by-step triage actions.Verification & Test Evidence
tests/reconciliationPayouts.test.ts(26 tests covering all 11 issue scenarios + DB mock tests)tests/reconciliationWorker.test.ts(6 tests)tests/reconciliationService.test.tstests/adminReconciliation.test.ts(17 tests)npm run openapi:check-> PASS.npm run db:check-drift-> PASS (0 schema drift).Closes #980