Commit 82e9c02
authored
feat: TokenBalanceController architect handling unprocessed tokens (#8132)
<!-- CURSOR_AGENT_PR_BODY_BEGIN -->
## Explanation
* **What is the current state of things and why does it need to
change?**
Previously, the `AccountsApiBalanceFetcher` would zero out balances for
non-native tokens it couldn't retrieve. The `TokenBalancesController`
would then only pass on unsupported *chains* to subsequent fetchers.
This prevented the RPC balance fetcher from attempting to retrieve
balances for these "missed" tokens. Additionally,
`TokenDetectionController` had noisy `console.warn` logs for token
metadata cache misses.
* **What is the solution your changes offer and how does it work?**
This PR modifies the balance fetching flow to return "unprocessed
tokens" for non-native tokens that the `AccountsApiBalanceFetcher`
cannot process. These `unprocessedTokens` are then explicitly passed
through the `TokenBalancesController` to subsequent fetchers. The
`RpcBalanceFetcher` now accepts these `unprocessedTokens` and, when
provided, will only fetch balances for those specific tokens, avoiding
redundant work for native or staked tokens. The `console.warn` logs in
`TokenDetectionController` have also been removed.
* **Are there any changes whose purpose might not obvious to those
unfamiliar with the domain?**
The introduction of the `unprocessedTokens` parameter and its
propagation across fetchers is key. When `unprocessedTokens` are
present, the RPC fetcher operates in a targeted mode, only querying for
the specified ERC-20 tokens, rather than performing a full chain-wide
balance fetch.
* **If your primary goal was to update one package but you found you had
to update another one along the way, why did you do so?**
The change required modifications across `api-balance-fetcher`,
`TokenBalancesController`, and `rpc-balance-fetcher` to correctly
implement the "unprocessed tokens" handoff and fallback mechanism.
`TokenDetectionController` was updated to remove noisy logs as
requested.
Code Walkthrough:
https://www.loom.com/share/c38c5369dcb54d62908747078a899be9
* **If you had to upgrade a dependency, why did you do so?**
No dependency upgrades were required.
## References
* https://consensyssoftware.atlassian.net/browse/ASSETS-2871
## Checklist
- [x] I've updated the test suite for new or updated code as appropriate
- [ ] 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
---
<p><a
href="https://cursor.com/agents/bc-03398f4f-6aed-4e3f-a24a-cfe4b63b7946"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://cursor.com/assets/images/open-in-web-dark.png"><source
media="(prefers-color-scheme: light)"
srcset="https://cursor.com/assets/images/open-in-web-light.png"><img
alt="Open in Web" width="114" height="28"
src="https://cursor.com/assets/images/open-in-web-dark.png"></picture></a> <a
href="https://cursor.com/background-agent?bcId=bc-03398f4f-6aed-4e3f-a24a-cfe4b63b7946"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://cursor.com/assets/images/open-in-cursor-dark.png"><source
media="(prefers-color-scheme: light)"
srcset="https://cursor.com/assets/images/open-in-cursor-light.png"><img
alt="Open in Cursor" width="131" height="28"
src="https://cursor.com/assets/images/open-in-cursor-dark.png"></picture></a> </p>
<!-- CURSOR_AGENT_PR_BODY_END -->1 parent e3e7bab commit 82e9c02
File tree
10 files changed
+548
-190
lines changed- packages/assets-controllers
- src
- multi-chain-accounts-service
- rpc-service
10 files changed
+548
-190
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
440 | 440 | | |
441 | 441 | | |
442 | 442 | | |
443 | | - | |
444 | | - | |
445 | | - | |
446 | | - | |
447 | | - | |
448 | | - | |
449 | | - | |
450 | | - | |
451 | 443 | | |
452 | 444 | | |
453 | 445 | | |
| |||
476 | 468 | | |
477 | 469 | | |
478 | 470 | | |
479 | | - | |
480 | | - | |
481 | | - | |
482 | | - | |
483 | | - | |
484 | | - | |
485 | | - | |
486 | | - | |
487 | | - | |
488 | | - | |
489 | | - | |
490 | 471 | | |
491 | 472 | | |
492 | 473 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
| |||
Lines changed: 89 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
| |||
6680 | 6681 | | |
6681 | 6682 | | |
6682 | 6683 | | |
| 6684 | + | |
| 6685 | + | |
| 6686 | + | |
| 6687 | + | |
| 6688 | + | |
| 6689 | + | |
| 6690 | + | |
| 6691 | + | |
| 6692 | + | |
| 6693 | + | |
| 6694 | + | |
| 6695 | + | |
| 6696 | + | |
| 6697 | + | |
| 6698 | + | |
| 6699 | + | |
| 6700 | + | |
| 6701 | + | |
| 6702 | + | |
| 6703 | + | |
| 6704 | + | |
| 6705 | + | |
| 6706 | + | |
| 6707 | + | |
| 6708 | + | |
| 6709 | + | |
| 6710 | + | |
| 6711 | + | |
| 6712 | + | |
| 6713 | + | |
| 6714 | + | |
| 6715 | + | |
| 6716 | + | |
| 6717 | + | |
| 6718 | + | |
| 6719 | + | |
| 6720 | + | |
| 6721 | + | |
| 6722 | + | |
| 6723 | + | |
| 6724 | + | |
| 6725 | + | |
| 6726 | + | |
| 6727 | + | |
| 6728 | + | |
| 6729 | + | |
| 6730 | + | |
| 6731 | + | |
| 6732 | + | |
| 6733 | + | |
| 6734 | + | |
| 6735 | + | |
| 6736 | + | |
| 6737 | + | |
| 6738 | + | |
| 6739 | + | |
| 6740 | + | |
| 6741 | + | |
| 6742 | + | |
| 6743 | + | |
| 6744 | + | |
| 6745 | + | |
| 6746 | + | |
| 6747 | + | |
| 6748 | + | |
| 6749 | + | |
| 6750 | + | |
| 6751 | + | |
| 6752 | + | |
| 6753 | + | |
| 6754 | + | |
| 6755 | + | |
| 6756 | + | |
| 6757 | + | |
| 6758 | + | |
| 6759 | + | |
| 6760 | + | |
| 6761 | + | |
| 6762 | + | |
| 6763 | + | |
| 6764 | + | |
| 6765 | + | |
| 6766 | + | |
| 6767 | + | |
| 6768 | + | |
| 6769 | + | |
| 6770 | + | |
| 6771 | + | |
6683 | 6772 | | |
6684 | 6773 | | |
6685 | 6774 | | |
| |||
Lines changed: 80 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
| 69 | + | |
69 | 70 | | |
70 | 71 | | |
71 | 72 | | |
| |||
278 | 279 | | |
279 | 280 | | |
280 | 281 | | |
281 | | - | |
| 282 | + | |
282 | 283 | | |
283 | 284 | | |
284 | 285 | | |
| |||
348 | 349 | | |
349 | 350 | | |
350 | 351 | | |
351 | | - | |
352 | | - | |
353 | | - | |
354 | | - | |
355 | | - | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
356 | 367 | | |
357 | 368 | | |
358 | 369 | | |
| |||
818 | 829 | | |
819 | 830 | | |
820 | 831 | | |
| 832 | + | |
| 833 | + | |
821 | 834 | | |
822 | | - | |
| 835 | + | |
823 | 836 | | |
824 | 837 | | |
825 | 838 | | |
| |||
834 | 847 | | |
835 | 848 | | |
836 | 849 | | |
| 850 | + | |
837 | 851 | | |
838 | 852 | | |
| 853 | + | |
839 | 854 | | |
840 | 855 | | |
841 | 856 | | |
| |||
845 | 860 | | |
846 | 861 | | |
847 | 862 | | |
848 | | - | |
849 | | - | |
850 | | - | |
851 | | - | |
852 | | - | |
853 | | - | |
| 863 | + | |
| 864 | + | |
| 865 | + | |
| 866 | + | |
| 867 | + | |
| 868 | + | |
| 869 | + | |
| 870 | + | |
| 871 | + | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
| 877 | + | |
854 | 878 | | |
855 | | - | |
856 | 879 | | |
857 | 880 | | |
858 | 881 | | |
859 | | - | |
| 882 | + | |
860 | 883 | | |
861 | 884 | | |
862 | 885 | | |
863 | 886 | | |
864 | 887 | | |
865 | 888 | | |
| 889 | + | |
| 890 | + | |
| 891 | + | |
| 892 | + | |
| 893 | + | |
| 894 | + | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
| 901 | + | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
| 906 | + | |
| 907 | + | |
| 908 | + | |
| 909 | + | |
| 910 | + | |
| 911 | + | |
| 912 | + | |
| 913 | + | |
| 914 | + | |
| 915 | + | |
| 916 | + | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
| 925 | + | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
866 | 931 | | |
867 | 932 | | |
868 | 933 | | |
| |||
Lines changed: 1 addition & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3408 | 3408 | | |
3409 | 3409 | | |
3410 | 3410 | | |
3411 | | - | |
| 3411 | + | |
3412 | 3412 | | |
3413 | 3413 | | |
3414 | 3414 | | |
3415 | | - | |
3416 | | - | |
3417 | 3415 | | |
3418 | 3416 | | |
3419 | 3417 | | |
| |||
3434 | 3432 | | |
3435 | 3433 | | |
3436 | 3434 | | |
3437 | | - | |
3438 | | - | |
3439 | | - | |
3440 | | - | |
3441 | | - | |
3442 | 3435 | | |
3443 | 3436 | | |
3444 | 3437 | | |
3445 | 3438 | | |
3446 | 3439 | | |
3447 | 3440 | | |
3448 | | - | |
3449 | | - | |
3450 | 3441 | | |
3451 | 3442 | | |
3452 | 3443 | | |
| |||
Lines changed: 0 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
838 | 838 | | |
839 | 839 | | |
840 | 840 | | |
841 | | - | |
842 | | - | |
843 | | - | |
844 | 841 | | |
845 | 842 | | |
846 | 843 | | |
| |||
961 | 958 | | |
962 | 959 | | |
963 | 960 | | |
964 | | - | |
965 | | - | |
966 | | - | |
967 | 961 | | |
968 | 962 | | |
969 | 963 | | |
| |||
0 commit comments