Repository navigation
feat(fiat): fiat transaction limits, velocity controls & KYC-tier enforcement (#362) - #736
Open
huangji6693-max wants to merge 1 commit into
Conversation
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
Closes #362
Implements platform-side fiat transaction limits, rolling-window velocity controls, and KYC-tier enforcement across manual and scheduled fiat on-ramp/off-ramp order creation paths.
Key Changes
enum KycTier { TIER_0 TIER_1 TIER_2 TIER_3 },model KycProfile, andmodel FiatLimitPolicywith seeded default tier policies and direction-specificoffRampOverrides.20261027020000_fiat_limits_kyc_tierswithmigration.sqlandrollback.sql.src/fiat/limits.ts):evaluateFiatOrder({ userId, direction, amount, currency, tier, recentOrders, now, policy, fxRate, fxFeedAvailable, isFrozen }):compliance_freeze).tier_zero,per_txn, rolling 1hvelocity_hourly, rolling 24hvelocity_daily, rolling 24hdailyvolume, and rolling 30d / calendarmonthlyvolume.PENDING,PROCESSING, andSETTLEDorders immediately; releases headroom onFAILED/REFUNDEDas of the failure/refund timestamp without retroactively rewriting prior windows.rateSource: 'FX_FEED') and fails closed (fx_unavailable) when the FX feed is down.limitWarningwhen post-order utilization exceedsLIMIT_SOFT_WARN_PCT(80%).evaluateScheduledFiatRun: returnsskipped_limiton denial and auto-pauses scheduled plans afterN = 3consecutiveskipped_limitruns.src/fiat/service.ts,src/routes/fiat.ts,src/routes/kyc.ts,src/routes/admin.ts):evaluateFiatOrderintocreateFiatOrder(returns403 fiat_limit_exceededon denial; attacheslimitWarningand emitsfiat.limit.approachingon soft warning) and addedexecuteScheduledFiatOrder.GET /api/v1/fiat/limitsreturning caller's tier, per-windowlimit/used/remaining, andnextResetAt.POST /api/v1/kyc/verifyand signature-verifiedPOST /api/v1/kyc/webhook/:provider.GET/PUT /api/v1/admin/fiat/limit-policiesandPOST /api/v1/admin/users/:id/kyc-tier(requiresreviewNote, audit-logged).docs/FIAT_LIMITS.md, updateddocs/openapi.yamlanddocs/API_KEYS.md.tests/unit/fiat/limits.test.ts) and integration tests (tests/integration/fiat-limits.integration.test.ts).