Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
c1e6850
feat(assets-controllers): move constructor reads of other controllers…
cursoragent Nov 5, 2026
03be254
test(assets-controllers): cast mocked network clients through unknown
cursoragent Nov 5, 2026
a6abb55
feat(wallet): add assets-controllers controllers to the default confi…
cursoragent Nov 5, 2026
ea8cfb0
chore: link changelog entries to #11314
cursoragent Nov 5, 2026
6d9a733
chore: link changelog entries to #11315
dawnseeker8 Nov 9, 2026
b10687b
Merge branch 'main' into cursor/wallet-assets-controllers-draft-1943
dawnseeker8 Nov 9, 2026
1f8da61
fix: update yarn.lock for assets-controllers ^113.1.1 range
dawnseeker8 Nov 9, 2026
06c1d7a
fix(wallet): align assets-controllers range with constraints
dawnseeker8 Nov 9, 2026
c2e334c
Merge remote-tracking branch 'origin/main' into cursor/wallet-assets-…
cursoragent Nov 9, 2026
0d9a3a6
fix(assets-controllers): keep rates and detection current after init
cursoragent Nov 9, 2026
76c8763
Merge remote-tracking branch 'origin/main' into HEAD
dawnseeker8 Nov 9, 2026
a553ac6
fix: align with assets-controllers 113.3.0 release
dawnseeker8 Nov 9, 2026
8f16093
Merge origin/main into cursor/wallet-assets-controllers-draft-1943
cursoragent Nov 9, 2026
c098a48
Merge remote-tracking branch 'origin/main' into cursor/wallet-assets-…
cursoragent Nov 10, 2026
4181e77
Merge remote-tracking branch 'origin/main' into cursor/wallet-assets-…
cursoragent Nov 10, 2026
e14ff6a
fix(assets-controllers): retry Blockaid rescan until PhishingControll…
cursoragent Nov 10, 2026
c9f3663
Merge remote-tracking branch 'origin/main' into cursor/wallet-assets-…
cursoragent Nov 11, 2026
add3e2d
Merge remote-tracking branch 'origin/main' into cursor/wallet-assets-…
cursoragent Nov 11, 2026
fd8639e
Merge remote-tracking branch 'origin/main' into cursor/wallet-assets-…
cursoragent Nov 16, 2026
3570dd5
Merge remote-tracking branch 'origin/main' into cursor/wallet-assets-…
cursoragent Nov 17, 2026
85eee2a
Merge remote-tracking branch 'origin/main' into cursor/wallet-assets-…
cursoragent Nov 18, 2026
07a9bac
fix(assets-controllers): do not block init on background fetches
cursoragent Nov 18, 2026
c89bfa0
Merge remote-tracking branch 'origin/main' into cursor/wallet-assets-…
cursoragent Nov 19, 2026
f47b033
fix(assets-controllers): satisfy state types in MultichainBalancesCon…
cursoragent Nov 19, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -913,6 +913,7 @@
/packages/wallet/src/initialization/instances/accounts-controller/ @MetaMask/accounts-engineers
/packages/wallet/src/initialization/instances/address-book-controller/ @MetaMask/confirmations
/packages/wallet/src/initialization/instances/approval-controller/ @MetaMask/confirmations
/packages/wallet/src/initialization/instances/assets-controllers/ @MetaMask/metamask-assets
/packages/wallet/src/initialization/instances/claims-controller/ @MetaMask/web3auth
/packages/wallet/src/initialization/instances/claims-service/ @MetaMask/web3auth
/packages/wallet/src/initialization/instances/client-controller/ @MetaMask/core-platform @MetaMask/extension-platform @MetaMask/mobile-platform
Expand Down
1 change: 1 addition & 0 deletions codeowners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const config = {
},
'assets-controllers': {
teams: ['@MetaMask/metamask-assets'],
initializationPath: 'assets-controllers',
},
'authenticated-user-storage': {
teams: ['@MetaMask/auth-engineers'],
Expand Down
32 changes: 31 additions & 1 deletion packages/assets-controllers/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,31 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed
### Added

- Add `init` method to `TokensController`, `TokenBalancesController`, `TokenDetectionController`, `TokenRatesController`, `AccountTrackerController`, `NftController`, `MultichainBalancesController`, `MultichainAssetsRatesController`, `MultichainAssetsController` and `TokenListController` ([#11315](https://github.com/MetaMask/core/pull/11315))
- `init` reads the other controllers that the constructor used to read. Calling it more than once has no effect.
- `TokenListController.init` calls `initialize` once.
- Expose `addNfts` through the `NftController` messenger ([#11315](https://github.com/MetaMask/core/pull/11315))

### Changed

- **BREAKING:** The constructors of `TokensController`, `TokenBalancesController`, `TokenDetectionController`, `TokenRatesController`, `AccountTrackerController`, `NftController`, `MultichainBalancesController`, `MultichainAssetsRatesController` and `MultichainAssetsController` no longer call other controllers or start background work, so they can be constructed in any order ([#11315](https://github.com/MetaMask/core/pull/11315))
- Call `init` on each of them once the controllers they read from are registered. Until then:
- `TokensController` does not enrich persisted tokens from the token list, and reads the selected account on demand.
- `TokenBalancesController`, `TokenDetectionController` and `AccountTrackerController` treat the keyring as locked, and `TokenBalancesController` knows of no tokens.
- `TokenRatesController` knows of no tokens and does not pass native asset identifiers to the token prices service. After `init`, identifiers that `NetworkEnablementController` fills or changes are passed to the token prices service on `NetworkEnablementController:stateChange` and again before each rate lookup.
- `AccountTrackerController` starts with an empty `accountsByChainId`; `init` adds an empty entry for the selected network's chain when no `accountsByChainId` state was provided.
- `NftController` reads the selected account on demand.
- `MultichainBalancesController` does not fetch the initial non-EVM balances.
- `MultichainAssetsRatesController` uses `usd` as the current currency.
- `MultichainAssetsController` does not start the periodic Blockaid re-scan.
- `TokenDetectionController.init` reports a failure to read `PreferencesController:getState` through `messenger.captureException` instead of throwing. The preference stays unset after a failed read and is read again the next time detection runs. While it is still unset, non-mainnet detection is skipped and mainnet uses the static token list. `PreferencesController:stateChange` also updates the preference.
- **BREAKING:** `TokensControllerMessenger` must allow the `NetworkController:getSelectedNetworkClient` action ([#11315](https://github.com/MetaMask/core/pull/11315))
- **BREAKING:** `TokenRatesControllerMessenger` must allow the `NetworkEnablementController:stateChange` event ([#11315](https://github.com/MetaMask/core/pull/11315))
- The controller subscribes to it and passes updated `nativeAssetIdentifiers` to the token prices service. It also re-reads them before each rate lookup.
- `TokensController` no longer requires the `chainId` and `provider` options ([#11315](https://github.com/MetaMask/core/pull/11315))
- When `provider` is omitted, the provider of the selected network client (`NetworkController:getSelectedNetworkClient`) is used.
- Bump `@metamask/transaction-controller` from `^74.0.0` to `^74.2.0` ([#11579](https://github.com/MetaMask/core/pull/11579), [#11605](https://github.com/MetaMask/core/pull/11605))
- Bump `@metamask/keyring-controller` from `^28.2.0` to `^28.2.2` ([#11474](https://github.com/MetaMask/core/pull/11474), [#11537](https://github.com/MetaMask/core/pull/11537))
- Bump `@metamask/profile-sync-controller` from `^36.1.1` to `^36.1.2` ([#11474](https://github.com/MetaMask/core/pull/11474))
Expand All @@ -20,6 +43,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Remove Blast Mainnet (`0x13e31`) from the Multicall3 address map and `SPOT_PRICES_SUPPORT_INFO`, as the network is being terminated ([#11598](https://github.com/MetaMask/core/pull/11598))

### Fixed

- `TokenRatesController` applies `nativeAssetIdentifiers` that `NetworkEnablementController` fills or updates after `init`, so CAIP-19 native token rate lookups are not left on the map captured during `init` ([#11315](https://github.com/MetaMask/core/pull/11315))
- `TokenDetectionController` reads `useTokenDetection` again when detection runs if that preference is still unset, so a `PreferencesController` registered after `init` does not leave non-mainnet detection skipped ([#11315](https://github.com/MetaMask/core/pull/11315))
- `MultichainAssetsController` retries the Blockaid re-scan every minute when `PhishingController:bulkScanTokens` is not registered yet, then returns to the configured interval after that action can be called ([#11315](https://github.com/MetaMask/core/pull/11315))
- The first missing handler is reported through `messenger.captureException`. Stored tokens stay unchanged until a scan reaches `PhishingController`. A scan that reaches the controller and fails stays on the configured interval.

## [113.3.2]

### Changed
Expand Down
109 changes: 109 additions & 0 deletions packages/assets-controllers/src/AccountTrackerController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import type {
NetworkClientId,
NetworkClientConfiguration,
NetworkConfiguration,
NetworkControllerGetNetworkClientByIdAction,
NetworkControllerGetStateAction,
} from '@metamask/network-controller';
import { getDefaultPreferencesState } from '@metamask/preferences-controller';
import { TransactionStatus } from '@metamask/transaction-controller';
Expand Down Expand Up @@ -139,6 +141,112 @@ describe('AccountTrackerController', () => {
);
});

describe('construction and init', () => {
it('does not call other controllers when constructed', () => {
const messenger: AccountTrackerControllerMessenger = new Messenger({
namespace: 'AccountTrackerController',
});
const call = vi.spyOn(messenger, 'call');

const controller = new AccountTrackerController({
messenger,
getStakedBalanceForChain: vi.fn(),
});

expect(controller.state).toStrictEqual({ accountsByChainId: {} });
expect(controller.isActive).toBe(false);
expect(call).not.toHaveBeenCalled();
});

it('does not add the selected chain in init when accountsByChainId state is provided', async () => {
await withController(
{
options: {
state: { accountsByChainId: { '0x89': {} } },
},
},
({ controller }) => {
expect(controller.state).toStrictEqual({
accountsByChainId: { '0x89': {} },
});
},
);
});

it('keeps an entry for the selected chain that was added before init', () => {
const rootMessenger: RootMessenger = new Messenger({
namespace: MOCK_ANY_NAMESPACE,
});
const messenger: AccountTrackerControllerMessenger = new Messenger({
namespace: 'AccountTrackerController',
parent: rootMessenger,
});
rootMessenger.delegate({
messenger,
actions: [
'KeyringController:getState',
'NetworkController:getState',
'NetworkController:getNetworkClientById',
],
});
rootMessenger.registerActionHandler('KeyringController:getState', () => ({
isUnlocked: true,
keyrings: [],
}));
rootMessenger.registerActionHandler(
'NetworkController:getState',
() =>
({ selectedNetworkClientId: 'mainnet' }) as ReturnType<
NetworkControllerGetStateAction['handler']
>,
);
rootMessenger.registerActionHandler(
'NetworkController:getNetworkClientById',
() =>
({
configuration: { chainId: initialChainId },
}) as unknown as ReturnType<
NetworkControllerGetNetworkClientByIdAction['handler']
>,
);
const controller = new AccountTrackerController({
messenger,
getStakedBalanceForChain: vi.fn(),
});
controller.updateNativeBalances([
{ address: ADDRESS_1, chainId: initialChainId, balance: '0x1' },
]);

controller.init();

expect(controller.isActive).toBe(true);
expect(controller.state.accountsByChainId).toStrictEqual({
[initialChainId]: {
[CHECKSUM_ADDRESS_1]: { balance: '0x1' },
},
});
});

it('does not add the selected chain in init when isDeprecated() returns true', async () => {
await withController(
{ options: { isDeprecated: () => true } },
({ controller }) => {
expect(controller.state).toStrictEqual({ accountsByChainId: {} });
},
);
});

it('reads other controllers only once when init is called repeatedly', async () => {
await withController(({ controller, messenger }) => {
const call = vi.spyOn(messenger, 'call');

controller.init();

expect(call).not.toHaveBeenCalled();
});
});
});

it('should refresh when selectedAccount changes', async () => {
await withController(
{
Expand Down Expand Up @@ -2467,6 +2575,7 @@ async function withController<ReturnValue>(
getStakedBalanceForChain: vi.fn(),
...options,
});
controller.init();

const refresh = async (
networkClientIds: NetworkClientId[],
Expand Down
60 changes: 45 additions & 15 deletions packages/assets-controllers/src/AccountTrackerController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,10 @@ export class AccountTrackerController extends StaticIntervalPollingController<Ac
/** Track if the keyring is locked */
#isLocked = true;

readonly #seedSelectedChain: boolean;

#initialized = false;

/**
* Creates an AccountTracker instance.
*
Expand Down Expand Up @@ -313,26 +317,16 @@ export class AccountTrackerController extends StaticIntervalPollingController<Ac
isOnboarded?: () => boolean;
isDeprecated?: () => boolean;
}) {
const { selectedNetworkClientId } = messenger.call(
'NetworkController:getState',
);
const {
configuration: { chainId },
} = messenger.call(
'NetworkController:getNetworkClientById',
selectedNetworkClientId,
);
super({
name: controllerName,
messenger,
state: {
accountsByChainId: {
[chainId]: {},
},
accountsByChainId: {},
...state,
},
metadata: accountTrackerMetadata,
});
this.#seedSelectedChain = state?.accountsByChainId === undefined;
this.#getStakedBalanceForChain = getStakedBalanceForChain;

this.#includeStakedAssets = includeStakedAssets;
Expand All @@ -359,9 +353,6 @@ export class AccountTrackerController extends StaticIntervalPollingController<Ac
this.#enforceDisabledState();
}

const { isUnlocked } = this.messenger.call('KeyringController:getState');
this.#isLocked = !isUnlocked;

this.setIntervalLength(interval);

this.messenger.subscribe(
Expand Down Expand Up @@ -436,6 +427,45 @@ export class AccountTrackerController extends StaticIntervalPollingController<Ac
messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
}

/**
* Complete initialization once the controllers this controller reads from
* have been constructed: read the lock state from `KeyringController` and,
* when no `accountsByChainId` state was provided, add an empty entry for the
* chain of the selected network.
*
* The constructor does not call other controllers, so it can run before they
* are constructed. Until this is called, the controller treats the keyring as
* locked. Calling it more than once has no effect.
*/
init(): void {
if (this.#initialized) {
return;
}
this.#initialized = true;

const { isUnlocked } = this.messenger.call('KeyringController:getState');
this.#isLocked = !isUnlocked;

if (!this.#seedSelectedChain || this.#isDeprecated()) {
return;
}

const { selectedNetworkClientId } = this.messenger.call(
'NetworkController:getState',
);
const {
configuration: { chainId },
} = this.messenger.call(
'NetworkController:getNetworkClientById',
selectedNetworkClientId,
);
if (this.state.accountsByChainId[chainId] === undefined) {
this.update((state) => {
state.accountsByChainId[chainId] = {};
});
}
}

/**
* Whether the controller is active (keyring is unlocked and user is onboarded).
* When locked or not onboarded, balance updates should be skipped.
Expand Down
Loading