Repository navigation
fix(bridge): match a virtual-account deposit to its IBEX credit when Bridge reports it (ENG-891) - #546
Merged
Conversation
…Bridge reports it (ENG-891) The Bridge deposit route's real-time step only ran for transfer events; virtual-account deposits arrive as virtual_account.activity and skipped it, so they waited for the hourly matcher unless IBEX Hub's webhook came second. A virtual_account.activity payment_processed event with a tx hash now runs matchBridgeDepositNow, the hourly matcher's per-customer read and tx hash join for that one deposit, after the deposit row, audit row and event lock, without holding Bridge's response. It does not call reconcileByTxHash, which would file a false "no IBEX receive" orphan whenever Bridge's event beats IBEX's credit; recording the credit runs that reconcile itself. With IBEX Hub's webhook, whichever event comes second records the deposit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Gn2VCc25BAQjEu33uLycvP
…atch window in tests (ENG-891) Review fixes for the virtual-account real-time match. - WEBHOOKS.md (deposit.completed) and the recordIbexCryptoReceive docstring listed two recorders. They now name all three: the payment_processed event on the Bridge deposit route (via matchBridgeDepositNow) when IBEX has already credited, IBEX Hub's organization webhook when Bridge's event came first, and the hourly matcher for a delivery either one missed. The no_bridge_deposit comment says the Bridge deposit route picks up the first case, with the hourly matcher as backstop. - The window test only checked the read's account and sort, so it passed with CREDIT_LEAD_MS at 0 or at 7 days. It now matches a credit settled 14 minutes before Bridge's event and refuses one settled 16 minutes before; it fails with either of those values. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Gn2VCc25BAQjEu33uLycvP
bobodread876
approved these changes
Nov 20, 2026
bobodread876
left a comment
Collaborator
There was a problem hiding this comment.
Simon review clean after one fix round; CI green on b0c6ce8, deposit route and matcher specs run.
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.
What
When Bridge reports a virtual-account deposit
payment_processed, Flash records its IBEX credit at that moment, if IBEX has already made the credit. Recording means the ERPNext settle row, the deposit row Completed, and the user's notification. This is ENG-891, PR 3 of 3.Why
The deposit route's real-time step ran only for
event_category === "transfer". Virtual-account deposits arrive asvirtual_account.activity, with the state inevent_object.type, so they skipped it.Since #545, IBEX Hub's webhook records a deposit when IBEX reports the credit, but only if Bridge's deposit row already exists. IBEX usually settles a minute or two before Bridge's event lands. In that order the IBEX webhook finds no deposit row, and the deposit waited for the hourly matcher. This PR covers that order from the Bridge side.
How
matchBridgeDepositNow(src/app/bridge/match-ibex-deposits.ts) runs the hourly matcher's own per-customer logic for one deposit: account by Bridge customer, its USDT wallet, IBEX crypto receives settled from 15 minutes before the event, exact tx-hash join, thenrecordIbexCryptoReceive. It checks first whether the hash is already processed. It never throws and returns one ofrecorded,already_processed,no_ibex_creditorfailed.deposit.ts: avirtual_account.activityevent withtypepayment_processedand a tx hash (receipt.destination_tx_hash, elsedestination.tx_hash, as the deposit row stores it) calls it. The call happens:reconcileByTxHashfor these events. It would file abridge_without_ibexorphan and alert whenever Bridge's event beats IBEX's credit. Recording the credit already runs that reconcile, and the hourly deposit check flags real orphans after 6 hours.Ordering, after this PR
Every path goes through
recordIbexCryptoReceive. It locks on the hash and skips a processed receive, so the user is notified once.Tests
deposit.spec.ts:payment_processedevent matches with the right transfer, customer and hash;reconcileByTxHashcall;funds_received,payment_submittedand an event with no hash do not match;match-ibex-deposits.spec.ts(matchBridgeDepositNow):no_ibex_creditwhen IBEX has nothing yet;app/bridgeandservices/bridge, all passing;tscshows only the two existing localgraphql*-server.tserrors.Not tested: a real Bridge virtual-account event. The next real deposit on production is the proof.
🤖 Generated with Claude Code
https://claude.ai/code/session_01Gn2VCc25BAQjEu33uLycvP