@metamask-previews/assets-controller 6.2.1-preview-56dd1249f → 6.2.1-preview-c3dc0c91e
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 +1 -10
- package/dist/AssetsController.cjs +3 -89
- package/dist/AssetsController.cjs.map +1 -1
- package/dist/AssetsController.d.cts +3 -5
- package/dist/AssetsController.d.cts.map +1 -1
- package/dist/AssetsController.d.mts +3 -5
- package/dist/AssetsController.d.mts.map +1 -1
- package/dist/AssetsController.mjs +3 -89
- package/dist/AssetsController.mjs.map +1 -1
- package/dist/index.cjs +1 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +0 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +0 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +0 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
- package/dist/defaults.cjs +0 -101
- package/dist/defaults.cjs.map +0 -1
- package/dist/defaults.d.cts +0 -50
- package/dist/defaults.d.cts.map +0 -1
- package/dist/defaults.d.mts +0 -50
- package/dist/defaults.d.mts.map +0 -1
- package/dist/defaults.mjs +0 -95
- package/dist/defaults.mjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,18 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
-
### Added
|
|
11
|
-
|
|
12
|
-
- Seed mUSD (`0xaca92e438df0b2401ff60da7e4337b687a2435da`) as a default tracked asset on Ethereum mainnet (`eip155:1`), Linea (`eip155:59144`), and Monad testnet (`eip155:143`) ([#8616](https://github.com/MetaMask/core/pull/8616))
|
|
13
|
-
- `assetsInfo` is pre-populated in default controller state so mUSD metadata is available before any on-chain fetch completes.
|
|
14
|
-
- Zero-balance entries are written into `assetsBalance` at startup, on account/network changes, and immediately when the user adds a chain that has default tracked assets.
|
|
15
|
-
- New exports: `DEFAULT_TRACKED_ASSETS_BY_CHAIN`, `CHAINS_WITH_DEFAULT_TRACKED_ASSETS`, `DEFAULT_ASSET_METADATA`, `buildDefaultAssetsInfo`, `getDefaultTrackedAssetsForChain`, `getDefaultAssetMetadata`.
|
|
16
|
-
|
|
17
10
|
### Changed
|
|
18
11
|
|
|
19
|
-
- Bump `@metamask/keyring-api` from `^
|
|
20
|
-
- Bump `@metamask/keyring-internal-api` from `^10.1.1` to `^11.0.1` ([#8584](https://github.com/MetaMask/core/pull/8584), [#8647](https://github.com/MetaMask/core/pull/8647))
|
|
21
|
-
- Bump `@metamask/keyring-snap-client` from `^9.0.1` to `^9.0.2` ([#8647](https://github.com/MetaMask/core/pull/8647))
|
|
12
|
+
- Bump `@metamask/keyring-internal-api` from `^10.1.1` to `^11.0.0` ([#8584](https://github.com/MetaMask/core/pull/8584))
|
|
22
13
|
- Bump `@metamask/messenger` from `^1.1.1` to `^1.2.0` ([#8632](https://github.com/MetaMask/core/pull/8632))
|
|
23
14
|
- Bump `@metamask/keyring-controller` from `^25.2.0` to `^25.3.0` ([#8634](https://github.com/MetaMask/core/pull/8634))
|
|
24
15
|
- Bump `@metamask/network-controller` from `^30.0.1` to `^30.1.0` ([#8636](https://github.com/MetaMask/core/pull/8636))
|
|
@@ -13,7 +13,7 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
|
|
|
13
13
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
14
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
15
|
};
|
|
16
|
-
var _AssetsController_instances, _AssetsController_isEnabled, _AssetsController_isBasicFunctionality, _AssetsController_defaultUpdateInterval, _AssetsController_trace, _AssetsController_captureException, _AssetsController_firstInitFetchReported, _AssetsController_stateSizeReported, _AssetsController_emitTrace, _AssetsController_emitStateSizeTrace, _AssetsController_uiOpen, _AssetsController_keyringUnlocked, _AssetsController_controllerMutex, _AssetsController_activeSubscriptions, _AssetsController_enabledChains, _AssetsController_lastKnownAccountIds, _AssetsController_getSelectedAccounts, _AssetsController_backendWebsocketDataSource, _AssetsController_accountsApiDataSource, _AssetsController_snapDataSource, _AssetsController_rpcDataSource, _AssetsController_stakedBalanceDataSource, _AssetsController_allBalanceDataSources_get, _AssetsController_priceDataSource, _AssetsController_detectionMiddleware, _AssetsController_customAssetGraduationMiddleware, _AssetsController_rpcFallbackMiddleware, _AssetsController_tokenDataSource, _AssetsController_unsubscribeBasicFunctionality, _AssetsController_queryApiClient, _AssetsController_onActiveChainsUpdated, _AssetsController_initializeNativeAssetsMap, _AssetsController_initializeState, _AssetsController_extractEnabledChains, _AssetsController_normalizeChainReference, _AssetsController_subscribeToEvents, _AssetsController_onUnapprovedTransactionAdded, _AssetsController_updateActive, _AssetsController_handleAccountTreeStateChange, _AssetsController_registerActionHandlers, _AssetsController_handleActiveChainsUpdate, _AssetsController_executeMiddlewares, _AssetsController_getNativeAssetMap, _AssetsController_isNativeAsset, _AssetsController_resolveNativeAssetIds, _AssetsController_getNativeAssetIdsForEnabledChains, _AssetsController_getNativeAssetIdsForAccount, _AssetsController_ensureNativeBalancesDefaultZero,
|
|
16
|
+
var _AssetsController_instances, _AssetsController_isEnabled, _AssetsController_isBasicFunctionality, _AssetsController_defaultUpdateInterval, _AssetsController_trace, _AssetsController_captureException, _AssetsController_firstInitFetchReported, _AssetsController_stateSizeReported, _AssetsController_emitTrace, _AssetsController_emitStateSizeTrace, _AssetsController_uiOpen, _AssetsController_keyringUnlocked, _AssetsController_controllerMutex, _AssetsController_activeSubscriptions, _AssetsController_enabledChains, _AssetsController_lastKnownAccountIds, _AssetsController_getSelectedAccounts, _AssetsController_backendWebsocketDataSource, _AssetsController_accountsApiDataSource, _AssetsController_snapDataSource, _AssetsController_rpcDataSource, _AssetsController_stakedBalanceDataSource, _AssetsController_allBalanceDataSources_get, _AssetsController_priceDataSource, _AssetsController_detectionMiddleware, _AssetsController_customAssetGraduationMiddleware, _AssetsController_rpcFallbackMiddleware, _AssetsController_tokenDataSource, _AssetsController_unsubscribeBasicFunctionality, _AssetsController_queryApiClient, _AssetsController_onActiveChainsUpdated, _AssetsController_initializeNativeAssetsMap, _AssetsController_initializeState, _AssetsController_extractEnabledChains, _AssetsController_normalizeChainReference, _AssetsController_subscribeToEvents, _AssetsController_onUnapprovedTransactionAdded, _AssetsController_updateActive, _AssetsController_handleAccountTreeStateChange, _AssetsController_registerActionHandlers, _AssetsController_handleActiveChainsUpdate, _AssetsController_executeMiddlewares, _AssetsController_getNativeAssetMap, _AssetsController_isNativeAsset, _AssetsController_resolveNativeAssetIds, _AssetsController_getNativeAssetIdsForEnabledChains, _AssetsController_getNativeAssetIdsForAccount, _AssetsController_ensureNativeBalancesDefaultZero, _AssetsController_updateState, _AssetsController_getAssetsFromState, _AssetsController_shouldHideNativeToken, _AssetsController_tokenStandardToAssetType, _AssetsController_start, _AssetsController_stop, _AssetsController_subscribeAssets, _AssetsController_subscribeAssetsBalance, _AssetsController_subscribeRpcCustomAssetsSupplement, _AssetsController_unsubscribeBySubscriptionKey, _AssetsController_subscribeStakedBalance, _AssetsController_buildChainToAccountsMap, _AssetsController_subscribeDataSource, _AssetsController_unsubscribeDataSource, _AssetsController_buildDataRequest, _AssetsController_getEnabledChainsForAccount, _AssetsController_handleAccountGroupChanged, _AssetsController_handleEnabledNetworksChanged;
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
exports.AssetsController = exports.getDefaultAssetsControllerState = void 0;
|
|
19
19
|
const base_controller_1 = require("@metamask/base-controller");
|
|
@@ -30,7 +30,6 @@ const RpcDataSource_1 = require("./data-sources/RpcDataSource.cjs");
|
|
|
30
30
|
const SnapDataSource_1 = require("./data-sources/SnapDataSource.cjs");
|
|
31
31
|
const StakedBalanceDataSource_1 = require("./data-sources/StakedBalanceDataSource.cjs");
|
|
32
32
|
const TokenDataSource_1 = require("./data-sources/TokenDataSource.cjs");
|
|
33
|
-
const defaults_1 = require("./defaults.cjs");
|
|
34
33
|
const errors_1 = require("./errors.cjs");
|
|
35
34
|
const logger_1 = require("./logger.cjs");
|
|
36
35
|
const CustomAssetGraduationMiddleware_1 = require("./middlewares/CustomAssetGraduationMiddleware.cjs");
|
|
@@ -74,18 +73,11 @@ const log = (0, logger_1.createModuleLogger)(logger_1.projectLogger, CONTROLLER_
|
|
|
74
73
|
/**
|
|
75
74
|
* Returns the default state for AssetsController.
|
|
76
75
|
*
|
|
77
|
-
* @returns The default AssetsController state
|
|
78
|
-
* asset maps start empty; `assetsInfo` is pre-seeded for default tracked
|
|
79
|
-
* assets (see {@link buildDefaultAssetsInfo}).
|
|
76
|
+
* @returns The default AssetsController state with empty maps.
|
|
80
77
|
*/
|
|
81
78
|
function getDefaultAssetsControllerState() {
|
|
82
79
|
return {
|
|
83
|
-
|
|
84
|
-
// (e.g. mUSD on Ethereum mainnet, Linea, Monad) so they are
|
|
85
|
-
// immediately renderable in the UI before any RPC poll completes.
|
|
86
|
-
// Per-account zero-balance entries are filled into `assetsBalance`
|
|
87
|
-
// by `#ensureDefaultTrackedAssetsSeeded` once accounts are known.
|
|
88
|
-
assetsInfo: (0, defaults_1.buildDefaultAssetsInfo)(),
|
|
80
|
+
assetsInfo: {},
|
|
89
81
|
assetsBalance: {},
|
|
90
82
|
assetsPrice: {},
|
|
91
83
|
customAssets: {},
|
|
@@ -1034,15 +1026,6 @@ _AssetsController_isEnabled = new WeakMap(), _AssetsController_isBasicFunctional
|
|
|
1034
1026
|
this.messenger.subscribe('NetworkEnablementController:stateChange', ({ enabledNetworkMap }) => {
|
|
1035
1027
|
__classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_handleEnabledNetworksChanged).call(this, enabledNetworkMap).catch(console.error);
|
|
1036
1028
|
});
|
|
1037
|
-
// When a new network is added (e.g. the user finally adds Monad
|
|
1038
|
-
// to NetworkController), seed the default tracked assets for it
|
|
1039
|
-
// — but only if the chain is in our defaults registry. This is
|
|
1040
|
-
// what makes mUSD show up on Monad the moment the network is
|
|
1041
|
-
// configured, without waiting for it to also be enabled in
|
|
1042
|
-
// NetworkEnablementController.
|
|
1043
|
-
this.messenger.subscribe('NetworkController:networkAdded', (networkConfiguration) => {
|
|
1044
|
-
__classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_handleNetworkAdded).call(this, networkConfiguration.chainId);
|
|
1045
|
-
});
|
|
1046
1029
|
// Client + Keyring lifecycle: only run when UI is open AND keyring is unlocked
|
|
1047
1030
|
this.messenger.subscribe('ClientController:stateChange', (isUiOpen) => {
|
|
1048
1031
|
__classPrivateFieldSet(this, _AssetsController_uiOpen, isUiOpen, "f");
|
|
@@ -1111,7 +1094,6 @@ _AssetsController_isEnabled = new WeakMap(), _AssetsController_isBasicFunctional
|
|
|
1111
1094
|
__classPrivateFieldSet(this, _AssetsController_lastKnownAccountIds, currentIds, "f");
|
|
1112
1095
|
__classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_subscribeAssets).call(this);
|
|
1113
1096
|
__classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_ensureNativeBalancesDefaultZero).call(this);
|
|
1114
|
-
__classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_ensureDefaultTrackedAssetsSeeded).call(this);
|
|
1115
1097
|
this.getAssets(accounts, {
|
|
1116
1098
|
chainIds: [...__classPrivateFieldGet(this, _AssetsController_enabledChains, "f")],
|
|
1117
1099
|
forceUpdate: true,
|
|
@@ -1300,50 +1282,6 @@ async function _AssetsController_executeMiddlewares(sources, request, initialRes
|
|
|
1300
1282
|
}
|
|
1301
1283
|
}
|
|
1302
1284
|
});
|
|
1303
|
-
}, _AssetsController_ensureDefaultTrackedAssetsSeeded = function _AssetsController_ensureDefaultTrackedAssetsSeeded(chainsToSeed) {
|
|
1304
|
-
const accounts = __classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_getSelectedAccounts).call(this);
|
|
1305
|
-
if (accounts.length === 0) {
|
|
1306
|
-
return;
|
|
1307
|
-
}
|
|
1308
|
-
// Default tracked assets are ERC-20s on EVM chains today. Restrict
|
|
1309
|
-
// seeding to accounts that have at least one EVM scope so we don't
|
|
1310
|
-
// pollute non-EVM accounts. The wildcard `eip155:0` scope counts.
|
|
1311
|
-
const evmAccounts = accounts.filter((account) => (account.scopes ?? []).some((scope) => scope.startsWith('eip155:')));
|
|
1312
|
-
if (evmAccounts.length === 0) {
|
|
1313
|
-
return;
|
|
1314
|
-
}
|
|
1315
|
-
// Gate seeding on whether the chain is currently enabled. This is
|
|
1316
|
-
// why mUSD appears on mainnet/Linea immediately (those are normally
|
|
1317
|
-
// enabled at startup) but only appears on Monad once the user
|
|
1318
|
-
// turns the Monad network on.
|
|
1319
|
-
const candidateChains = chainsToSeed ?? [...__classPrivateFieldGet(this, _AssetsController_enabledChains, "f")];
|
|
1320
|
-
const targetChains = candidateChains.filter((chainId) => defaults_1.CHAINS_WITH_DEFAULT_TRACKED_ASSETS.has(chainId));
|
|
1321
|
-
if (targetChains.length === 0) {
|
|
1322
|
-
return;
|
|
1323
|
-
}
|
|
1324
|
-
this.update((state) => {
|
|
1325
|
-
var _a;
|
|
1326
|
-
const balances = state.assetsBalance;
|
|
1327
|
-
const metadata = state.assetsInfo;
|
|
1328
|
-
for (const chainId of targetChains) {
|
|
1329
|
-
const defaultAssetIds = defaults_1.DEFAULT_TRACKED_ASSETS_BY_CHAIN.get(chainId) ?? [];
|
|
1330
|
-
for (const assetId of defaultAssetIds) {
|
|
1331
|
-
// Re-seed metadata if state was hydrated from a prior version
|
|
1332
|
-
// that didn't include defaults.
|
|
1333
|
-
if (!metadata[assetId]) {
|
|
1334
|
-
const seed = (0, defaults_1.getDefaultAssetMetadata)(assetId);
|
|
1335
|
-
if (seed) {
|
|
1336
|
-
metadata[assetId] = seed;
|
|
1337
|
-
}
|
|
1338
|
-
}
|
|
1339
|
-
for (const account of evmAccounts) {
|
|
1340
|
-
balances[_a = account.id] ?? (balances[_a] = {});
|
|
1341
|
-
const accountBalances = balances[account.id];
|
|
1342
|
-
accountBalances[assetId] ?? (accountBalances[assetId] = { amount: '0' });
|
|
1343
|
-
}
|
|
1344
|
-
}
|
|
1345
|
-
}
|
|
1346
|
-
});
|
|
1347
1285
|
}, _AssetsController_updateState = async function _AssetsController_updateState(response) {
|
|
1348
1286
|
const normalizedResponse = normalizeResponse(response);
|
|
1349
1287
|
const mode = normalizedResponse.updateMode ?? 'merge';
|
|
@@ -1602,7 +1540,6 @@ async function _AssetsController_executeMiddlewares(sources, request, initialRes
|
|
|
1602
1540
|
__classPrivateFieldSet(this, _AssetsController_lastKnownAccountIds, new Set(accounts.map((a) => a.id)), "f");
|
|
1603
1541
|
__classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_subscribeAssets).call(this);
|
|
1604
1542
|
__classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_ensureNativeBalancesDefaultZero).call(this);
|
|
1605
|
-
__classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_ensureDefaultTrackedAssetsSeeded).call(this);
|
|
1606
1543
|
this.getAssets(accounts, {
|
|
1607
1544
|
chainIds,
|
|
1608
1545
|
forceUpdate: true,
|
|
@@ -1906,7 +1843,6 @@ async function _AssetsController_handleAccountGroupChanged() {
|
|
|
1906
1843
|
});
|
|
1907
1844
|
}
|
|
1908
1845
|
__classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_ensureNativeBalancesDefaultZero).call(this);
|
|
1909
|
-
__classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_ensureDefaultTrackedAssetsSeeded).call(this);
|
|
1910
1846
|
}, _AssetsController_handleEnabledNetworksChanged = async function _AssetsController_handleEnabledNetworksChanged(enabledNetworkMap) {
|
|
1911
1847
|
const previousChains = __classPrivateFieldGet(this, _AssetsController_enabledChains, "f");
|
|
1912
1848
|
__classPrivateFieldSet(this, _AssetsController_enabledChains, __classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_extractEnabledChains).call(this, enabledNetworkMap), "f");
|
|
@@ -1944,27 +1880,5 @@ async function _AssetsController_handleAccountGroupChanged() {
|
|
|
1944
1880
|
});
|
|
1945
1881
|
}
|
|
1946
1882
|
__classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_ensureNativeBalancesDefaultZero).call(this);
|
|
1947
|
-
// Seed default tracked assets (mUSD) for any chain the user has
|
|
1948
|
-
// *just* enabled. This is what makes mUSD appear on Monad after
|
|
1949
|
-
// the user finally adds it to NetworkEnablementController.
|
|
1950
|
-
if (addedChains.length > 0) {
|
|
1951
|
-
__classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_ensureDefaultTrackedAssetsSeeded).call(this, addedChains);
|
|
1952
|
-
}
|
|
1953
|
-
}, _AssetsController_handleNetworkAdded = function _AssetsController_handleNetworkAdded(hexChainId) {
|
|
1954
|
-
let caipChainId;
|
|
1955
|
-
try {
|
|
1956
|
-
caipChainId = `eip155:${parseInt(hexChainId, 16)}`;
|
|
1957
|
-
}
|
|
1958
|
-
catch {
|
|
1959
|
-
return;
|
|
1960
|
-
}
|
|
1961
|
-
if (!defaults_1.CHAINS_WITH_DEFAULT_TRACKED_ASSETS.has(caipChainId)) {
|
|
1962
|
-
return;
|
|
1963
|
-
}
|
|
1964
|
-
log('Network added — seeding default tracked assets', {
|
|
1965
|
-
hexChainId,
|
|
1966
|
-
caipChainId,
|
|
1967
|
-
});
|
|
1968
|
-
__classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_ensureDefaultTrackedAssetsSeeded).call(this, [caipChainId]);
|
|
1969
1883
|
};
|
|
1970
1884
|
//# sourceMappingURL=AssetsController.cjs.map
|