Commit 7b49e02
authored
fix(transaction-pay-controller): use Infura endpoint for live token balance queries (#8839)
## Explanation
When querying a live on-chain token balance, the controller previously
resolved the network client using `findNetworkClientIdByChainId`, which
returns whatever endpoint is currently selected for that chain —
including custom RPC endpoints. Custom RPC endpoints may not support the
`pending` block tag used by these calls, causing the query to fail.
This change adds a preference for the chain's Infura endpoint when one
is configured, falling back to the existing
`findNetworkClientIdByChainId` behaviour if no Infura endpoint is
configured or if the lookup throws.
## References
<!--
Are there any issues that this pull request is tied to?
-->
## Checklist
- [x] I've updated the test suite for new or updated code as appropriate
- [x] I've updated documentation (JSDoc, Markdown, etc.) for new or
updated code as appropriate
- [x] I've communicated my changes to consumers by [updating changelogs
for packages I've
changed](https://github.com/MetaMask/core/tree/main/docs/processes/updating-changelogs.md)
- [ ] I've introduced [breaking
changes](https://github.com/MetaMask/core/tree/main/docs/processes/breaking-changes.md)
in this PR and have prepared draft pull requests for clients and
consumer packages to resolve them
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Medium Risk**
> Changes which RPC endpoint serves balance checks and on-chain amount
reads before Relay submit; wrong endpoint selection could block or
mis-validate pay deposits, though Infura preference falls back to the
default client.
>
> **Overview**
> Introduces shared **`provider` utilities** (`getNetworkClientId`,
`rpcRequest`) so chain RPC calls go through the controller messenger’s
`provider.request` instead of **ethers `Web3Provider` / `Contract`**.
>
> **Live token balances** (`getLiveTokenBalance`) now call
`eth_getBalance` / `eth_call` with the **`pending`** block tag and pass
**`preferInfura: true`**, picking the chain’s Infura `networkClientId`
when configured and otherwise using
`findNetworkClientIdByChainId`—addressing failures on custom RPCs that
don’t support pending queries.
>
> The same RPC helper path is used for **fiat source amount resolution**
and **transfer amount from tx hash** (receipt logs,
`debug_traceTransaction`, `eth_getTransactionByHash`). **Across**,
**Relay**, and **gas** estimation call sites switch to
`getNetworkClientId` for consistency.
>
> Messenger **`AllowedActions`** and test mocks register
**`NetworkController:getNetworkConfigurationByChainId`**. Changelog
documents the Infura preference for live balance queries.
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
4ca5364. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent 855ab80 commit 7b49e02
13 files changed
Lines changed: 615 additions & 225 deletions
File tree
- packages/transaction-pay-controller
- src
- strategy
- across
- fiat
- relay
- tests
- utils
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| |||
Lines changed: 2 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
| |||
141 | 142 | | |
142 | 143 | | |
143 | 144 | | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
| 145 | + | |
148 | 146 | | |
149 | 147 | | |
150 | 148 | | |
| |||
Lines changed: 18 additions & 30 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | 1 | | |
3 | 2 | | |
4 | 3 | | |
| |||
15 | 14 | | |
16 | 15 | | |
17 | 16 | | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | 17 | | |
24 | 18 | | |
25 | 19 | | |
| |||
210 | 204 | | |
211 | 205 | | |
212 | 206 | | |
| 207 | + | |
213 | 208 | | |
214 | 209 | | |
215 | 210 | | |
216 | 211 | | |
217 | 212 | | |
218 | | - | |
219 | | - | |
220 | | - | |
221 | | - | |
222 | 213 | | |
223 | 214 | | |
224 | 215 | | |
225 | | - | |
226 | | - | |
227 | | - | |
228 | | - | |
229 | 216 | | |
| 217 | + | |
230 | 218 | | |
231 | 219 | | |
232 | 220 | | |
| |||
255 | 243 | | |
256 | 244 | | |
257 | 245 | | |
258 | | - | |
259 | | - | |
260 | | - | |
261 | | - | |
262 | | - | |
263 | | - | |
264 | 246 | | |
265 | 247 | | |
266 | 248 | | |
267 | | - | |
| 249 | + | |
268 | 250 | | |
269 | 251 | | |
270 | 252 | | |
| |||
297 | 279 | | |
298 | 280 | | |
299 | 281 | | |
300 | | - | |
| 282 | + | |
301 | 283 | | |
302 | 284 | | |
303 | 285 | | |
304 | | - | |
| 286 | + | |
305 | 287 | | |
306 | 288 | | |
307 | 289 | | |
| |||
314 | 296 | | |
315 | 297 | | |
316 | 298 | | |
317 | | - | |
| 299 | + | |
318 | 300 | | |
319 | 301 | | |
320 | 302 | | |
| |||
327 | 309 | | |
328 | 310 | | |
329 | 311 | | |
330 | | - | |
| 312 | + | |
331 | 313 | | |
332 | 314 | | |
333 | 315 | | |
| |||
344 | 326 | | |
345 | 327 | | |
346 | 328 | | |
347 | | - | |
348 | | - | |
349 | | - | |
350 | | - | |
351 | | - | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
352 | 340 | | |
353 | 341 | | |
354 | 342 | | |
| |||
Lines changed: 3 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
| |||
508 | 509 | | |
509 | 510 | | |
510 | 511 | | |
511 | | - | |
512 | | - | |
513 | | - | |
514 | | - | |
| 512 | + | |
515 | 513 | | |
516 | 514 | | |
517 | 515 | | |
| |||
600 | 598 | | |
601 | 599 | | |
602 | 600 | | |
603 | | - | |
604 | | - | |
605 | | - | |
606 | | - | |
| 601 | + | |
607 | 602 | | |
608 | 603 | | |
609 | 604 | | |
| |||
Lines changed: 11 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| |||
117 | 118 | | |
118 | 119 | | |
119 | 120 | | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
120 | 125 | | |
121 | 126 | | |
122 | 127 | | |
| |||
255 | 260 | | |
256 | 261 | | |
257 | 262 | | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
258 | 268 | | |
259 | 269 | | |
260 | 270 | | |
| |||
321 | 331 | | |
322 | 332 | | |
323 | 333 | | |
| 334 | + | |
324 | 335 | | |
325 | 336 | | |
326 | 337 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| 34 | + | |
34 | 35 | | |
35 | 36 | | |
36 | 37 | | |
| |||
78 | 79 | | |
79 | 80 | | |
80 | 81 | | |
| 82 | + | |
81 | 83 | | |
82 | 84 | | |
83 | 85 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
227 | 228 | | |
228 | 229 | | |
229 | 230 | | |
230 | | - | |
231 | | - | |
232 | | - | |
233 | | - | |
| 231 | + | |
234 | 232 | | |
235 | 233 | | |
236 | 234 | | |
| |||
0 commit comments