chore: decouple controllers from tokens list#8700
Conversation
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
There are 2 total unresolved issues (including 1 from previous review).
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit d483965. Configure here.
| "@metamask/storage-service": "^1.0.1", | ||
| "@metamask/transaction-controller": "^65.1.0", | ||
| "@metamask/utils": "^11.9.0", | ||
| "@tanstack/query-core": "^5.62.16", |
There was a problem hiding this comment.
you will have a lavamoat validation if you do this , you should have policies approval
|
@cursor give me a description for this PR |
|
I can see from the GitHub context that this PR is about decoupling controllers from the tokens list. Since I cannot update the PR description directly, here's a comprehensive description you can use: ExplanationThis PR decouples the
Key ChangesNew
|



Explanation
This PR decouples the
TokenDetectionControllerandTokensControllerfrom theTokenListControllerby introducing a new sharedTokenListService. This architectural improvement provides:TokenListControllerstate/messagingKey Changes
New
TokenListServiceTokenListServiceclass andbuildTokenListMaputility function@tanstack/query-coreas a new dependencyBreaking Changes to Controllers
TokenDetectionController: Now requirestokenListServicein constructor optionsTokensController: Now requirestokenListServicein constructor optionsTokenListControllermessaging systemTokenDetectionControllerno longer automatically restarts detection onTokenListController:stateChangeToken Detection Improvements
Token Enrichment Changes
TokensControllerswitches from reactive events to one-time async enrichment at initializationPromise.allSettledfor resiliencenameandrwaDataenriched once during initialization vs. on every state changeTesting Updates
TokenListServiceunit testsNote: This introduces breaking changes requiring constructor updates for both controllers. Consumers will need to provide the new
tokenListServicedependency.References
Mobile: MetaMask/metamask-mobile#29743
Jira: https://consensyssoftware.atlassian.net/browse/ASSETS-3091
Checklist
Note
Medium Risk
Introduces a new shared caching layer and changes
TokenDetectionController/TokensControllerconstruction and runtime behavior, which can impact token discovery/enrichment if consumers don’t wiretokenListServicecorrectly or if cache/normalization assumptions differ across chains.Overview
Adds a new
TokenListService(TanStack Query-backed) to fetch + cache per-chain token lists in-memory for 4 hours, exporting bothTokenListServiceandbuildTokenListMap, and adds@tanstack/query-coreas a direct dependency.BREAKING:
TokenDetectionControllerandTokensControllernow require atokenListServiceconstructor option and no longer depend onTokenListControlleractions/events; token detection now pulls fresh token-list snapshots per chain from the service (with lowercase-key normalization and graceful early-return on fetch failures) and no longer restarts onTokenListController:stateChange.Changes token metadata enrichment in
TokensControllerfrom reactive updates on token-list state changes to a one-time async initialization pass (multi-chain,Promise.allSettled) that fillsname/rwaData, and updates tests/changelog accordingly (including newTokenListServiceunit tests and expanded mUSD/detection guard coverage).Reviewed by Cursor Bugbot for commit c67b9ef. Bugbot is set up for automated code reviews on this repo. Configure here.