Skip to content

feat: comprehensive stablecoin hardening — atomicity, middleware, polyglot services, UI/UX parity#26

Merged
munisp merged 1 commit into
devin/1779302835-typescript-strict-fixesfrom
devin/1782245425-stablecoin-hardening
Jun 23, 2026
Merged

feat: comprehensive stablecoin hardening — atomicity, middleware, polyglot services, UI/UX parity#26
munisp merged 1 commit into
devin/1779302835-typescript-strict-fixesfrom
devin/1782245425-stablecoin-hardening

Conversation

@devin-ai-integration

Copy link
Copy Markdown
Contributor

Summary

Closes all 10 stablecoin gaps identified in the audit. Every stablecoin endpoint now flows through the atomic fund flow middleware (Redis distributed lock → idempotency cache → TigerBeetle double-entry → Temporal saga compensation → Kafka/Fluvio events), matching the safety guarantees on fiat fund flows from PRs #21-23.

Core changes

Atomicity wrapper (server/middleware/stablecoinAtomicity.ts): All 14 stablecoin mutations now call executeAtomicStablecoinFlow() which delegates to withAtomicFundFlow() from PR #22, adding stablecoin-specific Kafka topic routing and insider threat control checks (maker-checker for ops >$10K, geo-fencing, DLP).

Non-atomic wallet fix: stakeForYield and bridgeChain previously did SELECT balance → JS check → UPDATE. Now use pessimistic WHERE CAST(balance AS DECIMAL) >= amount on all debit paths.

3 new router endpoints on stablecoinEnhanced:

  • redeemP2pClaim — validates claim link, checks 30-day expiry, credits stablecoin
  • pauseDcaPlan / resumeDcaPlan — DCA lifecycle management

DCA + auto-convert + P2P claim (server/services/stablecoinScheduler.ts):

  • executeDcaPurchase(plan) → atomic fiat→stablecoin via executeAtomicStablecoinFlow
  • autoConvertIncomingRemittance(userId, amount, fiatCurrency, ref) → checks user preference, converts % to target stablecoin
  • executeP2pClaim(claimId, userId) → validates 30-day expiry, atomic credit
  • expireStaleP2pClaims() → daily cron refunds expired claims to senders

Polyglot services

Service Port Key responsibility
Go settlement 8200 TigerBeetle ledger writes via Dapr, Kafka event publishing, Circle/Yellow Card/Mojaloop webhook handlers, saga lifecycle orchestration
Rust on-chain guard 8210 Ed25519/ECDSA signature verification, fencing tokens (monotonic sequence per wallet), double-spend detection (in-memory bloom filter + PostgreSQL), SHA-256 receipt chain
Python oracle 8220 Live FX rates (4-source median from CoinGecko/Binance/CoinMarketCap/Chainlink, reject >0.5% deviation), de-peg monitoring (1% threshold, Fluvio alert), DeFi yield tracking (Aave/Compound/Venus APY)

Infrastructure configs

  • APISix (infra/apisix/stablecoin-routes.yaml): 14 routes with circuit breaking (2-5 failure threshold), rate limiting, OpenAppSec WAF on webhook endpoints
  • OpenSearch (infra/opensearch/stablecoin-index-templates.json): Index templates for transactions, settlements, depeg events, FX rates
  • Fluvio (infra/fluvio/stablecoin-streaming.yaml): 11 topics with SmartModules (depeg-filter, high-value-filter, fx-anomaly-detector)
  • Lakehouse (infra/lakehouse/stablecoin-tables.yaml): Bronze (raw events) → Silver (enriched) → Gold (aggregated) analytics tables

UI/UX parity

  • PWA (Stablecoin.tsx): 11-tab dashboard — on-ramp, off-ramp, bank withdrawal, swap, send, yield, bridge, P2P send, bill pay, DCA, virtual card. De-peg alert banner. Fixed trpc.stablecoin.*trpc.stablecoinPlatform.* for enhanced endpoints.
  • Flutter (stablecoin_screen.dart): 7-tab screen with all operations, matching dark theme
  • React Native (StablecoinScreen.tsx): 7-tab screen with modal picker, all 8 mutations wired

Tests

50+ vitest assertions in server/stablecoin-hardening.test.ts covering: atomicity wrapper, pessimistic debit, DCA scheduler, auto-convert, P2P claim flow (30-day expiry), APISix routes (14 routes, 11 circuit breakers), OpenSearch templates, Fluvio topics, Lakehouse tables, Go/Rust/Python service structure, UI parity verification.

6,633 lines added across 16 files, 0 TypeScript errors.

Link to Devin session: https://app.devin.ai/sessions/64d054ae77da41e9a2b74d8593fa635c
Requested by: @munisp

…yglot services, UI/UX parity

- Wire all 14 stablecoin endpoints through atomic fund flow middleware
  (Redis locks, idempotency, TigerBeetle double-entry, Temporal sagas, Kafka events)
- Fix non-atomic wallet updates with pessimistic WHERE balance >= amount
- Add DCA scheduler, auto-convert watcher, P2P claim flow with 30-day expiry
- Add 3 new router endpoints: redeemP2pClaim, pauseDcaPlan, resumeDcaPlan
- Wire insider threat controls (maker-checker, geo-fence, DLP) on stablecoin ops

Polyglot services:
- Go settlement orchestrator (port 8200): TigerBeetle ledger, Dapr state,
  Kafka events, Circle/Yellow Card webhook handlers, Mojaloop ILP settlement
- Rust on-chain guard (port 8210): Ed25519/ECDSA signature verification,
  fencing tokens, double-spend detection, receipt chain
- Python oracle (port 8220): Live FX rates (4-source median), de-peg monitoring
  (1% threshold), DeFi yield tracking (Aave/Compound/Venus), Fluvio streaming

Infrastructure:
- APISix: 14 stablecoin routes with circuit breaking + rate limiting
- OpenAppSec: WAF rules for webhook endpoints
- OpenSearch: Index templates for transactions, settlements, depeg events, FX rates
- Fluvio: 11 topics with SmartModules (depeg filter, high-value filter, FX anomaly)
- Lakehouse: Bronze/Silver/Gold tables for stablecoin analytics

UI/UX parity:
- PWA: 11-tab stablecoin dashboard (on-ramp, off-ramp, swap, send, yield, bridge,
  P2P, bill pay, DCA, virtual card, history) with de-peg alerts
- Flutter: Full stablecoin screen with all 7 operations
- React Native: Full stablecoin screen with 7 tabs and modal picker

Tests: 50+ vitest assertions covering atomicity, DCA, auto-convert, P2P claims,
APISix routes, OpenSearch templates, Fluvio topics, Lakehouse tables, UI parity

Co-Authored-By: Patrick Munis <pmunis@gmail.com>
@munisp munisp self-assigned this Jun 23, 2026
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author
Original prompt from Patrick

https://drive.google.com/file/d/14K-94cZoOVgiYCUA-VympU-4_8IBqv2d/view?usp=sharing
extract the contents of the archive. List all the features of the platform

@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant