Skip to content

fix(swap): instrument bridge quote after intent verification (#752) - #823

Merged
szhygulin merged 1 commit into
mainfrom
fix/752-bridge-instrument-reorder
Jul 26, 2026
Merged

fix(swap): instrument bridge quote after intent verification (#752)#823
szhygulin merged 1 commit into
mainfrom
fix/752-bridge-instrument-reorder

Conversation

@graciangabriel8

Copy link
Copy Markdown
Contributor

Closes #752

What changed and why

#752 item 2: instrumentBridgeQuote was called inside the swapClass === "bridge" branch of prepareSwap (src/modules/swap/index.ts), BEFORE verifyLifiBridgeIntent ran later in the same function. This contradicted design §4.2 step 6, whose own docstring on instrumentBridgeQuote already says it must "never sit before ... the existing bridge guards."

Effect of the bug: a bridge route that verifyLifiBridgeIntent later REFUSEs (destination-chain mismatch or non-wallet EVM receiver, #798) still got counted toward lifiBridgeSuspectedUnreachableCount before the throw. That counter is the exact metric PROD condition 2 uses to promote #745, so a REFUSEd route was inflating a promotion signal it should never touch.

Fix: moved the instrumentBridgeQuote call out of the pre-guard bridge branch to a new if (swapClass === "bridge") block placed immediately after verifyLifiBridgeIntent(args, txRequest.data), so it only runs once that guard has passed.

Scope

Only item 2 of #752 is addressed here. Items 1 (native-in LiFi topology sentinel — needs a live li.quest quote to verify) and 3 (commit real probe-output JSON) both need live network access unavailable to this authoring session; left as follow-up per the issue's own framing ("accept the residual" / "commit... probe output" are separable asks).

Falsifier test

Added test/swap-lifi-minout.test.tsdescribe("#752 — bridge instrumentation runs AFTER verifyLifiBridgeIntent"):

Tests were NOT run locally — Node/npm are not installed on the authoring machine. CI (Build & Test on Node 20 + 22) is the authoritative check for this PR. The test was written by close reading of the existing test file's mocks (fetchQuote mock, evmClientStub, makeBridgeQuote helper, bridgeArgs fixture) and matching its exact style/imports; no existing test's assertions were run to confirm.

Existing tests updated

None. The reorder doesn't change behavior for any bridge route that passes verifyLifiBridgeIntent (the existing T6 tests all use the default wallet-matching receiver and unaffected destinationChainId, so they still increment/don't-increment the counter exactly as before).

Blast radius

Single function (prepareSwap), bridge-class branch only. No change to generic-swap handling, no change to verifyLifiBridgeIntent itself, no change to instrumentBridgeQuote's own logic — only where it's called from. Diff is 51 lines across 2 files.

Residual concerns

  • Items 1 and 3 from chore(swap): #685/#746 follow-ups — native-in sentinel verify, bridge-instrument reorder, commit probe output #752 remain open (out of scope here, noted above).
  • This fix only closes the ordering gap; it doesn't add a regression test for the destination-chain-mismatch REFUSE path specifically (only the receiver-mismatch REFUSE path), since both throw from the same verifyLifiBridgeIntent call and the receiver-mismatch case avoids any INTERMEDIATE_CHAIN_BRIDGES interaction, making it the cleaner/more deterministic falsifier. Happy to add a second case if reviewers want both REFUSE paths covered explicitly.

instrumentBridgeQuote ran before verifyLifiBridgeIntent in the bridge
branch of prepareSwap, contradicting design §4.2 step 6. A bridge route
later REFUSEd by verifyLifiBridgeIntent (destination chain or receiver
mismatch) still incremented lifiBridgeSuspectedUnreachableCount, mildly
inflating the exact metric PROD condition 2 uses to promote #745.

Move the instrumentBridgeQuote call to after verifyLifiBridgeIntent,
still gated on swapClass === "bridge".
@szhygulin
szhygulin marked this pull request as ready for review July 26, 2026 08:04
@szhygulin
szhygulin merged commit 6ec3f60 into main Jul 26, 2026
3 checks passed
@szhygulin
szhygulin deleted the fix/752-bridge-instrument-reorder branch July 26, 2026 08:04
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 26, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

chore(swap): #685/#746 follow-ups — native-in sentinel verify, bridge-instrument reorder, commit probe output

2 participants