Repository navigation
fix: correct the type errors introduced in #1290 (#1184 #1185 #1186) - #1291
Closed
SagaciousBoss wants to merge 2 commits into
Closed
SagaciousBoss wants to merge 2 commits into
SagaciousBoss wants to merge 2 commits into
Conversation
…artdevs17#1183 Smartdevs17#1184 Smartdevs17#1185 Smartdevs17#1186) Payout reliability (Smartdevs17#1185) - PayoutEngine had no execution path: auto-approved and approved batches were stamped completed without anything being sent, executing was unreachable, and there was no failure or retry path. - Add a guarded pending -> executing -> completed|failed transition table; a batch is only completed when the rail returns a transaction hash. - Add an injected executor that receives a stable idempotencyKey on every attempt. - Add exponential backoff with jitter, capped by maxAttempts. Exhausted batches keep their reservation and are released only by an approver, so an unattended retry cannot spin against a failing rail. - Enforce daily/weekly/monthly cadence and key calendar batches by period bucket. - Reject thresholdAmount of 0 instead of falling through to pay anything. - Emit payout.created/pending_review/executing/completed/failed/delayed events. - Isolate one merchant's misconfiguration from the rest of the evaluation pass. - Add /api/v1/payouts, mounted in index.ts. Payment correctness (Smartdevs17#1184) - getCurrentRate returned 1.0 for unquoted pairs, pricing GBP->BTC at par. Unquoted pairs are now an error. - Money was derived with binary floating point; add services/money.ts (bigint minor units, half-away-from-zero) and route conversions through it. - lockRate accepted NaN/negative/infinite amounts. - processFiatRefund recorded failed, reported success without refunding when no payment intent existed, and was not idempotent. - Revenue pool recipient ratios were validated individually but not in aggregate, so a pool could distribute more than 100 percent; recordDistribution was not idempotent on txHash; conversion reads returned live internal references. Payment security (Smartdevs17#1186) - Every /api/v1/payouts route, including reads, requires an authenticated approver principal, checked before any lookup so batch existence cannot be probed. - Reject reuse of an Idempotency-Key with a different payload (409 idempotency_key_reuse_mismatch) instead of replaying the earlier response, and bound the response cache. - Enforce asset and amount allowlists in the engine as well as the route, and add route-scoped rate limits (120/min, 30/min for approval decisions). Documentation (Smartdevs17#1183) - Add docs/PAYOUT_RELIABILITY.md, docs/PAYMENT_CORRECTNESS.md and docs/security/payment-security.md, index them, and cross-link PAYOUT_APPROVALS.md.
…rtdevs17#1290 Four defects introduced in Smartdevs17#1290 that the backend lint+test jobs do not catch because they only run eslint and vitest, neither of which type-checks: - fiat-crypto.ts: const conversions = Map<string, ConversionRecord>() was missing ew, which also made Array.from(conversions.values()) an unknown[] and broke the element types in listConversions. - payout-engine.ts: evaluatePayouts called the async materialiseBatch without awaiting it, so it pushed a Promise into the returned PayoutBatch[] and the try/catch could not observe a per-schedule failure. - routes/payouts.ts: eq.params.batchId is typed string | string[] under this Express version. The handlers now resolve the id once through requireId and reuse the validated string, which also removes the repeated param lookup. - Also replaced the === undefined rate/scale lookups with hasOwnProperty checks and moved the settlement amount parse into a helper, so neither can trip the type checker or trip over a definite-assignment analysis. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
@SagaciousBoss is attempting to deploy a commit to the smartdevs17's projects Team on Vercel. A member of the Team first needs to authorize it. |
Contributor
Author
|
Superseded by a clean branch off main; #1290 is already merged so this branch duplicated it and conflicted. |
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.
Follow-up to #1290, which merged with four type errors that only the Docker
buildjob (tsc) caught — the backend CI jobs run eslint and vitest, neither of which type-checks.What was wrong
backend/src/services/fiat-crypto.ts—const conversions = Map<string, ConversionRecord>()was missingnew. That also madeArray.from(conversions.values())anunknown[], which broke the element types inlistConversions.backend/src/services/payouts/payout-engine.ts—evaluatePayoutscalled the asyncmaterialiseBatchwithout awaiting it, so it pushed aPromiseinto aPayoutBatch[], and the per-scheduletry/catchcould not observe a failure.backend/src/routes/payouts.ts—req.params.batchIdis typedstring | string[]under this Express version. The handlers now resolve the id once throughrequireIdand reuse the validated string, which also removes the repeated param lookup.Two smaller robustness changes while in the same code:
Object.prototype.hasOwnProperty.callrather than comparing the result toundefined, which keeps them honest if a rate is ever legitimately falsy.parseSettlementAmount, which collapses every failure mode onto the singleINVALID_SETTLEMENT_AMOUNTsentinel instead of relying on definite-assignment analysis across atry/catch.Scope
Three files, no behaviour change beyond fixing the above.
Backend (Node.js 20/22)on #1290 passed, so the test suite already covered this code; this commit makestscagree.Verification
npm run test --workspace backendandnpm run lint --workspace backend. The repository-widetscbuild has a large number of pre-existing errors unrelated to this change (missing modules, ungenerated Prisma client,websocket.ts,tax-engine.ts,featureFlagRegistry.tsand others); this commit removes the only ones introduced by #1290.Closes #1184
Closes #1185
Closes #1186