@metamask/assets-controllers 74.2.0 → 74.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -7,6 +7,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [74.3.1]
11
+
12
+ ### Fixed
13
+
14
+ - Fix values returned from multicall fetcher to use the correct BN type, not BigNumber ([#6411](https://github.com/MetaMask/core/pull/6411))
15
+
16
+ - Ensure every access to the state of `AccountTrackerController` is done with a checksumed address ([#6411](https://github.com/MetaMask/core/pull/6411))
17
+
18
+ - Ensure the balance passed to update `AccountTrackerController:updateNativeBalances` is of type `Hex` ([#6411](https://github.com/MetaMask/core/pull/6411))
19
+
20
+ ## [74.3.0]
21
+
22
+ ### Added
23
+
24
+ - Add native and staked balances to assets calculations ([#6399](https://github.com/MetaMask/core/pull/6399))
25
+
10
26
  ## [74.2.0]
11
27
 
12
28
  ### Added
@@ -1932,7 +1948,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1932
1948
 
1933
1949
  - Use Ethers for AssetsContractController ([#845](https://github.com/MetaMask/core/pull/845))
1934
1950
 
1935
- [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/assets-controllers@74.2.0...HEAD
1951
+ [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/assets-controllers@74.3.1...HEAD
1952
+ [74.3.1]: https://github.com/MetaMask/core/compare/@metamask/assets-controllers@74.3.0...@metamask/assets-controllers@74.3.1
1953
+ [74.3.0]: https://github.com/MetaMask/core/compare/@metamask/assets-controllers@74.2.0...@metamask/assets-controllers@74.3.0
1936
1954
  [74.2.0]: https://github.com/MetaMask/core/compare/@metamask/assets-controllers@74.1.1...@metamask/assets-controllers@74.2.0
1937
1955
  [74.1.1]: https://github.com/MetaMask/core/compare/@metamask/assets-controllers@74.1.0...@metamask/assets-controllers@74.1.1
1938
1956
  [74.1.0]: https://github.com/MetaMask/core/compare/@metamask/assets-controllers@74.0.0...@metamask/assets-controllers@74.1.0
@@ -346,11 +346,14 @@ class AccountTrackerController extends (0, polling_controller_1.StaticIntervalPo
346
346
  const stakedBalancesByChainAndAddress = {};
347
347
  aggregated.forEach(({ success, value, account, token, chainId }) => {
348
348
  if (success && value !== undefined) {
349
+ const checksumAddress = (0, controller_utils_1.toChecksumHexAddress)(account);
349
350
  const hexValue = `0x${value.toString(16)}`;
350
351
  if (token === ZERO_ADDRESS) {
351
352
  // Native balance
352
- if (nextAccountsByChainId[chainId][account].balance !== hexValue) {
353
- nextAccountsByChainId[chainId][account].balance = hexValue;
353
+ if (nextAccountsByChainId[chainId][checksumAddress].balance !==
354
+ hexValue) {
355
+ nextAccountsByChainId[chainId][checksumAddress].balance =
356
+ hexValue;
354
357
  hasChanges = true;
355
358
  }
356
359
  }
@@ -359,7 +362,8 @@ class AccountTrackerController extends (0, polling_controller_1.StaticIntervalPo
359
362
  if (!stakedBalancesByChainAndAddress[chainId]) {
360
363
  stakedBalancesByChainAndAddress[chainId] = {};
361
364
  }
362
- stakedBalancesByChainAndAddress[chainId][account] = hexValue;
365
+ stakedBalancesByChainAndAddress[chainId][checksumAddress] =
366
+ hexValue;
363
367
  }
364
368
  }
365
369
  });
@@ -431,16 +435,19 @@ class AccountTrackerController extends (0, polling_controller_1.StaticIntervalPo
431
435
  updateNativeBalances(balances) {
432
436
  this.update((state) => {
433
437
  balances.forEach(({ address, chainId, balance }) => {
438
+ const checksumAddress = (0, controller_utils_1.toChecksumHexAddress)(address);
434
439
  // Ensure the chainId exists in the state
435
440
  if (!state.accountsByChainId[chainId]) {
436
441
  state.accountsByChainId[chainId] = {};
437
442
  }
438
443
  // Ensure the address exists for this chain
439
- if (!state.accountsByChainId[chainId][address]) {
440
- state.accountsByChainId[chainId][address] = { balance: '0x0' };
444
+ if (!state.accountsByChainId[chainId][checksumAddress]) {
445
+ state.accountsByChainId[chainId][checksumAddress] = {
446
+ balance: '0x0',
447
+ };
441
448
  }
442
449
  // Update the balance
443
- state.accountsByChainId[chainId][address].balance = balance;
450
+ state.accountsByChainId[chainId][checksumAddress].balance = balance;
444
451
  });
445
452
  });
446
453
  }
@@ -454,16 +461,20 @@ class AccountTrackerController extends (0, polling_controller_1.StaticIntervalPo
454
461
  updateStakedBalances(stakedBalances) {
455
462
  this.update((state) => {
456
463
  stakedBalances.forEach(({ address, chainId, stakedBalance }) => {
464
+ const checksumAddress = (0, controller_utils_1.toChecksumHexAddress)(address);
457
465
  // Ensure the chainId exists in the state
458
466
  if (!state.accountsByChainId[chainId]) {
459
467
  state.accountsByChainId[chainId] = {};
460
468
  }
461
469
  // Ensure the address exists for this chain
462
- if (!state.accountsByChainId[chainId][address]) {
463
- state.accountsByChainId[chainId][address] = { balance: '0x0' };
470
+ if (!state.accountsByChainId[chainId][checksumAddress]) {
471
+ state.accountsByChainId[chainId][checksumAddress] = {
472
+ balance: '0x0',
473
+ };
464
474
  }
465
475
  // Update the staked balance
466
- state.accountsByChainId[chainId][address].stakedBalance = stakedBalance;
476
+ state.accountsByChainId[chainId][checksumAddress].stakedBalance =
477
+ stakedBalance;
467
478
  });
468
479
  });
469
480
  }
@@ -1 +1 @@
1
- {"version":3,"file":"AccountTrackerController.cjs","sourceRoot":"","sources":["../src/AccountTrackerController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AACA,wDAAoD;AACpD,wDAAwD;AAYxD,iEAIoC;AACpC,oEAA2C;AAO3C,qEAA+E;AAE/E,2CAAgE;AAChE,6CAAoC;AACpC,kDAAuB;AACvB,mCAA4C;AAC5C,sGAA4E;AAE5E,6EAKoC;AACpC,iDAAgF;AAChF,gGAI4D;AAE5D;;GAEG;AACH,MAAM,cAAc,GAAG,0BAA0B,CAAC;AAKlD,MAAM,YAAY,GAChB,4CAA+D,CAAC;AAElE;;;GAGG;AACH,MAAM,+BAA+B;IASnC,YACE,WAA2C,EAC3C,gBAAiD,EACjD,m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,GACb,GAAG,IAAI,CAAC,eAAe,CAAC,IAAI,CAC3B,wCAAwC,EACxC,uBAAuB,CACxB,CAAC;IAEF,OAAO;QACL,OAAO;QACP,QAAQ;QACR,QAAQ,EAAE,IAAI,mBAAQ,CAAC,QAAQ,CAAC;QAChC,YAAY;KACb,CAAC;AACJ,CAAC;IAQC,MAAM,EAAE,8BAA8B,EAAE,GAAG,IAAI,CAAC,eAAe,CAAC,IAAI,CAClE,4BAA4B,CAC7B,CAAC;IACF,OAAO,MAAM,CAAC,MAAM,CAAC,8BAA8B,CAAC,CAAC,OAAO,CAC1D,CAAC,oBAAoB,EAAE,EAAE,CACvB,oBAAoB,CAAC,YAAY,CAAC,GAAG,CACnC,CAAC,WAAW,EAAE,EAAE,CAAC,WAAW,CAAC,eAAe,CAC7C,CACJ,CAAC;AACJ,CAAC;IAmQC,IAAI,CAAC,eAAe,CAAC,qBAAqB,CACxC,GAAG,cAAc,uBAAgC,EACjD,IAAI,CAAC,oBAAoB,CAAC,IAAI,CAAC,IAAI,CAAC,CACrC,CAAC;IAEF,IAAI,CAAC,eAAe,CAAC,qBAAqB,CACxC,GAAG,cAAc,uBAAgC,EACjD,IAAI,CAAC,oBAAoB,CAAC,IAAI,CAAC,IAAI,CAAC,CACrC,CAAC;AACJ,CAAC;AAGH,kBAAe,wBAAwB,CAAC","sourcesContent":["import type { BigNumber } from '@ethersproject/bignumber';\nimport { Contract } from '@ethersproject/contracts';\nimport { Web3Provider } from '@ethersproject/providers';\nimport type {\n AccountsControllerSelectedEvmAccountChangeEvent,\n AccountsControllerGetSelectedAccountAction,\n AccountsControllerListAccountsAction,\n AccountsControllerSelectedAccountChangeEvent,\n} from '@metamask/accounts-controller';\nimport type {\n ControllerStateChangeEvent,\n ControllerGetStateAction,\n RestrictedMessenger,\n} from '@metamask/base-controller';\nimport {\n query,\n safelyExecuteWithTimeout,\n toChecksumHexAddress,\n} from '@metamask/controller-utils';\nimport EthQuery from '@metamask/eth-query';\nimport type {\n NetworkClient,\n NetworkClientId,\n NetworkControllerGetNetworkClientByIdAction,\n NetworkControllerGetStateAction,\n} from '@metamask/network-controller';\nimport { StaticIntervalPollingController } from '@metamask/polling-controller';\nimport type { PreferencesControllerGetStateAction } from '@metamask/preferences-controller';\nimport { assert, hasProperty, type Hex } from '@metamask/utils';\nimport { Mutex } from 'async-mutex';\nimport BN from 'bn.js';\nimport { cloneDeep, isEqual } from 'lodash';\nimport abiSingleCallBalancesContract from 'single-call-balance-checker-abi';\n\nimport {\n SINGLE_CALL_BALANCES_ADDRESS_BY_CHAINID,\n STAKING_CONTRACT_ADDRESS_BY_CHAINID,\n type AssetsContractController,\n type StakedBalance,\n} from './AssetsContractController';\nimport { reduceInBatchesSerially, TOKEN_PRICES_BATCH_SIZE } from './assetsUtil';\nimport {\n AccountsApiBalanceFetcher,\n type BalanceFetcher,\n type ProcessedBalance,\n} from './multi-chain-accounts-service/api-balance-fetcher';\n\n/**\n * The name of the {@link AccountTrackerController}.\n */\nconst controllerName = 'AccountTrackerController';\n\nexport type ChainIdHex = Hex;\nexport type ChecksumAddress = Hex;\n\nconst ZERO_ADDRESS =\n '0x0000000000000000000000000000000000000000' as ChecksumAddress;\n\n/**\n * RPC-based balance fetcher for AccountTrackerController.\n * Fetches only native balances and staked balances (no token balances).\n */\nclass AccountTrackerRpcBalanceFetcher implements BalanceFetcher {\n readonly #getProvider: (chainId: Hex) => Web3Provider;\n\n readonly #getNetworkClient: (chainId: Hex) => NetworkClient;\n\n readonly #includeStakedAssets: boolean;\n\n readonly #getStakedBalanceForChain: AssetsContractController['getStakedBalanceForChain'];\n\n constructor(\n getProvider: (chainId: Hex) => Web3Provider,\n getNetworkClient: (chainId: Hex) => NetworkClient,\n includeStakedAssets: boolean,\n getStakedBalanceForChain: AssetsContractController['getStakedBalanceForChain'],\n ) {\n this.#getProvider = getProvider;\n this.#getNetworkClient = getNetworkClient;\n this.#includeStakedAssets = includeStakedAssets;\n this.#getStakedBalanceForChain = getStakedBalanceForChain;\n }\n\n supports(): boolean {\n return true; // fallback – supports every chain\n }\n\n async fetch({\n chainIds,\n queryAllAccounts,\n selectedAccount,\n allAccounts,\n }: Parameters<BalanceFetcher['fetch']>[0]): Promise<ProcessedBalance[]> {\n // Process all chains in parallel for better performance\n const chainProcessingPromises = chainIds.map(async (chainId) => {\n const accountsToUpdate = queryAllAccounts\n ? Object.values(allAccounts).map(\n (account) =>\n toChecksumHexAddress(account.address) as ChecksumAddress,\n )\n : [selectedAccount];\n\n const { provider, blockTracker } = this.#getNetworkClient(chainId);\n const ethQuery = new EthQuery(provider);\n const chainResults: ProcessedBalance[] = [];\n\n // Force fresh block data before multicall\n await safelyExecuteWithTimeout(() =>\n blockTracker?.checkForLatestBlock?.(),\n );\n\n // Fetch native balances\n if (hasProperty(SINGLE_CALL_BALANCES_ADDRESS_BY_CHAINID, chainId)) {\n const contractAddress = SINGLE_CALL_BALANCES_ADDRESS_BY_CHAINID[\n chainId\n ] as string;\n\n const contract = new Contract(\n contractAddress,\n abiSingleCallBalancesContract,\n this.#getProvider(chainId),\n );\n\n const nativeBalances = await safelyExecuteWithTimeout(\n () =>\n contract.balances(accountsToUpdate, [ZERO_ADDRESS]) as Promise<\n BigNumber[]\n >,\n false,\n 3_000, // 3s max call for multicall contract call\n );\n\n if (nativeBalances) {\n accountsToUpdate.forEach((address, index) => {\n chainResults.push({\n success: true,\n value: new BN(nativeBalances[index].toString()),\n account: address,\n token: ZERO_ADDRESS,\n chainId,\n });\n });\n }\n } else {\n // Process accounts in batches using reduceInBatchesSerially\n await reduceInBatchesSerially<string, void>({\n values: accountsToUpdate,\n batchSize: TOKEN_PRICES_BATCH_SIZE,\n initialResult: undefined,\n eachBatch: async (workingResult: void, batch: string[]) => {\n const balancePromises = batch.map(async (address: string) => {\n const balanceResult = await this.#getBalanceFromChain(\n address,\n ethQuery,\n ).catch(() => null);\n\n if (balanceResult) {\n chainResults.push({\n success: true,\n value: new BN(balanceResult.replace('0x', ''), 16),\n account: address as ChecksumAddress,\n token: ZERO_ADDRESS,\n chainId,\n });\n } else {\n chainResults.push({\n success: false,\n account: address as ChecksumAddress,\n token: ZERO_ADDRESS,\n chainId,\n });\n }\n });\n\n await Promise.allSettled(balancePromises);\n return workingResult;\n },\n });\n }\n\n // Fetch staked balances if enabled\n if (this.#includeStakedAssets) {\n const stakedBalancesPromise = this.#getStakedBalanceForChain(\n accountsToUpdate,\n chainId,\n );\n\n const stakedBalanceResult = await safelyExecuteWithTimeout(\n async () =>\n (await stakedBalancesPromise) as Record<string, StakedBalance>,\n );\n\n if (stakedBalanceResult) {\n // Find the staking contract address for this chain\n const stakingContractAddress =\n STAKING_CONTRACT_ADDRESS_BY_CHAINID[\n chainId as keyof typeof STAKING_CONTRACT_ADDRESS_BY_CHAINID\n ];\n\n if (stakingContractAddress) {\n Object.entries(stakedBalanceResult).forEach(\n ([address, balance]) => {\n chainResults.push({\n success: true,\n value: balance\n ? new BN(balance.replace('0x', ''), 16)\n : new BN('0'),\n account: address as ChecksumAddress,\n token: toChecksumHexAddress(\n stakingContractAddress,\n ) as ChecksumAddress,\n chainId,\n });\n },\n );\n }\n }\n }\n\n return chainResults;\n });\n\n // Wait for all chains to complete (or fail) and collect results\n const chainResultsArray = await Promise.allSettled(chainProcessingPromises);\n const results: ProcessedBalance[] = [];\n\n chainResultsArray.forEach((chainResult) => {\n if (chainResult.status === 'fulfilled') {\n results.push(...chainResult.value);\n } else {\n // Log error but continue with other chains\n console.warn('Chain processing failed:', chainResult.reason);\n }\n });\n\n return results;\n }\n\n /**\n * Fetches the balance of a given address from the blockchain.\n *\n * @param address - The account address to fetch the balance for.\n * @param ethQuery - The EthQuery instance to query getBalance with.\n * @returns A promise that resolves to the balance in a hex string format.\n */\n async #getBalanceFromChain(\n address: string,\n ethQuery?: EthQuery,\n ): Promise<string | undefined> {\n return await safelyExecuteWithTimeout(async () => {\n assert(ethQuery, 'Provider not set.');\n return await query(ethQuery, 'getBalance', [address]);\n });\n }\n}\n\n/**\n * AccountInformation\n *\n * Account information object\n *\n * balance - Hex string of an account balance in wei\n *\n * stakedBalance - Hex string of an account staked balance in wei\n */\nexport type AccountInformation = {\n balance: string;\n stakedBalance?: string;\n};\n\n/**\n * AccountTrackerControllerState\n *\n * Account tracker controller state\n *\n * accountsByChainId - Map of addresses to account information by chain\n */\nexport type AccountTrackerControllerState = {\n accountsByChainId: Record<string, { [address: string]: AccountInformation }>;\n};\n\nconst accountTrackerMetadata = {\n accountsByChainId: {\n persist: true,\n anonymous: false,\n },\n};\n\n/**\n * The action that can be performed to get the state of the {@link AccountTrackerController}.\n */\nexport type AccountTrackerControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n AccountTrackerControllerState\n>;\n\n/**\n * The action that can be performed to update multiple native token balances in batch.\n */\nexport type AccountTrackerUpdateNativeBalancesAction = {\n type: `${typeof controllerName}:updateNativeBalances`;\n handler: AccountTrackerController['updateNativeBalances'];\n};\n\n/**\n * The action that can be performed to update multiple staked balances in batch.\n */\nexport type AccountTrackerUpdateStakedBalancesAction = {\n type: `${typeof controllerName}:updateStakedBalances`;\n handler: AccountTrackerController['updateStakedBalances'];\n};\n\n/**\n * The actions that can be performed using the {@link AccountTrackerController}.\n */\nexport type AccountTrackerControllerActions =\n | AccountTrackerControllerGetStateAction\n | AccountTrackerUpdateNativeBalancesAction\n | AccountTrackerUpdateStakedBalancesAction;\n\n/**\n * The messenger of the {@link AccountTrackerController} for communication.\n */\nexport type AllowedActions =\n | AccountsControllerListAccountsAction\n | PreferencesControllerGetStateAction\n | AccountsControllerGetSelectedAccountAction\n | NetworkControllerGetStateAction\n | NetworkControllerGetNetworkClientByIdAction;\n\n/**\n * The event that {@link AccountTrackerController} can emit.\n */\nexport type AccountTrackerControllerStateChangeEvent =\n ControllerStateChangeEvent<\n typeof controllerName,\n AccountTrackerControllerState\n >;\n\n/**\n * The events that {@link AccountTrackerController} can emit.\n */\nexport type AccountTrackerControllerEvents =\n AccountTrackerControllerStateChangeEvent;\n\n/**\n * The external events available to the {@link AccountTrackerController}.\n */\nexport type AllowedEvents =\n | AccountsControllerSelectedEvmAccountChangeEvent\n | AccountsControllerSelectedAccountChangeEvent;\n\n/**\n * The messenger of the {@link AccountTrackerController}.\n */\nexport type AccountTrackerControllerMessenger = RestrictedMessenger<\n typeof controllerName,\n AccountTrackerControllerActions | AllowedActions,\n AccountTrackerControllerEvents | AllowedEvents,\n AllowedActions['type'],\n AllowedEvents['type']\n>;\n\n/** The input to start polling for the {@link AccountTrackerController} */\ntype AccountTrackerPollingInput = {\n networkClientIds: NetworkClientId[];\n};\n\n/**\n * Controller that tracks the network balances for all user accounts.\n */\nexport class AccountTrackerController extends StaticIntervalPollingController<AccountTrackerPollingInput>()<\n typeof controllerName,\n AccountTrackerControllerState,\n AccountTrackerControllerMessenger\n> {\n readonly #refreshMutex = new Mutex();\n\n readonly #includeStakedAssets: boolean;\n\n readonly #getStakedBalanceForChain: AssetsContractController['getStakedBalanceForChain'];\n\n readonly #balanceFetchers: BalanceFetcher[];\n\n /**\n * Creates an AccountTracker instance.\n *\n * @param options - The controller options.\n * @param options.interval - Polling interval used to fetch new account balances.\n * @param options.state - Initial state to set on this controller.\n * @param options.messenger - The controller messaging system.\n * @param options.getStakedBalanceForChain - The function to get the staked native asset balance for a chain.\n * @param options.includeStakedAssets - Whether to include staked assets in the account balances.\n * @param options.useAccountsAPI - Enable Accounts‑API strategy (if supported chain).\n * @param options.allowExternalServices - Disable external HTTP calls (privacy / offline mode).\n */\n constructor({\n interval = 10000,\n state,\n messenger,\n getStakedBalanceForChain,\n includeStakedAssets = false,\n useAccountsAPI = false,\n allowExternalServices = () => true,\n }: {\n interval?: number;\n state?: Partial<AccountTrackerControllerState>;\n messenger: AccountTrackerControllerMessenger;\n getStakedBalanceForChain: AssetsContractController['getStakedBalanceForChain'];\n includeStakedAssets?: boolean;\n useAccountsAPI?: boolean;\n allowExternalServices?: () => boolean;\n }) {\n const { selectedNetworkClientId } = messenger.call(\n 'NetworkController:getState',\n );\n const {\n configuration: { chainId },\n } = messenger.call(\n 'NetworkController:getNetworkClientById',\n selectedNetworkClientId,\n );\n super({\n name: controllerName,\n messenger,\n state: {\n accountsByChainId: {\n [chainId]: {},\n },\n ...state,\n },\n metadata: accountTrackerMetadata,\n });\n this.#getStakedBalanceForChain = getStakedBalanceForChain;\n\n this.#includeStakedAssets = includeStakedAssets;\n\n // Initialize balance fetchers - Strategy order: API first, then RPC fallback\n this.#balanceFetchers = [\n ...(useAccountsAPI && allowExternalServices()\n ? [new AccountsApiBalanceFetcher('extension', this.#getProvider)]\n : []),\n new AccountTrackerRpcBalanceFetcher(\n this.#getProvider,\n this.#getNetworkClient,\n includeStakedAssets,\n getStakedBalanceForChain,\n ),\n ];\n\n this.setIntervalLength(interval);\n\n this.messagingSystem.subscribe(\n 'AccountsController:selectedEvmAccountChange',\n (newAddress, prevAddress) => {\n if (newAddress !== prevAddress) {\n // Making an async call for this new event\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n this.refresh(this.#getNetworkClientIds());\n }\n },\n (event): string => event.address,\n );\n\n this.#registerMessageHandlers();\n }\n\n private syncAccounts(newChainIds: string[]) {\n const accountsByChainId = cloneDeep(this.state.accountsByChainId);\n const { selectedNetworkClientId } = this.messagingSystem.call(\n 'NetworkController:getState',\n );\n const {\n configuration: { chainId: currentChainId },\n } = this.messagingSystem.call(\n 'NetworkController:getNetworkClientById',\n selectedNetworkClientId,\n );\n\n const existing = Object.keys(accountsByChainId?.[currentChainId] ?? {});\n\n // Initialize new chain IDs if they don't exist\n newChainIds.forEach((newChainId) => {\n if (!accountsByChainId[newChainId]) {\n accountsByChainId[newChainId] = {};\n existing.forEach((address) => {\n accountsByChainId[newChainId][address] = { balance: '0x0' };\n });\n }\n });\n\n // Note: The address from the preferences controller are checksummed\n // The addresses from the accounts controller are lowercased\n const addresses = Object.values(\n this.messagingSystem\n .call('AccountsController:listAccounts')\n .map((internalAccount) =>\n toChecksumHexAddress(internalAccount.address),\n ),\n );\n const newAddresses = addresses.filter(\n (address) => !existing.includes(address),\n );\n const oldAddresses = existing.filter(\n (address) => !addresses.includes(address),\n );\n Object.keys(accountsByChainId).forEach((chainId) => {\n newAddresses.forEach((address) => {\n accountsByChainId[chainId][address] = {\n balance: '0x0',\n };\n });\n });\n\n Object.keys(accountsByChainId).forEach((chainId) => {\n oldAddresses.forEach((address) => {\n delete accountsByChainId[chainId][address];\n });\n });\n\n if (!isEqual(this.state.accountsByChainId, accountsByChainId)) {\n this.update((state) => {\n state.accountsByChainId = accountsByChainId;\n });\n }\n }\n\n readonly #getProvider = (chainId: Hex): Web3Provider => {\n const { networkConfigurationsByChainId } = this.messagingSystem.call(\n 'NetworkController:getState',\n );\n const cfg = networkConfigurationsByChainId[chainId];\n const { networkClientId } = cfg.rpcEndpoints[cfg.defaultRpcEndpointIndex];\n const client = this.messagingSystem.call(\n 'NetworkController:getNetworkClientById',\n networkClientId,\n );\n return new Web3Provider(client.provider);\n };\n\n readonly #getNetworkClient = (chainId: Hex) => {\n const { networkConfigurationsByChainId } = this.messagingSystem.call(\n 'NetworkController:getState',\n );\n const cfg = networkConfigurationsByChainId[chainId];\n const { networkClientId } = cfg.rpcEndpoints[cfg.defaultRpcEndpointIndex];\n return this.messagingSystem.call(\n 'NetworkController:getNetworkClientById',\n networkClientId,\n );\n };\n\n /**\n * Resolves a networkClientId to a network client config\n * or globally selected network config if not provided\n *\n * @param networkClientId - Optional networkClientId to fetch a network client with\n * @returns network client config\n */\n #getCorrectNetworkClient(networkClientId?: NetworkClientId) {\n const selectedNetworkClientId =\n networkClientId ??\n this.messagingSystem.call('NetworkController:getState')\n .selectedNetworkClientId;\n const {\n configuration: { chainId },\n provider,\n blockTracker,\n } = this.messagingSystem.call(\n 'NetworkController:getNetworkClientById',\n selectedNetworkClientId,\n );\n\n return {\n chainId,\n provider,\n ethQuery: new EthQuery(provider),\n blockTracker,\n };\n }\n\n /**\n * Retrieves the list of network client IDs.\n *\n * @returns An array of network client IDs.\n */\n #getNetworkClientIds(): NetworkClientId[] {\n const { networkConfigurationsByChainId } = this.messagingSystem.call(\n 'NetworkController:getState',\n );\n return Object.values(networkConfigurationsByChainId).flatMap(\n (networkConfiguration) =>\n networkConfiguration.rpcEndpoints.map(\n (rpcEndpoint) => rpcEndpoint.networkClientId,\n ),\n );\n }\n\n /**\n * Refreshes the balances of the accounts using the networkClientId\n *\n * @param input - The input for the poll.\n * @param input.networkClientIds - The network client IDs used to get balances.\n */\n async _executePoll({\n networkClientIds,\n }: AccountTrackerPollingInput): Promise<void> {\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n this.refresh(networkClientIds);\n }\n\n /**\n * Refreshes the balances of the accounts depending on the multi-account setting.\n * If multi-account is disabled, only updates the selected account balance.\n * If multi-account is enabled, updates balances for all accounts.\n *\n * @param networkClientIds - Optional network client IDs to fetch a network client with\n */\n async refresh(networkClientIds: NetworkClientId[]) {\n const selectedAccount = this.messagingSystem.call(\n 'AccountsController:getSelectedAccount',\n );\n const allAccounts = this.messagingSystem.call(\n 'AccountsController:listAccounts',\n );\n const { isMultiAccountBalancesEnabled } = this.messagingSystem.call(\n 'PreferencesController:getState',\n );\n\n const releaseLock = await this.#refreshMutex.acquire();\n try {\n const chainIds = networkClientIds.map((networkClientId) => {\n const { chainId } = this.#getCorrectNetworkClient(networkClientId);\n return chainId;\n });\n\n this.syncAccounts(chainIds);\n\n // Use balance fetchers with fallback strategy\n const aggregated: ProcessedBalance[] = [];\n let remainingChains = [...chainIds] as ChainIdHex[];\n\n // Try each fetcher in order, removing successfully processed chains\n for (const fetcher of this.#balanceFetchers) {\n const supportedChains = remainingChains.filter((c) =>\n fetcher.supports(c),\n );\n if (!supportedChains.length) {\n continue;\n }\n\n try {\n const balances = await fetcher.fetch({\n chainIds: supportedChains,\n queryAllAccounts: isMultiAccountBalancesEnabled,\n selectedAccount: toChecksumHexAddress(\n selectedAccount.address,\n ) as ChecksumAddress,\n allAccounts,\n });\n\n if (balances && balances.length > 0) {\n aggregated.push(...balances);\n // Remove chains that were successfully processed\n const processedChains = new Set(balances.map((b) => b.chainId));\n remainingChains = remainingChains.filter(\n (chain) => !processedChains.has(chain),\n );\n }\n } catch (error) {\n console.warn(\n `Balance fetcher failed for chains ${supportedChains.join(', ')}: ${String(error)}`,\n );\n // Continue to next fetcher (fallback)\n }\n\n // If all chains have been processed, break early\n if (remainingChains.length === 0) {\n break;\n }\n }\n\n // Build a _copy_ of the current state and track whether anything changed\n const nextAccountsByChainId: AccountTrackerControllerState['accountsByChainId'] =\n cloneDeep(this.state.accountsByChainId);\n let hasChanges = false;\n\n // Process the aggregated balance results\n const stakedBalancesByChainAndAddress: Record<\n string,\n Record<string, string>\n > = {};\n\n aggregated.forEach(({ success, value, account, token, chainId }) => {\n if (success && value !== undefined) {\n const hexValue = `0x${value.toString(16)}`;\n\n if (token === ZERO_ADDRESS) {\n // Native balance\n if (nextAccountsByChainId[chainId][account].balance !== hexValue) {\n nextAccountsByChainId[chainId][account].balance = hexValue;\n hasChanges = true;\n }\n } else {\n // Staked balance (from staking contract address)\n if (!stakedBalancesByChainAndAddress[chainId]) {\n stakedBalancesByChainAndAddress[chainId] = {};\n }\n stakedBalancesByChainAndAddress[chainId][account] = hexValue;\n }\n }\n });\n\n // Apply staked balances\n Object.entries(stakedBalancesByChainAndAddress).forEach(\n ([chainId, balancesByAddress]) => {\n Object.entries(balancesByAddress).forEach(\n ([address, stakedBalance]) => {\n if (\n nextAccountsByChainId[chainId][address].stakedBalance !==\n stakedBalance\n ) {\n nextAccountsByChainId[chainId][address].stakedBalance =\n stakedBalance;\n hasChanges = true;\n }\n },\n );\n },\n );\n\n // Only update state if something changed\n if (hasChanges) {\n this.update((state) => {\n state.accountsByChainId = nextAccountsByChainId;\n });\n }\n } finally {\n releaseLock();\n }\n }\n\n /**\n * Sync accounts balances with some additional addresses.\n *\n * @param addresses - the additional addresses, may be hardware wallet addresses.\n * @param networkClientId - Optional networkClientId to fetch a network client with.\n * @returns accounts - addresses with synced balance\n */\n async syncBalanceWithAddresses(\n addresses: string[],\n networkClientId?: NetworkClientId,\n ): Promise<\n Record<string, { balance: string; stakedBalance?: StakedBalance }>\n > {\n const { ethQuery } = this.#getCorrectNetworkClient(networkClientId);\n\n // TODO: This should use multicall when enabled by the user.\n return await Promise.all(\n addresses.map(\n (address): Promise<[string, string, StakedBalance] | undefined> => {\n return safelyExecuteWithTimeout(async () => {\n assert(ethQuery, 'Provider not set.');\n const balance = await query(ethQuery, 'getBalance', [address]);\n\n let stakedBalance: StakedBalance;\n if (this.#includeStakedAssets) {\n stakedBalance = (\n await this.#getStakedBalanceForChain([address], networkClientId)\n )[address];\n }\n return [address, balance, stakedBalance];\n });\n },\n ),\n ).then((value) => {\n return value.reduce((obj, item) => {\n if (!item) {\n return obj;\n }\n\n const [address, balance, stakedBalance] = item;\n return {\n ...obj,\n [address]: {\n balance,\n stakedBalance,\n },\n };\n }, {});\n });\n }\n\n /**\n * Updates the balances of multiple native tokens in a single batch operation.\n * This is more efficient than calling updateNativeToken multiple times as it\n * triggers only one state update.\n *\n * @param balances - Array of balance updates, each containing address, chainId, and balance.\n */\n updateNativeBalances(\n balances: { address: string; chainId: Hex; balance: string }[],\n ) {\n this.update((state) => {\n balances.forEach(({ address, chainId, balance }) => {\n // Ensure the chainId exists in the state\n if (!state.accountsByChainId[chainId]) {\n state.accountsByChainId[chainId] = {};\n }\n\n // Ensure the address exists for this chain\n if (!state.accountsByChainId[chainId][address]) {\n state.accountsByChainId[chainId][address] = { balance: '0x0' };\n }\n\n // Update the balance\n state.accountsByChainId[chainId][address].balance = balance;\n });\n });\n }\n\n /**\n * Updates the staked balances of multiple accounts in a single batch operation.\n * This is more efficient than updating staked balances individually as it\n * triggers only one state update.\n *\n * @param stakedBalances - Array of staked balance updates, each containing address, chainId, and stakedBalance.\n */\n updateStakedBalances(\n stakedBalances: {\n address: string;\n chainId: Hex;\n stakedBalance: StakedBalance;\n }[],\n ) {\n this.update((state) => {\n stakedBalances.forEach(({ address, chainId, stakedBalance }) => {\n // Ensure the chainId exists in the state\n if (!state.accountsByChainId[chainId]) {\n state.accountsByChainId[chainId] = {};\n }\n\n // Ensure the address exists for this chain\n if (!state.accountsByChainId[chainId][address]) {\n state.accountsByChainId[chainId][address] = { balance: '0x0' };\n }\n\n // Update the staked balance\n state.accountsByChainId[chainId][address].stakedBalance = stakedBalance;\n });\n });\n }\n\n #registerMessageHandlers() {\n this.messagingSystem.registerActionHandler(\n `${controllerName}:updateNativeBalances` as const,\n this.updateNativeBalances.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:updateStakedBalances` as const,\n this.updateStakedBalances.bind(this),\n );\n }\n}\n\nexport default AccountTrackerController;\n"]}
1
+ {"version":3,"file":"AccountTrackerController.cjs","sourceRoot":"","sources":["../src/AccountTrackerController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AACA,wDAAoD;AACpD,wDAAwD;AAYxD,iEAIoC;AACpC,oEAA2C;AAO3C,qEAA+E;AAE/E,2CAAgE;AAChE,6CAAoC;AACpC,kDAAuB;AACvB,mCAA4C;AAC5C,sGAA4E;AAE5E,6EAKoC;AACpC,iDAAgF;AAChF,gGAI4D;AAE5D;;GAEG;AACH,MAAM,cAAc,GAAG,0BAA0B,CAAC;AAKlD,MAAM,YAAY,GAChB,4CAA+D,CAAC;AAElE;;;GAGG;AACH,MAAM,+BAA+B;IASnC,YACE,WAA2C,EAC3C,gBAAiD,EACjD,mBAA4B,EAC5B,wBAA8E;;QAZvE,+DAA6C;QAE7C,oEAAmD;QAEnD,uEAA8B;QAE9B,4EAAgF;QAQvF,uBAAA,IAAI,gDAAgB,WAAW,MAAA,CAAC;QAChC,uBAAA,IAAI,qDAAqB,gBAAgB,MAAA,CAAC;QAC1C,uBAAA,IAAI,wDAAwB,mBAAmB,MAAA,CAAC;QAChD,uBAAA,IAAI,6DAA6B,wBAAwB,MAAA,CAAC;IAC5D,CAAC;IAED,QAAQ;QACN,O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,QAAQ,EAAE,IAAI,mBAAQ,CAAC,QAAQ,CAAC;QAChC,YAAY;KACb,CAAC;AACJ,CAAC;IAQC,MAAM,EAAE,8BAA8B,EAAE,GAAG,IAAI,CAAC,eAAe,CAAC,IAAI,CAClE,4BAA4B,CAC7B,CAAC;IACF,OAAO,MAAM,CAAC,MAAM,CAAC,8BAA8B,CAAC,CAAC,OAAO,CAC1D,CAAC,oBAAoB,EAAE,EAAE,CACvB,oBAAoB,CAAC,YAAY,CAAC,GAAG,CACnC,CAAC,WAAW,EAAE,EAAE,CAAC,WAAW,CAAC,eAAe,CAC7C,CACJ,CAAC;AACJ,CAAC;IAkRC,IAAI,CAAC,eAAe,CAAC,qBAAqB,CACxC,GAAG,cAAc,uBAAgC,EACjD,IAAI,CAAC,oBAAoB,CAAC,IAAI,CAAC,IAAI,CAAC,CACrC,CAAC;IAEF,IAAI,CAAC,eAAe,CAAC,qBAAqB,CACxC,GAAG,cAAc,uBAAgC,EACjD,IAAI,CAAC,oBAAoB,CAAC,IAAI,CAAC,IAAI,CAAC,CACrC,CAAC;AACJ,CAAC;AAGH,kBAAe,wBAAwB,CAAC","sourcesContent":["import type { BigNumber } from '@ethersproject/bignumber';\nimport { Contract } from '@ethersproject/contracts';\nimport { Web3Provider } from '@ethersproject/providers';\nimport type {\n AccountsControllerSelectedEvmAccountChangeEvent,\n AccountsControllerGetSelectedAccountAction,\n AccountsControllerListAccountsAction,\n AccountsControllerSelectedAccountChangeEvent,\n} from '@metamask/accounts-controller';\nimport type {\n ControllerStateChangeEvent,\n ControllerGetStateAction,\n RestrictedMessenger,\n} from '@metamask/base-controller';\nimport {\n query,\n safelyExecuteWithTimeout,\n toChecksumHexAddress,\n} from '@metamask/controller-utils';\nimport EthQuery from '@metamask/eth-query';\nimport type {\n NetworkClient,\n NetworkClientId,\n NetworkControllerGetNetworkClientByIdAction,\n NetworkControllerGetStateAction,\n} from '@metamask/network-controller';\nimport { StaticIntervalPollingController } from '@metamask/polling-controller';\nimport type { PreferencesControllerGetStateAction } from '@metamask/preferences-controller';\nimport { assert, hasProperty, type Hex } from '@metamask/utils';\nimport { Mutex } from 'async-mutex';\nimport BN from 'bn.js';\nimport { cloneDeep, isEqual } from 'lodash';\nimport abiSingleCallBalancesContract from 'single-call-balance-checker-abi';\n\nimport {\n SINGLE_CALL_BALANCES_ADDRESS_BY_CHAINID,\n STAKING_CONTRACT_ADDRESS_BY_CHAINID,\n type AssetsContractController,\n type StakedBalance,\n} from './AssetsContractController';\nimport { reduceInBatchesSerially, TOKEN_PRICES_BATCH_SIZE } from './assetsUtil';\nimport {\n AccountsApiBalanceFetcher,\n type BalanceFetcher,\n type ProcessedBalance,\n} from './multi-chain-accounts-service/api-balance-fetcher';\n\n/**\n * The name of the {@link AccountTrackerController}.\n */\nconst controllerName = 'AccountTrackerController';\n\nexport type ChainIdHex = Hex;\nexport type ChecksumAddress = Hex;\n\nconst ZERO_ADDRESS =\n '0x0000000000000000000000000000000000000000' as ChecksumAddress;\n\n/**\n * RPC-based balance fetcher for AccountTrackerController.\n * Fetches only native balances and staked balances (no token balances).\n */\nclass AccountTrackerRpcBalanceFetcher implements BalanceFetcher {\n readonly #getProvider: (chainId: Hex) => Web3Provider;\n\n readonly #getNetworkClient: (chainId: Hex) => NetworkClient;\n\n readonly #includeStakedAssets: boolean;\n\n readonly #getStakedBalanceForChain: AssetsContractController['getStakedBalanceForChain'];\n\n constructor(\n getProvider: (chainId: Hex) => Web3Provider,\n getNetworkClient: (chainId: Hex) => NetworkClient,\n includeStakedAssets: boolean,\n getStakedBalanceForChain: AssetsContractController['getStakedBalanceForChain'],\n ) {\n this.#getProvider = getProvider;\n this.#getNetworkClient = getNetworkClient;\n this.#includeStakedAssets = includeStakedAssets;\n this.#getStakedBalanceForChain = getStakedBalanceForChain;\n }\n\n supports(): boolean {\n return true; // fallback – supports every chain\n }\n\n async fetch({\n chainIds,\n queryAllAccounts,\n selectedAccount,\n allAccounts,\n }: Parameters<BalanceFetcher['fetch']>[0]): Promise<ProcessedBalance[]> {\n // Process all chains in parallel for better performance\n const chainProcessingPromises = chainIds.map(async (chainId) => {\n const accountsToUpdate = queryAllAccounts\n ? Object.values(allAccounts).map(\n (account) =>\n toChecksumHexAddress(account.address) as ChecksumAddress,\n )\n : [selectedAccount];\n\n const { provider, blockTracker } = this.#getNetworkClient(chainId);\n const ethQuery = new EthQuery(provider);\n const chainResults: ProcessedBalance[] = [];\n\n // Force fresh block data before multicall\n await safelyExecuteWithTimeout(() =>\n blockTracker?.checkForLatestBlock?.(),\n );\n\n // Fetch native balances\n if (hasProperty(SINGLE_CALL_BALANCES_ADDRESS_BY_CHAINID, chainId)) {\n const contractAddress = SINGLE_CALL_BALANCES_ADDRESS_BY_CHAINID[\n chainId\n ] as string;\n\n const contract = new Contract(\n contractAddress,\n abiSingleCallBalancesContract,\n this.#getProvider(chainId),\n );\n\n const nativeBalances = await safelyExecuteWithTimeout(\n () =>\n contract.balances(accountsToUpdate, [ZERO_ADDRESS]) as Promise<\n BigNumber[]\n >,\n false,\n 3_000, // 3s max call for multicall contract call\n );\n\n if (nativeBalances) {\n accountsToUpdate.forEach((address, index) => {\n chainResults.push({\n success: true,\n value: new BN(nativeBalances[index].toString()),\n account: address,\n token: ZERO_ADDRESS,\n chainId,\n });\n });\n }\n } else {\n // Process accounts in batches using reduceInBatchesSerially\n await reduceInBatchesSerially<string, void>({\n values: accountsToUpdate,\n batchSize: TOKEN_PRICES_BATCH_SIZE,\n initialResult: undefined,\n eachBatch: async (workingResult: void, batch: string[]) => {\n const balancePromises = batch.map(async (address: string) => {\n const balanceResult = await this.#getBalanceFromChain(\n address,\n ethQuery,\n ).catch(() => null);\n\n if (balanceResult) {\n chainResults.push({\n success: true,\n value: new BN(balanceResult.replace('0x', ''), 16),\n account: address as ChecksumAddress,\n token: ZERO_ADDRESS,\n chainId,\n });\n } else {\n chainResults.push({\n success: false,\n account: address as ChecksumAddress,\n token: ZERO_ADDRESS,\n chainId,\n });\n }\n });\n\n await Promise.allSettled(balancePromises);\n return workingResult;\n },\n });\n }\n\n // Fetch staked balances if enabled\n if (this.#includeStakedAssets) {\n const stakedBalancesPromise = this.#getStakedBalanceForChain(\n accountsToUpdate,\n chainId,\n );\n\n const stakedBalanceResult = await safelyExecuteWithTimeout(\n async () =>\n (await stakedBalancesPromise) as Record<string, StakedBalance>,\n );\n\n if (stakedBalanceResult) {\n // Find the staking contract address for this chain\n const stakingContractAddress =\n STAKING_CONTRACT_ADDRESS_BY_CHAINID[\n chainId as keyof typeof STAKING_CONTRACT_ADDRESS_BY_CHAINID\n ];\n\n if (stakingContractAddress) {\n Object.entries(stakedBalanceResult).forEach(\n ([address, balance]) => {\n chainResults.push({\n success: true,\n value: balance\n ? new BN(balance.replace('0x', ''), 16)\n : new BN('0'),\n account: address as ChecksumAddress,\n token: toChecksumHexAddress(\n stakingContractAddress,\n ) as ChecksumAddress,\n chainId,\n });\n },\n );\n }\n }\n }\n\n return chainResults;\n });\n\n // Wait for all chains to complete (or fail) and collect results\n const chainResultsArray = await Promise.allSettled(chainProcessingPromises);\n const results: ProcessedBalance[] = [];\n\n chainResultsArray.forEach((chainResult) => {\n if (chainResult.status === 'fulfilled') {\n results.push(...chainResult.value);\n } else {\n // Log error but continue with other chains\n console.warn('Chain processing failed:', chainResult.reason);\n }\n });\n\n return results;\n }\n\n /**\n * Fetches the balance of a given address from the blockchain.\n *\n * @param address - The account address to fetch the balance for.\n * @param ethQuery - The EthQuery instance to query getBalance with.\n * @returns A promise that resolves to the balance in a hex string format.\n */\n async #getBalanceFromChain(\n address: string,\n ethQuery?: EthQuery,\n ): Promise<string | undefined> {\n return await safelyExecuteWithTimeout(async () => {\n assert(ethQuery, 'Provider not set.');\n return await query(ethQuery, 'getBalance', [address]);\n });\n }\n}\n\n/**\n * AccountInformation\n *\n * Account information object\n *\n * balance - Hex string of an account balance in wei\n *\n * stakedBalance - Hex string of an account staked balance in wei\n */\nexport type AccountInformation = {\n balance: string;\n stakedBalance?: string;\n};\n\n/**\n * AccountTrackerControllerState\n *\n * Account tracker controller state\n *\n * accountsByChainId - Map of addresses to account information by chain\n */\nexport type AccountTrackerControllerState = {\n accountsByChainId: Record<string, { [address: string]: AccountInformation }>;\n};\n\nconst accountTrackerMetadata = {\n accountsByChainId: {\n persist: true,\n anonymous: false,\n },\n};\n\n/**\n * The action that can be performed to get the state of the {@link AccountTrackerController}.\n */\nexport type AccountTrackerControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n AccountTrackerControllerState\n>;\n\n/**\n * The action that can be performed to update multiple native token balances in batch.\n */\nexport type AccountTrackerUpdateNativeBalancesAction = {\n type: `${typeof controllerName}:updateNativeBalances`;\n handler: AccountTrackerController['updateNativeBalances'];\n};\n\n/**\n * The action that can be performed to update multiple staked balances in batch.\n */\nexport type AccountTrackerUpdateStakedBalancesAction = {\n type: `${typeof controllerName}:updateStakedBalances`;\n handler: AccountTrackerController['updateStakedBalances'];\n};\n\n/**\n * The actions that can be performed using the {@link AccountTrackerController}.\n */\nexport type AccountTrackerControllerActions =\n | AccountTrackerControllerGetStateAction\n | AccountTrackerUpdateNativeBalancesAction\n | AccountTrackerUpdateStakedBalancesAction;\n\n/**\n * The messenger of the {@link AccountTrackerController} for communication.\n */\nexport type AllowedActions =\n | AccountsControllerListAccountsAction\n | PreferencesControllerGetStateAction\n | AccountsControllerGetSelectedAccountAction\n | NetworkControllerGetStateAction\n | NetworkControllerGetNetworkClientByIdAction;\n\n/**\n * The event that {@link AccountTrackerController} can emit.\n */\nexport type AccountTrackerControllerStateChangeEvent =\n ControllerStateChangeEvent<\n typeof controllerName,\n AccountTrackerControllerState\n >;\n\n/**\n * The events that {@link AccountTrackerController} can emit.\n */\nexport type AccountTrackerControllerEvents =\n AccountTrackerControllerStateChangeEvent;\n\n/**\n * The external events available to the {@link AccountTrackerController}.\n */\nexport type AllowedEvents =\n | AccountsControllerSelectedEvmAccountChangeEvent\n | AccountsControllerSelectedAccountChangeEvent;\n\n/**\n * The messenger of the {@link AccountTrackerController}.\n */\nexport type AccountTrackerControllerMessenger = RestrictedMessenger<\n typeof controllerName,\n AccountTrackerControllerActions | AllowedActions,\n AccountTrackerControllerEvents | AllowedEvents,\n AllowedActions['type'],\n AllowedEvents['type']\n>;\n\n/** The input to start polling for the {@link AccountTrackerController} */\ntype AccountTrackerPollingInput = {\n networkClientIds: NetworkClientId[];\n};\n\n/**\n * Controller that tracks the network balances for all user accounts.\n */\nexport class AccountTrackerController extends StaticIntervalPollingController<AccountTrackerPollingInput>()<\n typeof controllerName,\n AccountTrackerControllerState,\n AccountTrackerControllerMessenger\n> {\n readonly #refreshMutex = new Mutex();\n\n readonly #includeStakedAssets: boolean;\n\n readonly #getStakedBalanceForChain: AssetsContractController['getStakedBalanceForChain'];\n\n readonly #balanceFetchers: BalanceFetcher[];\n\n /**\n * Creates an AccountTracker instance.\n *\n * @param options - The controller options.\n * @param options.interval - Polling interval used to fetch new account balances.\n * @param options.state - Initial state to set on this controller.\n * @param options.messenger - The controller messaging system.\n * @param options.getStakedBalanceForChain - The function to get the staked native asset balance for a chain.\n * @param options.includeStakedAssets - Whether to include staked assets in the account balances.\n * @param options.useAccountsAPI - Enable Accounts‑API strategy (if supported chain).\n * @param options.allowExternalServices - Disable external HTTP calls (privacy / offline mode).\n */\n constructor({\n interval = 10000,\n state,\n messenger,\n getStakedBalanceForChain,\n includeStakedAssets = false,\n useAccountsAPI = false,\n allowExternalServices = () => true,\n }: {\n interval?: number;\n state?: Partial<AccountTrackerControllerState>;\n messenger: AccountTrackerControllerMessenger;\n getStakedBalanceForChain: AssetsContractController['getStakedBalanceForChain'];\n includeStakedAssets?: boolean;\n useAccountsAPI?: boolean;\n allowExternalServices?: () => boolean;\n }) {\n const { selectedNetworkClientId } = messenger.call(\n 'NetworkController:getState',\n );\n const {\n configuration: { chainId },\n } = messenger.call(\n 'NetworkController:getNetworkClientById',\n selectedNetworkClientId,\n );\n super({\n name: controllerName,\n messenger,\n state: {\n accountsByChainId: {\n [chainId]: {},\n },\n ...state,\n },\n metadata: accountTrackerMetadata,\n });\n this.#getStakedBalanceForChain = getStakedBalanceForChain;\n\n this.#includeStakedAssets = includeStakedAssets;\n\n // Initialize balance fetchers - Strategy order: API first, then RPC fallback\n this.#balanceFetchers = [\n ...(useAccountsAPI && allowExternalServices()\n ? [new AccountsApiBalanceFetcher('extension', this.#getProvider)]\n : []),\n new AccountTrackerRpcBalanceFetcher(\n this.#getProvider,\n this.#getNetworkClient,\n includeStakedAssets,\n getStakedBalanceForChain,\n ),\n ];\n\n this.setIntervalLength(interval);\n\n this.messagingSystem.subscribe(\n 'AccountsController:selectedEvmAccountChange',\n (newAddress, prevAddress) => {\n if (newAddress !== prevAddress) {\n // Making an async call for this new event\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n this.refresh(this.#getNetworkClientIds());\n }\n },\n (event): string => event.address,\n );\n\n this.#registerMessageHandlers();\n }\n\n private syncAccounts(newChainIds: string[]) {\n const accountsByChainId = cloneDeep(this.state.accountsByChainId);\n const { selectedNetworkClientId } = this.messagingSystem.call(\n 'NetworkController:getState',\n );\n const {\n configuration: { chainId: currentChainId },\n } = this.messagingSystem.call(\n 'NetworkController:getNetworkClientById',\n selectedNetworkClientId,\n );\n\n const existing = Object.keys(accountsByChainId?.[currentChainId] ?? {});\n\n // Initialize new chain IDs if they don't exist\n newChainIds.forEach((newChainId) => {\n if (!accountsByChainId[newChainId]) {\n accountsByChainId[newChainId] = {};\n existing.forEach((address) => {\n accountsByChainId[newChainId][address] = { balance: '0x0' };\n });\n }\n });\n\n // Note: The address from the preferences controller are checksummed\n // The addresses from the accounts controller are lowercased\n const addresses = Object.values(\n this.messagingSystem\n .call('AccountsController:listAccounts')\n .map((internalAccount) =>\n toChecksumHexAddress(internalAccount.address),\n ),\n );\n const newAddresses = addresses.filter(\n (address) => !existing.includes(address),\n );\n const oldAddresses = existing.filter(\n (address) => !addresses.includes(address),\n );\n Object.keys(accountsByChainId).forEach((chainId) => {\n newAddresses.forEach((address) => {\n accountsByChainId[chainId][address] = {\n balance: '0x0',\n };\n });\n });\n\n Object.keys(accountsByChainId).forEach((chainId) => {\n oldAddresses.forEach((address) => {\n delete accountsByChainId[chainId][address];\n });\n });\n\n if (!isEqual(this.state.accountsByChainId, accountsByChainId)) {\n this.update((state) => {\n state.accountsByChainId = accountsByChainId;\n });\n }\n }\n\n readonly #getProvider = (chainId: Hex): Web3Provider => {\n const { networkConfigurationsByChainId } = this.messagingSystem.call(\n 'NetworkController:getState',\n );\n const cfg = networkConfigurationsByChainId[chainId];\n const { networkClientId } = cfg.rpcEndpoints[cfg.defaultRpcEndpointIndex];\n const client = this.messagingSystem.call(\n 'NetworkController:getNetworkClientById',\n networkClientId,\n );\n return new Web3Provider(client.provider);\n };\n\n readonly #getNetworkClient = (chainId: Hex) => {\n const { networkConfigurationsByChainId } = this.messagingSystem.call(\n 'NetworkController:getState',\n );\n const cfg = networkConfigurationsByChainId[chainId];\n const { networkClientId } = cfg.rpcEndpoints[cfg.defaultRpcEndpointIndex];\n return this.messagingSystem.call(\n 'NetworkController:getNetworkClientById',\n networkClientId,\n );\n };\n\n /**\n * Resolves a networkClientId to a network client config\n * or globally selected network config if not provided\n *\n * @param networkClientId - Optional networkClientId to fetch a network client with\n * @returns network client config\n */\n #getCorrectNetworkClient(networkClientId?: NetworkClientId) {\n const selectedNetworkClientId =\n networkClientId ??\n this.messagingSystem.call('NetworkController:getState')\n .selectedNetworkClientId;\n const {\n configuration: { chainId },\n provider,\n blockTracker,\n } = this.messagingSystem.call(\n 'NetworkController:getNetworkClientById',\n selectedNetworkClientId,\n );\n\n return {\n chainId,\n provider,\n ethQuery: new EthQuery(provider),\n blockTracker,\n };\n }\n\n /**\n * Retrieves the list of network client IDs.\n *\n * @returns An array of network client IDs.\n */\n #getNetworkClientIds(): NetworkClientId[] {\n const { networkConfigurationsByChainId } = this.messagingSystem.call(\n 'NetworkController:getState',\n );\n return Object.values(networkConfigurationsByChainId).flatMap(\n (networkConfiguration) =>\n networkConfiguration.rpcEndpoints.map(\n (rpcEndpoint) => rpcEndpoint.networkClientId,\n ),\n );\n }\n\n /**\n * Refreshes the balances of the accounts using the networkClientId\n *\n * @param input - The input for the poll.\n * @param input.networkClientIds - The network client IDs used to get balances.\n */\n async _executePoll({\n networkClientIds,\n }: AccountTrackerPollingInput): Promise<void> {\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n this.refresh(networkClientIds);\n }\n\n /**\n * Refreshes the balances of the accounts depending on the multi-account setting.\n * If multi-account is disabled, only updates the selected account balance.\n * If multi-account is enabled, updates balances for all accounts.\n *\n * @param networkClientIds - Optional network client IDs to fetch a network client with\n */\n async refresh(networkClientIds: NetworkClientId[]) {\n const selectedAccount = this.messagingSystem.call(\n 'AccountsController:getSelectedAccount',\n );\n const allAccounts = this.messagingSystem.call(\n 'AccountsController:listAccounts',\n );\n const { isMultiAccountBalancesEnabled } = this.messagingSystem.call(\n 'PreferencesController:getState',\n );\n\n const releaseLock = await this.#refreshMutex.acquire();\n try {\n const chainIds = networkClientIds.map((networkClientId) => {\n const { chainId } = this.#getCorrectNetworkClient(networkClientId);\n return chainId;\n });\n\n this.syncAccounts(chainIds);\n\n // Use balance fetchers with fallback strategy\n const aggregated: ProcessedBalance[] = [];\n let remainingChains = [...chainIds] as ChainIdHex[];\n\n // Try each fetcher in order, removing successfully processed chains\n for (const fetcher of this.#balanceFetchers) {\n const supportedChains = remainingChains.filter((c) =>\n fetcher.supports(c),\n );\n if (!supportedChains.length) {\n continue;\n }\n\n try {\n const balances = await fetcher.fetch({\n chainIds: supportedChains,\n queryAllAccounts: isMultiAccountBalancesEnabled,\n selectedAccount: toChecksumHexAddress(\n selectedAccount.address,\n ) as ChecksumAddress,\n allAccounts,\n });\n\n if (balances && balances.length > 0) {\n aggregated.push(...balances);\n // Remove chains that were successfully processed\n const processedChains = new Set(balances.map((b) => b.chainId));\n remainingChains = remainingChains.filter(\n (chain) => !processedChains.has(chain),\n );\n }\n } catch (error) {\n console.warn(\n `Balance fetcher failed for chains ${supportedChains.join(', ')}: ${String(error)}`,\n );\n // Continue to next fetcher (fallback)\n }\n\n // If all chains have been processed, break early\n if (remainingChains.length === 0) {\n break;\n }\n }\n\n // Build a _copy_ of the current state and track whether anything changed\n const nextAccountsByChainId: AccountTrackerControllerState['accountsByChainId'] =\n cloneDeep(this.state.accountsByChainId);\n let hasChanges = false;\n\n // Process the aggregated balance results\n const stakedBalancesByChainAndAddress: Record<\n string,\n Record<string, string>\n > = {};\n\n aggregated.forEach(({ success, value, account, token, chainId }) => {\n if (success && value !== undefined) {\n const checksumAddress = toChecksumHexAddress(account);\n const hexValue = `0x${value.toString(16)}`;\n\n if (token === ZERO_ADDRESS) {\n // Native balance\n if (\n nextAccountsByChainId[chainId][checksumAddress].balance !==\n hexValue\n ) {\n nextAccountsByChainId[chainId][checksumAddress].balance =\n hexValue;\n hasChanges = true;\n }\n } else {\n // Staked balance (from staking contract address)\n if (!stakedBalancesByChainAndAddress[chainId]) {\n stakedBalancesByChainAndAddress[chainId] = {};\n }\n stakedBalancesByChainAndAddress[chainId][checksumAddress] =\n hexValue;\n }\n }\n });\n\n // Apply staked balances\n Object.entries(stakedBalancesByChainAndAddress).forEach(\n ([chainId, balancesByAddress]) => {\n Object.entries(balancesByAddress).forEach(\n ([address, stakedBalance]) => {\n if (\n nextAccountsByChainId[chainId][address].stakedBalance !==\n stakedBalance\n ) {\n nextAccountsByChainId[chainId][address].stakedBalance =\n stakedBalance;\n hasChanges = true;\n }\n },\n );\n },\n );\n\n // Only update state if something changed\n if (hasChanges) {\n this.update((state) => {\n state.accountsByChainId = nextAccountsByChainId;\n });\n }\n } finally {\n releaseLock();\n }\n }\n\n /**\n * Sync accounts balances with some additional addresses.\n *\n * @param addresses - the additional addresses, may be hardware wallet addresses.\n * @param networkClientId - Optional networkClientId to fetch a network client with.\n * @returns accounts - addresses with synced balance\n */\n async syncBalanceWithAddresses(\n addresses: string[],\n networkClientId?: NetworkClientId,\n ): Promise<\n Record<string, { balance: string; stakedBalance?: StakedBalance }>\n > {\n const { ethQuery } = this.#getCorrectNetworkClient(networkClientId);\n\n // TODO: This should use multicall when enabled by the user.\n return await Promise.all(\n addresses.map(\n (address): Promise<[string, string, StakedBalance] | undefined> => {\n return safelyExecuteWithTimeout(async () => {\n assert(ethQuery, 'Provider not set.');\n const balance = await query(ethQuery, 'getBalance', [address]);\n\n let stakedBalance: StakedBalance;\n if (this.#includeStakedAssets) {\n stakedBalance = (\n await this.#getStakedBalanceForChain([address], networkClientId)\n )[address];\n }\n return [address, balance, stakedBalance];\n });\n },\n ),\n ).then((value) => {\n return value.reduce((obj, item) => {\n if (!item) {\n return obj;\n }\n\n const [address, balance, stakedBalance] = item;\n return {\n ...obj,\n [address]: {\n balance,\n stakedBalance,\n },\n };\n }, {});\n });\n }\n\n /**\n * Updates the balances of multiple native tokens in a single batch operation.\n * This is more efficient than calling updateNativeToken multiple times as it\n * triggers only one state update.\n *\n * @param balances - Array of balance updates, each containing address, chainId, and balance.\n */\n updateNativeBalances(\n balances: { address: string; chainId: Hex; balance: Hex }[],\n ) {\n this.update((state) => {\n balances.forEach(({ address, chainId, balance }) => {\n const checksumAddress = toChecksumHexAddress(address);\n\n // Ensure the chainId exists in the state\n if (!state.accountsByChainId[chainId]) {\n state.accountsByChainId[chainId] = {};\n }\n\n // Ensure the address exists for this chain\n if (!state.accountsByChainId[chainId][checksumAddress]) {\n state.accountsByChainId[chainId][checksumAddress] = {\n balance: '0x0',\n };\n }\n\n // Update the balance\n state.accountsByChainId[chainId][checksumAddress].balance = balance;\n });\n });\n }\n\n /**\n * Updates the staked balances of multiple accounts in a single batch operation.\n * This is more efficient than updating staked balances individually as it\n * triggers only one state update.\n *\n * @param stakedBalances - Array of staked balance updates, each containing address, chainId, and stakedBalance.\n */\n updateStakedBalances(\n stakedBalances: {\n address: string;\n chainId: Hex;\n stakedBalance: StakedBalance;\n }[],\n ) {\n this.update((state) => {\n stakedBalances.forEach(({ address, chainId, stakedBalance }) => {\n const checksumAddress = toChecksumHexAddress(address);\n\n // Ensure the chainId exists in the state\n if (!state.accountsByChainId[chainId]) {\n state.accountsByChainId[chainId] = {};\n }\n\n // Ensure the address exists for this chain\n if (!state.accountsByChainId[chainId][checksumAddress]) {\n state.accountsByChainId[chainId][checksumAddress] = {\n balance: '0x0',\n };\n }\n\n // Update the staked balance\n state.accountsByChainId[chainId][checksumAddress].stakedBalance =\n stakedBalance;\n });\n });\n }\n\n #registerMessageHandlers() {\n this.messagingSystem.registerActionHandler(\n `${controllerName}:updateNativeBalances` as const,\n this.updateNativeBalances.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:updateStakedBalances` as const,\n this.updateStakedBalances.bind(this),\n );\n }\n}\n\nexport default AccountTrackerController;\n"]}
@@ -159,7 +159,7 @@ export declare class AccountTrackerController extends AccountTrackerController_b
159
159
  updateNativeBalances(balances: {
160
160
  address: string;
161
161
  chainId: Hex;
162
- balance: string;
162
+ balance: Hex;
163
163
  }[]): void;
164
164
  /**
165
165
  * Updates the staked balances of multiple accounts in a single batch operation.
@@ -1 +1 @@
1
- {"version":3,"file":"AccountTrackerController.d.cts","sourceRoot":"","sources":["../src/AccountTrackerController.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,+CAA+C,EAC/C,0CAA0C,EAC1C,oCAAoC,EACpC,4CAA4C,EAC7C,sCAAsC;AACvC,OAAO,KAAK,EACV,0BAA0B,EAC1B,wBAAwB,EACxB,mBAAmB,EACpB,kCAAkC;AAOnC,OAAO,KAAK,EAEV,eAAe,EACf,2CAA2C,EAC3C,+BAA+B,EAChC,qCAAqC;AAEtC,OAAO,KAAK,EAAE,mCAAmC,EAAE,yCAAyC;AAC5F,OAAO,EAAuB,KAAK,GAAG,EAAE,wBAAwB;AAMhE,OAAO,EAGL,KAAK,wBAAwB,EAC7B,KAAK,aAAa,EACnB,uCAAmC;AAQpC;;GAEG;AACH,QAAA,MAAM,cAAc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C;QAChB,OAAO,EAAE,GAAG,CAAC;QACb,aAAa,EAAE,aAAa,CAAC;KAC9B,EAAE;CAoCN;AAED,eAAe,wBAAwB,CAAC"}
@@ -159,7 +159,7 @@ export declare class AccountTrackerController extends AccountTrackerController_b
159
159
  updateNativeBalances(balances: {
160
160
  address: string;
161
161
  chainId: Hex;
162
- balance: string;
162
+ balance: Hex;
163
163
  }[]): void;
164
164
  /**
165
165
  * Updates the staked balances of multiple accounts in a single batch operation.
@@ -1 +1 @@
1
- {"version":3,"file":"AccountTrackerController.d.mts","sourceRoot":"","sources":["../src/AccountTrackerController.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,+CAA+C,EAC/C,0CAA0C,EAC1C,oCAAoC,EACpC,4CAA4C,EAC7C,sCAAsC;AACvC,OAAO,KAAK,EACV,0BAA0B,EAC1B,wBAAwB,EACxB,mBAAmB,EACpB,kCAAkC;AAOnC,OAAO,KAAK,EAEV,eAAe,EACf,2CAA2C,EAC3C,+BAA+B,EAChC,qCAAqC;AAEtC,OAAO,KAAK,EAAE,mCAAmC,EAAE,yCAAyC;AAC5F,OAAO,EAAuB,KAAK,GAAG,EAAE,wBAAwB;AAMhE,OAAO,EAGL,KAAK,wBAAwB,EAC7B,KAAK,aAAa,EACnB,uCAAmC;AAQpC;;GAEG;AACH,QAAA,MAAM,cAAc,6BAA6B,CAAC;AAElD,MAAM,MAAM,UAAU,GAAG,GAAG,CAAC;AAC7B,MAAM,MAAM,eAAe,GAAG,GAAG,CAAC;AA2MlC;;;;;;;;GAQG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,6BAA6B,GAAG;IAC1C,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,CAAC,OAAO,EAAE,MAAM,GAAG,kBAAkB,CAAA;KAAE,CAAC,CAAC;C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,CAAC;QAC7C,wBAAwB,EAAE,wBAAwB,CAAC,0BAA0B,CAAC,CAAC;QAC/E,mBAAmB,CAAC,EAAE,OAAO,CAAC;QAC9B,cAAc,CAAC,EAAE,OAAO,CAAC;QACzB,qBAAqB,CAAC,EAAE,MAAM,OAAO,CAAC;KACvC;IAuDD,OAAO,CAAC,YAAY;IAmIpB;;;;;OAKG;IACG,YAAY,CAAC,EACjB,gBAAgB,GACjB,EAAE,0BAA0B,GAAG,OAAO,CAAC,IAAI,CAAC;IAM7C;;;;;;OAMG;IACG,OAAO,CAAC,gBAAgB,EAAE,eAAe,EAAE;IAkIjD;;;;;;OAMG;IACG,wBAAwB,CAC5B,SAAS,EAAE,MAAM,EAAE,EACnB,eAAe,CAAC,EAAE,eAAe,GAChC,OAAO,CACR,MAAM,CAAC,MAAM,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,aAAa,CAAC,EAAE,aAAa,CAAA;KAAE,CAAC,CACnE;IAuCD;;;;;;OAMG;IACH,oBAAoB,CAClB,QAAQ,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,GAAG,CAAC;QAAC,OAAO,EAAE,GAAG,CAAA;KAAE,EAAE;IAwB7D;;;;;;OAMG;IACH,oBAAoB,CAClB,cAAc,EAAE;QACd,OAAO,EAAE,MAAM,CAAC;QAChB,OAAO,EAAE,GAAG,CAAC;QACb,aAAa,EAAE,aAAa,CAAC;KAC9B,EAAE;CAoCN;AAED,eAAe,wBAAwB,CAAC"}
@@ -350,11 +350,14 @@ export class AccountTrackerController extends StaticIntervalPollingController()
350
350
  const stakedBalancesByChainAndAddress = {};
351
351
  aggregated.forEach(({ success, value, account, token, chainId }) => {
352
352
  if (success && value !== undefined) {
353
+ const checksumAddress = toChecksumHexAddress(account);
353
354
  const hexValue = `0x${value.toString(16)}`;
354
355
  if (token === ZERO_ADDRESS) {
355
356
  // Native balance
356
- if (nextAccountsByChainId[chainId][account].balance !== hexValue) {
357
- nextAccountsByChainId[chainId][account].balance = hexValue;
357
+ if (nextAccountsByChainId[chainId][checksumAddress].balance !==
358
+ hexValue) {
359
+ nextAccountsByChainId[chainId][checksumAddress].balance =
360
+ hexValue;
358
361
  hasChanges = true;
359
362
  }
360
363
  }
@@ -363,7 +366,8 @@ export class AccountTrackerController extends StaticIntervalPollingController()
363
366
  if (!stakedBalancesByChainAndAddress[chainId]) {
364
367
  stakedBalancesByChainAndAddress[chainId] = {};
365
368
  }
366
- stakedBalancesByChainAndAddress[chainId][account] = hexValue;
369
+ stakedBalancesByChainAndAddress[chainId][checksumAddress] =
370
+ hexValue;
367
371
  }
368
372
  }
369
373
  });
@@ -435,16 +439,19 @@ export class AccountTrackerController extends StaticIntervalPollingController()
435
439
  updateNativeBalances(balances) {
436
440
  this.update((state) => {
437
441
  balances.forEach(({ address, chainId, balance }) => {
442
+ const checksumAddress = toChecksumHexAddress(address);
438
443
  // Ensure the chainId exists in the state
439
444
  if (!state.accountsByChainId[chainId]) {
440
445
  state.accountsByChainId[chainId] = {};
441
446
  }
442
447
  // Ensure the address exists for this chain
443
- if (!state.accountsByChainId[chainId][address]) {
444
- state.accountsByChainId[chainId][address] = { balance: '0x0' };
448
+ if (!state.accountsByChainId[chainId][checksumAddress]) {
449
+ state.accountsByChainId[chainId][checksumAddress] = {
450
+ balance: '0x0',
451
+ };
445
452
  }
446
453
  // Update the balance
447
- state.accountsByChainId[chainId][address].balance = balance;
454
+ state.accountsByChainId[chainId][checksumAddress].balance = balance;
448
455
  });
449
456
  });
450
457
  }
@@ -458,16 +465,20 @@ export class AccountTrackerController extends StaticIntervalPollingController()
458
465
  updateStakedBalances(stakedBalances) {
459
466
  this.update((state) => {
460
467
  stakedBalances.forEach(({ address, chainId, stakedBalance }) => {
468
+ const checksumAddress = toChecksumHexAddress(address);
461
469
  // Ensure the chainId exists in the state
462
470
  if (!state.accountsByChainId[chainId]) {
463
471
  state.accountsByChainId[chainId] = {};
464
472
  }
465
473
  // Ensure the address exists for this chain
466
- if (!state.accountsByChainId[chainId][address]) {
467
- state.accountsByChainId[chainId][address] = { balance: '0x0' };
474
+ if (!state.accountsByChainId[chainId][checksumAddress]) {
475
+ state.accountsByChainId[chainId][checksumAddress] = {
476
+ balance: '0x0',
477
+ };
468
478
  }
469
479
  // Update the staked balance
470
- state.accountsByChainId[chainId][address].stakedBalance = stakedBalance;
480
+ state.accountsByChainId[chainId][checksumAddress].stakedBalance =
481
+ stakedBalance;
471
482
  });
472
483
  });
473
484
  }