Repository navigation
feat(wallet): add @metamask/assets-controllers to the default initialization configurations - #11315
dawnseeker8 wants to merge 24 commits into
Conversation
… into init Constructors of TokensController, TokenBalancesController, TokenDetectionController, TokenRatesController, AccountTrackerController, NftController, MultichainBalancesController, MultichainAssetsRatesController and MultichainAssetsController no longer call other controllers or start background work. The work moves to a new idempotent init method. TokenListController gains init, which calls initialize once. NftController exposes addNfts through its messenger, and TokensController falls back to the selected network client's provider. Co-authored-by: Xiaoming Wang <dawnseeker8@users.noreply.github.com>
Co-authored-by: Xiaoming Wang <dawnseeker8@users.noreply.github.com>
…gurations Adds the 16 messenger-based @metamask/assets-controllers controllers to the wallet's default initialization configurations. Each configuration delegates the actions and events its controller's messenger declares, builds callback options from messenger calls so construction order does not matter, and defaults the token prices and token list services. Wallet.init() runs the controllers' init methods. Co-authored-by: Xiaoming Wang <dawnseeker8@users.noreply.github.com>
Co-authored-by: Xiaoming Wang <dawnseeker8@users.noreply.github.com>
The Check Changelog workflow requires Unreleased entries to reference this pull request. Co-authored-by: Cursor <cursoragent@cursor.com>
Keep the assets-controllers entries for this pull request in Unreleased. The merge had placed them under the released 113.2.0 section. Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
|
@metamaskbot publish-preview |
|
Preview builds have been published. Learn how to use preview builds in other projects. Expand for full list of packages and versions. |
…controllers-draft-1943 Co-authored-by: Xiaoming Wang <dawnseeker8@users.noreply.github.com> # Conflicts: # packages/assets-controllers/CHANGELOG.md
TokenRatesController applies native asset identifiers from later NetworkEnablementController updates, and TokenDetectionController reads useTokenDetection again when it is still unset at detection time. Co-authored-by: Xiaoming Wang <dawnseeker8@users.noreply.github.com>
Bump the wallet's @metamask/assets-controllers range to ^113.3.0 so yarn install --immutable passes, and move this PR's changelog entries out of the released 113.3.0 section back to Unreleased. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@metamaskbot publish-preview |
|
Preview builds have been published. Learn how to use preview builds in other projects. Expand for full list of packages and versions. |
Keep this branch's unreleased changelog entries and main's released 113.3.1 and 21.0.1 sections. Point @metamask/wallet at @metamask/assets-controllers ^113.3.1 so the workspace range matches the released package. Co-authored-by: Xiaoming Wang <dawnseeker8@users.noreply.github.com>
…controllers-draft-1943 Co-authored-by: Xiaoming Wang <dawnseeker8@users.noreply.github.com> # Conflicts: # packages/assets-controllers/CHANGELOG.md # packages/wallet/CHANGELOG.md
…controllers-draft-1943 Co-authored-by: Xiaoming Wang <dawnseeker8@users.noreply.github.com>
…er is registered The first re-scan runs during init, before a client may have registered PhishingController. Retry that miss every minute, then return to the configured interval once bulkScanTokens can be called. Co-authored-by: Xiaoming Wang <dawnseeker8@users.noreply.github.com>
…controllers-draft-1943 Keep this branch's unreleased assets-controllers entries and main's profile-sync-controller bump to ^36.1.1. Co-authored-by: Xiaoming Wang <dawnseeker8@users.noreply.github.com> # Conflicts: # packages/assets-controllers/CHANGELOG.md
Prithpal-Sooriya
left a comment
There was a problem hiding this comment.
LGTM! Most of the legacy AssetControllers will be removed, but we can do this as a separate task - nice work!
Do we want to refrain from adding them to |
…controllers-draft-1943 Co-authored-by: Xiaoming Wang <dawnseeker8@users.noreply.github.com> # Conflicts: # packages/assets-controllers/CHANGELOG.md
hi, @FrederikBolding , @Prithpal-Sooriya mentioned that since we are still in the middle of moving |
|
Hey @FrederikBolding @dawnseeker8 I'd say most of these controllers have been deprecated, but there are some that we will keep and not remove anytime soon - NFTController and Deficontroller. I think I agree, if we want, we can fully remove all these other controllers that aren't being used (e.g. CurrencyRateController, TokensController, etc), but we're also making sure that both mobile and extension clients have fully stopped using them (https://consensyssoftware.atlassian.net/browse/ASSETS-4135 // https://consensyssoftware.atlassian.net/browse/ASSETS-4141) |
…controllers-draft-1943 Co-authored-by: Xiaoming Wang <dawnseeker8@users.noreply.github.com> # Conflicts: # packages/assets-controllers/CHANGELOG.md # packages/wallet/CHANGELOG.md
🛑 Files requiring codeowner reviewTo merge this PR, you'll need to get approvals from the following owners. @MetaMask/core-platform (27 files)
@MetaMask/metamask-assets (23 files)
@MetaMask/core-platform (expand for more) |
…controllers-draft-1943 Co-authored-by: Xiaoming Wang <dawnseeker8@users.noreply.github.com> # Conflicts: # packages/assets-controllers/CHANGELOG.md # packages/wallet/CHANGELOG.md
…controllers-draft-1943 Co-authored-by: Xiaoming Wang <dawnseeker8@users.noreply.github.com>
MultichainBalancesController.init and TokensController.init awaited the initial non-EVM balance fetch and token-list enrichment. Those used to run fire-and-forget from the constructor, so a hung snap or token-list request kept Wallet.init() from settling. Start both in the background again, and keep logging or swallowing their failures. Co-authored-by: Xiaoming Wang <dawnseeker8@users.noreply.github.com>
…controllers-draft-1943 Co-authored-by: Xiaoming Wang <dawnseeker8@users.noreply.github.com>
…troller init test The init-pending test returned partial MultichainAssetsController and KeyringController states, which lint:tsc:check rejected. Co-authored-by: Xiaoming Wang <dawnseeker8@users.noreply.github.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ 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 f47b033. Configure here.
| removeNft: (...args) => | ||
| messenger.call('NftController:removeNft', ...args), | ||
| getNftState: () => messenger.call('NftController:getState'), | ||
| }), |
There was a problem hiding this comment.
NFT detection ignores persisted preference
Medium Severity
NftDetectionController is constructed with disabled: false and never reads PreferencesController:getState. #disabled is only updated from PreferencesController:stateChange, which is not replayed to existing subscribers. A persisted useNftDetection: false therefore never applies, so detectNfts keeps running until that preference changes.
Reviewed by Cursor Bugbot for commit f47b033. Configure here.


