Skip to content

feat: bridge reconciliation + USDT provisioning additions#354

Open
heyolaniran wants to merge 26 commits into
lnflash:tmp/bridge-rebase-pr-readyfrom
heyolaniran:feat/bridge-reconciliation
Open

feat: bridge reconciliation + USDT provisioning additions#354
heyolaniran wants to merge 26 commits into
lnflash:tmp/bridge-rebase-pr-readyfrom
heyolaniran:feat/bridge-reconciliation

Conversation

@heyolaniran
Copy link
Copy Markdown
Contributor

Summary

  • Ports 25 commits from feature/bridge-integration onto tmp/bridge-rebase-pr-ready
  • Adds Bridge↔IBEX deposit reconciliation (orphan tracking, PubSub, scheduled + CLI tooling, GraphQL exposure)
  • Adds USDT cash wallet provisioning for new accounts with VA idempotency guard
  • Fixes Ibex client operations (auth endpoint, USDT crypto receive webhook alignment, account creation, types)
  • Adds unit tests for reconciliation helpers and VA idempotency assertions
  • Adds KYC hosted-link return fix for incomplete KYC status

Conflict resolutions

All conflicts resolved keeping the tmp/bridge-rebase-pr-ready (HEAD) version for already-refactored code, and taking incoming changes for genuinely new functionality (e.g. usdtCashWallet guard before VA creation, currency parameter on balance reads).

Test plan

  • Unit tests: yarn test test/flash/unit/services/bridge/reconciliation.spec.ts
  • Unit tests: yarn test test/flash/unit/services/bridge/index.spec.ts
  • Integration: create virtual account flow still returns idempotent result on retry
  • Integration: USDT deposit webhook triggers reconcileByTxHash
  • GraphQL admin: bridgeReconciliationOrphans query returns orphan records

forge0x and others added 26 commits May 15, 2026 10:34
listByAccountId previously surfaced CouldNotListWalletsFromAccountIdError
when Mongo returned no rows; callers treat an empty list more naturally.
Ensures device-upgrade login, BTC wallet balance field, and on-chain send-all
query the correct Ibex account currency instead of relying on defaults.
Minors improvments in the creation of the Ibex address to link to the bridge card
this commit includes
- fix: how to get the accessToken after Ibex login
- feat: create an API call method to create the Ibex account for the flash account
- fix: how to get the crypto receive options from Ibex Api call
- feat: create an API call method to get the currency Id instead of hardcode it in USDT walletCurrency
- fix: the ethereum USDT option method
this commit includes :
- fix: Update the CryptoReceiveOption type
- feat: Add the IbexCurrency type for Ibex currency
- fix: update the cryptoReceiveInfo type
for usdt checking type wallet, the backend fetches the right currency Id from Ibex API call then create a new account with the API call method instead of the SDK
…o model

Track unmatched vs resolved orphans, resolvedAt, and indexes for
status and txHash queries. Extend the orphan service with
resolveOrphansByTxHash and findOrphans helpers.
Introduce BridgeReconciliationUpdate so matched and unmatched
reconciliation results can be broadcast to subscribers.
Use a 15-minute default window and payment_processed state for Bridge
deposits. Add reconcileByTxHash for on-demand matching, orphan
upserts, resolution of prior orphans on match, and PubSub events.
After persisting Bridge payment_processed with a destination tx hash,
or after IBEX crypto.receive handling, fire reconcileByTxHash in the
background with error logging only.
Add an admin bridgeReconciliationOrphans query with filtering, plus a
public bridgeReconciliation subscription backed by the new PubSub
trigger and typed payloads.
Pass an explicit window to the cron job and default the CLI script to
a quarter-hour window to match real-time webhook reconciliation.
Cover batch reconciliation behavior and reconcileByTxHash paths
including match, orphan creation, and PubSub publishing.
Describe batch versus real-time flows, orphan triage, and operational
entry points for operators.
Format Bridge reconciliation pubsub.publish calls for readability.
Without this, accountDetailsByUserPhone (and any admin query returning
wallets) throws INTERNAL_SERVER_ERROR on USDT wallet entries because the
admin GraphQL schema has no concrete type to resolve Wallet → UsdtWallet.
@bobodread876
Copy link
Copy Markdown
Collaborator

Build is broken: WalletType is used as a runtime value without importing it

Evidence:

  • src/services/bridge/index.ts:102, 108, 463 use WalletType.Checking

  • WalletType is only an ambient type unless imported from @domain/wallets

  • Validation: yarn tsc-check --pretty false under Node 20 reports:

    • src/services/bridge/index.ts(102,66): error TS2693: 'WalletType' only refers to a type, but is being used as a value here.
    • same at 108, 463

Impact:
The branch cannot typecheck/build as-is.

@bobodread876
Copy link
Copy Markdown
Collaborator

Full Review Feedback:

  1. TypeScript build fails

    • src/services/bridge/index.ts uses WalletType.Checking without importing WalletType.
    • Fix: add import { WalletType } from "@domain/wallets".
  2. Generated GraphQL schema is stale

    • New GraphQL fields are added in code but missing from generated SDL/supergraph files.
    • Missing fields:
      • bridgeReconciliation
      • bridgeReconciliationOrphans
  3. Security/privacy issue: public reconciliation subscription leaks global events

    • Any authenticated user can subscribe to all Bridge reconciliation events.
    • Leaks fields like txHash, customerId, amount, currency, and transferId.
  4. Targeted unit tests fail

    • test/flash/unit/services/bridge/index.spec.ts has 6 failing tests.
    • crypto-receive.spec.ts also fails due config/env loading through reconciliation imports.
  5. ESLint/prettier fails

    • Multiple formatting/lint failures across service and test files.
    • Includes console.log, any, prettier issues, and trailing whitespace.
  6. Reconciliation CLI default window is wrong

    • The docs/default say 15 minutes, but implementation floors 0.25 hours to 0, then clamps to 1.
    • Actual default becomes 1 hour, not 15 minutes.
  7. IBEX crypto receive lock uses the wrong semantic lock

    • crypto-receive.ts locks Ethereum tx_hash using lockPaymentHash.
    • Should use lockOnChainTxHash or a dedicated crypto/bridge tx lock helper.

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.

3 participants