Commit e2c6a9a
fix(transaction-pay): allow perps withdraw to Arbitrum USDC by skipping same-token filter for HyperLiquid source (#8387)
## Explanation
When a user initiates a perps withdrawal targeting Arbitrum USDC, the
`calculatePostQuoteSourceAmounts` function filters out the source token
because it matches the destination token (both are Arbitrum USDC on
chain `0xa4b1`). This prevents any Relay quote requests from being
built, so `calculateTotals` falls back to computing raw gas cost on the
dummy Arbitrum transaction — producing an absurd ~$16M transaction fee.
The relay strategy's `normalizeRequest()` would have renormalized the
source from Arbitrum USDC to HyperCore USDC (chain `0x539`, 8 decimals),
making them distinct tokens. But this normalization happens downstream
of the source-amounts filter, so it never gets a chance to run.
Withdrawing to a different token (e.g. BNB) works fine because
`isSameToken` returns false, so the filter doesn't apply and the Relay
quote is fetched normally.
Fixes https://consensyssoftware.atlassian.net/browse/CONF-1150
## Changes
- Pass `isHyperliquidSource` from `transactionData` into
`calculatePostQuoteSourceAmounts`
- Bypass the `isSameToken` filter when `isHyperliquidSource` is true,
since the relay strategy will renormalize the source to HyperCore USDC
(a different chain)
- Add unit tests for the new behavior and confirm existing behavior is
preserved
## References
- Affected flow: Perps → Withdraw → Receive USDC (Arbitrum)
- Root cause: `isSameToken(ArbitrumUSDC, ArbitrumUSDC)` → `true` →
source amount filtered out → no quotes → fallback to raw transaction gas
cost
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Medium Risk**
> Adjusts post-quote source-amount filtering logic for
`isHyperliquidSource`, which affects whether Relay quotes are requested
and therefore impacts fee/quote calculation for withdrawals. Scoped
behind a specific flag, but regressions could alter quoting behavior for
post-quote flows.
>
> **Overview**
> Fixes HyperLiquid *post-quote (withdrawal)* flows where the source
token could be incorrectly dropped as “same as destination,” preventing
Relay quote requests and leading to wildly incorrect fee estimates.
>
> `updateSourceAmounts` now passes `transactionData.isHyperliquidSource`
into `calculatePostQuoteSourceAmounts`, which bypasses the
same-token/same-chain filter when that flag is true. Adds unit tests
covering the new HyperLiquid behavior and preserving the existing
same-token filtering when the flag is false, and records the fix in the
changelog.
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
fbcb2ee. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
---------
Signed-off-by: dan437 <80175477+dan437@users.noreply.github.com>1 parent 219f334 commit e2c6a9a
File tree
3 files changed
+70
-2
lines changed- packages/transaction-pay-controller
- src/utils
3 files changed
+70
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
14 | 18 | | |
15 | 19 | | |
16 | 20 | | |
| |||
Lines changed: 57 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
353 | 353 | | |
354 | 354 | | |
355 | 355 | | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
356 | 413 | | |
357 | 414 | | |
358 | 415 | | |
| |||
Lines changed: 9 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| 48 | + | |
48 | 49 | | |
49 | 50 | | |
50 | 51 | | |
51 | 52 | | |
| 53 | + | |
52 | 54 | | |
53 | 55 | | |
54 | 56 | | |
| |||
80 | 82 | | |
81 | 83 | | |
82 | 84 | | |
| 85 | + | |
83 | 86 | | |
84 | 87 | | |
85 | 88 | | |
86 | 89 | | |
87 | 90 | | |
88 | 91 | | |
| 92 | + | |
89 | 93 | | |
90 | 94 | | |
91 | 95 | | |
| |||
99 | 103 | | |
100 | 104 | | |
101 | 105 | | |
102 | | - | |
103 | | - | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
104 | 111 | | |
105 | 112 | | |
106 | 113 | | |
| |||
0 commit comments