Skip to content

feat: Fund flow audit — fix all critical/high/medium gaps (Go/Rust/Python/TS)#36

Merged
munisp merged 1 commit into
production-hardenedfrom
devin/1781981843-fund-flow-audit
Jun 20, 2026
Merged

feat: Fund flow audit — fix all critical/high/medium gaps (Go/Rust/Python/TS)#36
munisp merged 1 commit into
production-hardenedfrom
devin/1781981843-fund-flow-audit

Conversation

@devin-ai-integration

Copy link
Copy Markdown
Contributor

Summary

Comprehensive fund flow audit across 485+ routers identified 15 gaps where money moves without proper accounting, events, or idempotency. All fixed across TypeScript, Go, Rust, and Python.

CRITICAL fixes (9 production-blocking issues)

Race conditioncashIn/cashOut balance read was OUTSIDE the transaction. Now uses SELECT ... FROM agents WHERE id = $1 FOR UPDATE inside withTransaction() to prevent concurrent overdraw.

Missing GL journal entries — 6 routers moved money without double-entry:

  • chargebackManagement: GL reversal on refund (Debit 5001 Chargeback Expense → Credit 1001 Cash)
  • disputeRefund: GL reversal on refund (Debit 5002 Refund Expense → Credit 1001 Cash)
  • reversalApproval/transactionReversalManager: GL reversal + balance restoration on approve
  • ecommerceOrders: GL reversal on refund/cancel status
  • crossBorderRemittance.send: Was only creating audit log — now debits float, creates GL entries (Debit 3001 Remittance Payable → Credit 2001 Agent Float), checks CBN limits, publishes Kafka events

Wrong table querymultiCurrencyExchange.convert was querying agentPushSubscriptions instead of doing FX conversion. Completely rewritten with 15 currencies (NGN/USD/EUR/GBP/GHS/XOF/KES/ZAR/EGP/USDT/USDC/TZS/UGX/RWF/ZMW), 48 bidirectional corridors, FOR UPDATE locking, GL double-entry, and Kafka events.

BNPL repaymentbnplEngine had zero repayment flow. Added processRepayment mutation (FOR UPDATE → debit float → GL entry → late penalty calculation → Kafka event) and collectOverdue batch processor.

HIGH fixes

  • airtimeVending, billPayments, splitPayments: Added publishEvent() Kafka domain events
  • floatTopUp, merchantPayments, recurringPayments: Added idempotencyKey input + withIdempotency() wrapping + Kafka events

MEDIUM fixes

  • savingsProducts: Added calculateInterest (compound interest with daily/monthly/quarterly/annual compounding) and accrueInterest mutation with GL entries. Replaced hardcoded stub responses with real DB queries.

Polyglot microservices

Service Language Port Capabilities
fund-flow-engine Go 8250 BNPL repayment (serializable tx), FX conversion (GL + spread), reversal execution, GL reconciliation
fund-flow-settlement Rust 8251 BNPL installment scheduling (amortization), FX rate engine (16 corridors, spread calc), reconciliation
fund-flow-analytics Python 8252 BNPL portfolio analytics, credit risk scoring (0-1000), FX forecasting (SMA/EMA), reversal fraud detection, anomaly detection (z-score)

Test impact

  • 0 new TypeScript errors (6 pre-existing: react-i18next/@dnd-kit type declarations)
  • 4,241 tests pass, 5 fail (4 pre-existing db-performance/critical-flows, 1 expected: sprint46 multi-currency test expects activePairs: 42 from old hardcoded stub — now dynamically computed as 48 due to expanded corridor coverage)
  • Go: go vet passes
  • Python: py_compile passes

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

…t/Python

CRITICAL fixes:
- cashIn/cashOut: FOR UPDATE locking to prevent race conditions on float balance
- cashIn/cashOut: Kafka event publishing for domain events
- chargebackManagement: GL reversal entries on refund resolution
- disputeRefund: GL double-entry for refund processing
- transactionReversalManager: executeReversal mutation with GL reversals
- reversalApproval: approve mutation with GL reversal + balance restoration
- ecommerceOrders: GL reversal on refund/cancel status
- crossBorderRemittance.send: complete money movement (CBN limits, FOR UPDATE,
  GL entries, idempotency, Kafka events)
- multiCurrencyExchange.convert: fixed wrong table query (was querying
  agentPushSubscriptions), implemented real FX conversion with 15 currencies,
  48 corridors, GL double-entry
- bnplEngine: processRepayment mutation with FOR UPDATE, GL entries,
  late penalty calculation, collectOverdue batch processing

HIGH fixes:
- airtimeVending: Kafka event publishing on vend
- billPayments: Kafka event publishing on payment
- splitPayments: Kafka event publishing on split
- floatTopUp: idempotencyKey support
- merchantPayments: idempotencyKey + Kafka events
- recurringPayments: idempotencyKey + Kafka events

MEDIUM fixes:
- savingsProducts: compound interest calculation (daily/monthly/quarterly/annual),
  interest accrual mutation with GL entries, real DB queries replacing stubs

Polyglot microservices:
- Go: fund-flow-engine (BNPL repayment, FX conversion, reversal execution,
  GL reconciliation) - port 8250
- Rust: fund-flow-settlement (BNPL installment scheduling with amortization,
  FX rate engine with spread, GL reconciliation) - port 8251
- Python: fund-flow-analytics (BNPL portfolio analytics, credit risk scoring,
  FX rate forecasting, reversal fraud detection, anomaly detection) - port 8252

Co-Authored-By: Patrick Munis <pmunis@gmail.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author
Original prompt from Patrick

https://drive.google.com/file/d/1ko3y7OBp1tJIXGTbe2QGFRHMQfxMTWHX/view?usp=sharing

  1. Extract ALL everything in the archive
  2. how do ensure and assess that features for example domain and business logic/rules/requirements are fully impemented and production ready and complete - can you thoroughly assess each files and features to determine there are ready for production
  1. Database integration (replace in-memory with real Postgres)
  2. Inter-service HTTP wiring with retries/circuit breakers
  3. Security hardening (JWT everywhere, remove hardcoded creds, mTLS)
  4. Integration tests for critical flows
  5. Graceful shutdown, observability, alerting
    3)search for orphan, partially and generic scaffolded features across the platform - fully implement them end to end -generic CRUD-only patterns , modules with no domain logic, disconnected features, and incomplete implementations.

@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