Explanation
@metamask/walletdoes not yet construct any of the legacy@metamask/assets-controllerscontrollers. Hosts construct them, and several constructors call other controllers immediately (AccountsController:getSelectedAccount,KeyringController:getState,TokensController:getState,NetworkController:getNetworkClientById, and others) or start async work. So the host has to construct them in a specific order, after their dependencies.This PR does two things, one commit each.
1.
@metamask/assets-controllers: constructors no longer call other controllers.The constructors of
TokensController,TokenBalancesController,TokenDetectionController,TokenRatesController,AccountTrackerController,NftController,MultichainBalancesController,MultichainAssetsRatesControllerandMultichainAssetsControllernow only register handlers and subscribe to events.accountsByChainId), move to a new idempotentinit()method.init()returns early when the controller is deprecated.TokenListControllergainsinit(), which callsinitialize()once.TokenDetectionController.init()reports a missingPreferencesControllerthroughmessenger.captureExceptioninstead of throwing. The nextPreferencesController:stateChangefills in the value.NftControllerexposesaddNftsthrough its messenger.TokensController'sproviderandchainIdare now optional. Without a provider it uses the selected network client's provider (new allowed actionNetworkController:getSelectedNetworkClient).Every changed controller has a test that constructs it on a messenger with no handlers registered, plus an idempotency test. Existing tests that relied on constructor side effects now call
init().2.
@metamask/wallet: the 16 messenger-based controllers become defaults.The configurations live in
src/initialization/instances/assets-controllers/, one file per controller in one folder, aspermission-controller/does. The codeowners script allows oneinitializationPathper package.getMessengerdelegates exactly the external actions and events the controller's messenger type declares. That includes controllers the client registers (PreferencesController,SnapController,PhishingController,AccountTreeController,AuthenticationController,AccountActivityService).AccountTrackerController.getStakedBalanceForChainandTokenDetectionController.getBalancesInSingleCallcallAssetsContractController.NftDetectionController.addNfts,removeNftandgetNftStatecallNftController.instanceOptions:CodefiTokenPricesServiceV2fortokenPricesService.TokenListServicefortokenListService.chainId.trackMetaMetricsEvent.NftDetectionControllerdisabled: falseandRatesControllerincludeUsdRate: false.Wallet.init()already callsinit()on every instance that has one, so it now starts the assets controllers too. Polling is still started by the client.DeFiPositionsControllerV2is not included. It is newer, not in the ticket's scope, and can be added separately.Notes for reviewers
PreferencesControllerdependency appears at runtime, not at construction.AccountTrackerController.refresh(triggered byAccountsController:selectedEvmAccountChangeandNetworkController:networkAdded) callsPreferencesController:getStatewithout a guard. Hosts already registerPreferencesControllerbefore unlocking, soWallet.test.tsnow registers a stub for it in the tests that unlock or import an SRP. The wallet changelog calls this out.wallet.init()still has one rejected result,MultichainNetworkController:getStatefromNetworkEnablementController. It was already there before this PR and comes from another controller the wallet doesn't construct.assets-controllers.test.ts. It mocks@metamask/assets-controllerswith subclasses that record their constructor options, so the forwarded options, default services and messenger-backed callbacks can be checked directly. The instances are still real controllers.References
AssetsControllerin the wallet), but starts the deferred work fromWallet.init()instead of on the first UI open.@metamask/assets-controllersto the default initialization configurations #11314, which is ready for review oncursor/wallet-assets-controllers-1943.Checklist
Note
High Risk
Breaking constructor/init contract across many asset controllers plus wallet default registration that can collide with existing host setup and relies on runtime preferences and phishing services.
Reviewed by Cursor Bugbot for commit f47b033. Bugbot is set up for automated code reviews on this repo. Configure here.