@metamask-previews/assets-controller 14.0.3-preview-e12b5ece6 → 14.0.3-preview-fe4b3be11
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 +5 -10
- package/dist/AssetsController.cjs +592 -273
- package/dist/AssetsController.cjs.map +1 -1
- package/dist/AssetsController.d.cts +7 -10
- package/dist/AssetsController.d.cts.map +1 -1
- package/dist/AssetsController.d.mts +7 -10
- package/dist/AssetsController.d.mts.map +1 -1
- package/dist/AssetsController.mjs +592 -273
- package/dist/AssetsController.mjs.map +1 -1
- package/dist/data-sources/AbstractDataSource.cjs +23 -0
- package/dist/data-sources/AbstractDataSource.cjs.map +1 -1
- package/dist/data-sources/AbstractDataSource.d.cts +13 -1
- package/dist/data-sources/AbstractDataSource.d.cts.map +1 -1
- package/dist/data-sources/AbstractDataSource.d.mts +13 -1
- package/dist/data-sources/AbstractDataSource.d.mts.map +1 -1
- package/dist/data-sources/AbstractDataSource.mjs +23 -0
- package/dist/data-sources/AbstractDataSource.mjs.map +1 -1
- package/dist/data-sources/AccountActivityDataSource.cjs +2 -0
- package/dist/data-sources/AccountActivityDataSource.cjs.map +1 -1
- package/dist/data-sources/AccountActivityDataSource.d.cts.map +1 -1
- package/dist/data-sources/AccountActivityDataSource.d.mts.map +1 -1
- package/dist/data-sources/AccountActivityDataSource.mjs +2 -0
- package/dist/data-sources/AccountActivityDataSource.mjs.map +1 -1
- package/dist/data-sources/AccountsApiDataSource.cjs +144 -31
- package/dist/data-sources/AccountsApiDataSource.cjs.map +1 -1
- package/dist/data-sources/AccountsApiDataSource.d.cts +18 -2
- package/dist/data-sources/AccountsApiDataSource.d.cts.map +1 -1
- package/dist/data-sources/AccountsApiDataSource.d.mts +18 -2
- package/dist/data-sources/AccountsApiDataSource.d.mts.map +1 -1
- package/dist/data-sources/AccountsApiDataSource.mjs +145 -32
- package/dist/data-sources/AccountsApiDataSource.mjs.map +1 -1
- package/dist/data-sources/RpcDataSource.cjs +163 -24
- package/dist/data-sources/RpcDataSource.cjs.map +1 -1
- package/dist/data-sources/RpcDataSource.d.cts +17 -0
- package/dist/data-sources/RpcDataSource.d.cts.map +1 -1
- package/dist/data-sources/RpcDataSource.d.mts +17 -0
- package/dist/data-sources/RpcDataSource.d.mts.map +1 -1
- package/dist/data-sources/RpcDataSource.mjs +164 -25
- package/dist/data-sources/RpcDataSource.mjs.map +1 -1
- package/dist/data-sources/evm-rpc-services/services/BalanceFetcher.cjs +21 -12
- package/dist/data-sources/evm-rpc-services/services/BalanceFetcher.cjs.map +1 -1
- package/dist/data-sources/evm-rpc-services/services/BalanceFetcher.d.cts +7 -2
- package/dist/data-sources/evm-rpc-services/services/BalanceFetcher.d.cts.map +1 -1
- package/dist/data-sources/evm-rpc-services/services/BalanceFetcher.d.mts +7 -2
- package/dist/data-sources/evm-rpc-services/services/BalanceFetcher.d.mts.map +1 -1
- package/dist/data-sources/evm-rpc-services/services/BalanceFetcher.mjs +21 -12
- package/dist/data-sources/evm-rpc-services/services/BalanceFetcher.mjs.map +1 -1
- package/dist/data-sources/evm-rpc-services/types/state.cjs.map +1 -1
- package/dist/data-sources/evm-rpc-services/types/state.d.cts +3 -2
- package/dist/data-sources/evm-rpc-services/types/state.d.cts.map +1 -1
- package/dist/data-sources/evm-rpc-services/types/state.d.mts +3 -2
- package/dist/data-sources/evm-rpc-services/types/state.d.mts.map +1 -1
- package/dist/data-sources/evm-rpc-services/types/state.mjs.map +1 -1
- package/dist/middlewares/ParallelMiddleware.cjs +9 -0
- package/dist/middlewares/ParallelMiddleware.cjs.map +1 -1
- package/dist/middlewares/ParallelMiddleware.d.cts.map +1 -1
- package/dist/middlewares/ParallelMiddleware.d.mts.map +1 -1
- package/dist/middlewares/ParallelMiddleware.mjs +9 -0
- package/dist/middlewares/ParallelMiddleware.mjs.map +1 -1
- package/dist/middlewares/RpcFallbackMiddleware.cjs +158 -128
- package/dist/middlewares/RpcFallbackMiddleware.cjs.map +1 -1
- package/dist/middlewares/RpcFallbackMiddleware.d.cts +10 -14
- package/dist/middlewares/RpcFallbackMiddleware.d.cts.map +1 -1
- package/dist/middlewares/RpcFallbackMiddleware.d.mts +10 -14
- package/dist/middlewares/RpcFallbackMiddleware.d.mts.map +1 -1
- package/dist/middlewares/RpcFallbackMiddleware.mjs +158 -128
- package/dist/middlewares/RpcFallbackMiddleware.mjs.map +1 -1
- package/dist/selectors/balance.cjs +4 -9
- package/dist/selectors/balance.cjs.map +1 -1
- package/dist/selectors/balance.d.cts.map +1 -1
- package/dist/selectors/balance.d.mts.map +1 -1
- package/dist/selectors/balance.mjs +4 -9
- package/dist/selectors/balance.mjs.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +28 -26
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +28 -26
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/package.json +4 -4
|
@@ -9,10 +9,10 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
9
9
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
|
-
var _RpcDataSource_instances, _RpcDataSource_messenger, _RpcDataSource_onActiveChainsUpdated, _RpcDataSource_getNativeAssetForChain, _RpcDataSource_timeout, _RpcDataSource_tokenDetectionEnabled, _RpcDataSource_useExternalService, _RpcDataSource_isOnboarded, _RpcDataSource_activeChains, _RpcDataSource_chainStatuses, _RpcDataSource_providerCache, _RpcDataSource_activeSubscriptions, _RpcDataSource_unsubscribeTransactionConfirmed, _RpcDataSource_multicallClient, _RpcDataSource_balanceFetcher, _RpcDataSource_tokenDetector, _RpcDataSource_getAssetType, _RpcDataSource_convertToHumanReadable, _RpcDataSource_collectMetadataForBalances, _RpcDataSource_hasValidDecimals, _RpcDataSource_pickValidDecimals, _RpcDataSource_handleBalanceUpdate, _RpcDataSource_handleDetectionUpdate, _RpcDataSource_subscribeToNetworkController, _RpcDataSource_subscribeToTransactionEvents, _RpcDataSource_onTransactionConfirmed, _RpcDataSource_refreshBalanceForChains, _RpcDataSource_initializeFromNetworkController, _RpcDataSource_updateFromNetworkState, _RpcDataSource_getProvider, _RpcDataSource_getMulticallProvider, _RpcDataSource_clearProviderCache, _RpcDataSource_fetchDecimalsViaRpc, _RpcDataSource_getExistingAssetsMetadata;
|
|
12
|
+
var _RpcDataSource_instances, _RpcDataSource_messenger, _RpcDataSource_onActiveChainsUpdated, _RpcDataSource_getNativeAssetForChain, _RpcDataSource_timeout, _RpcDataSource_tokenDetectionEnabled, _RpcDataSource_useExternalService, _RpcDataSource_isOnboarded, _RpcDataSource_isBalanceV6Enabled, _RpcDataSource_activeChains, _RpcDataSource_chainStatuses, _RpcDataSource_providerCache, _RpcDataSource_activeSubscriptions, _RpcDataSource_unsubscribeTransactionConfirmed, _RpcDataSource_multicallClient, _RpcDataSource_balanceFetcher, _RpcDataSource_tokenDetector, _RpcDataSource_getAssetType, _RpcDataSource_convertToHumanReadable, _RpcDataSource_collectMetadataForBalances, _RpcDataSource_hasValidDecimals, _RpcDataSource_pickValidDecimals, _RpcDataSource_handleBalanceUpdate, _RpcDataSource_handleDetectionUpdate, _RpcDataSource_subscribeToNetworkController, _RpcDataSource_subscribeToTransactionEvents, _RpcDataSource_onTransactionConfirmed, _RpcDataSource_refreshBalanceForChains, _RpcDataSource_initializeFromNetworkController, _RpcDataSource_updateFromNetworkState, _RpcDataSource_getProvider, _RpcDataSource_getMulticallProvider, _RpcDataSource_clearProviderCache, _RpcDataSource_fetchDecimalsViaRpc, _RpcDataSource_getSupplementalCustomAssetChains, _RpcDataSource_appendRequestCustomErc20sV5, _RpcDataSource_appendRequestCustomErc20sV6, _RpcDataSource_getCustomAssetsByAccount, _RpcDataSource_getExistingAssetsMetadata;
|
|
13
13
|
import { Web3Provider } from "@ethersproject/providers";
|
|
14
14
|
import { toHex } from "@metamask/controller-utils";
|
|
15
|
-
import { isStrictHexString, isCaipChainId, parseCaipAssetType, parseCaipChainId, hexToNumber, toCaipChainId
|
|
15
|
+
import { isStrictHexString, isCaipChainId, KnownCaipNamespace, parseCaipAssetType, parseCaipChainId, hexToNumber, toCaipChainId } from "@metamask/utils";
|
|
16
16
|
import BigNumberJS from "bignumber.js";
|
|
17
17
|
import { projectLogger, createModuleLogger } from "../logger.mjs";
|
|
18
18
|
import { ZERO_ADDRESS } from "../utils/constants.mjs";
|
|
@@ -68,6 +68,7 @@ export class RpcDataSource extends AbstractDataSource {
|
|
|
68
68
|
_RpcDataSource_tokenDetectionEnabled.set(this, void 0);
|
|
69
69
|
_RpcDataSource_useExternalService.set(this, void 0);
|
|
70
70
|
_RpcDataSource_isOnboarded.set(this, void 0);
|
|
71
|
+
_RpcDataSource_isBalanceV6Enabled.set(this, void 0);
|
|
71
72
|
/** Currently active chains */
|
|
72
73
|
_RpcDataSource_activeChains.set(this, []);
|
|
73
74
|
/** Network status for each active chain */
|
|
@@ -90,6 +91,7 @@ export class RpcDataSource extends AbstractDataSource {
|
|
|
90
91
|
__classPrivateFieldSet(this, _RpcDataSource_tokenDetectionEnabled, options.tokenDetectionEnabled ?? (() => true), "f");
|
|
91
92
|
__classPrivateFieldSet(this, _RpcDataSource_useExternalService, options.useExternalService ?? (() => true), "f");
|
|
92
93
|
__classPrivateFieldSet(this, _RpcDataSource_isOnboarded, options.isOnboarded ?? (() => true), "f");
|
|
94
|
+
__classPrivateFieldSet(this, _RpcDataSource_isBalanceV6Enabled, options.isBalanceV6Enabled ?? (() => false), "f");
|
|
93
95
|
const balanceInterval = options.balanceInterval ?? DEFAULT_BALANCE_INTERVAL;
|
|
94
96
|
const detectionInterval = options.detectionInterval ?? DEFAULT_DETECTION_INTERVAL;
|
|
95
97
|
log('Initializing RpcDataSource', {
|
|
@@ -246,6 +248,11 @@ export class RpcDataSource extends AbstractDataSource {
|
|
|
246
248
|
const assetsBalance = {};
|
|
247
249
|
const assetsInfo = {};
|
|
248
250
|
const failedChains = [];
|
|
251
|
+
// request.customAssets is flat. v6 resolves pin ownership from state so
|
|
252
|
+
// each account only fetches its own pins; v5 applies the flat list as on main.
|
|
253
|
+
const customAssetsByAccount = request.customAssets
|
|
254
|
+
? __classPrivateFieldGet(this, _RpcDataSource_instances, "m", _RpcDataSource_getCustomAssetsByAccount).call(this)
|
|
255
|
+
: {};
|
|
249
256
|
// Fetch balances for each account and its supported chains (pre-computed in request)
|
|
250
257
|
for (const { account, supportedChains, } of request.accountsWithSupportedChains) {
|
|
251
258
|
const chainsForAccount = chainsToFetch.filter((chain) => supportedChains.includes(chain));
|
|
@@ -264,25 +271,11 @@ export class RpcDataSource extends AbstractDataSource {
|
|
|
264
271
|
}
|
|
265
272
|
if (request.customAssets) {
|
|
266
273
|
const existingMetadata = __classPrivateFieldGet(this, _RpcDataSource_instances, "m", _RpcDataSource_getExistingAssetsMetadata).call(this);
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
__classPrivateFieldGet(this, _RpcDataSource_getAssetType, "f").call(this, assetId) === 'erc20') {
|
|
273
|
-
const tokenAddress = parsed.assetReference.toLowerCase();
|
|
274
|
-
const normalizedId = normalizeAssetId(assetId);
|
|
275
|
-
const decimals = existingMetadata[normalizedId]?.decimals;
|
|
276
|
-
assetsToFetch.push({
|
|
277
|
-
assetId,
|
|
278
|
-
address: tokenAddress,
|
|
279
|
-
decimals,
|
|
280
|
-
});
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
catch {
|
|
284
|
-
// Skip unparseable asset IDs
|
|
285
|
-
}
|
|
274
|
+
if (__classPrivateFieldGet(this, _RpcDataSource_isBalanceV6Enabled, "f").call(this)) {
|
|
275
|
+
__classPrivateFieldGet(this, _RpcDataSource_instances, "m", _RpcDataSource_appendRequestCustomErc20sV6).call(this, assetsToFetch, request.customAssets, chainId, existingMetadata, new Set((customAssetsByAccount[accountId] ?? []).map(normalizeAssetId)));
|
|
276
|
+
}
|
|
277
|
+
else {
|
|
278
|
+
__classPrivateFieldGet(this, _RpcDataSource_instances, "m", _RpcDataSource_appendRequestCustomErc20sV5).call(this, assetsToFetch, request.customAssets, chainId, existingMetadata);
|
|
286
279
|
}
|
|
287
280
|
}
|
|
288
281
|
try {
|
|
@@ -506,6 +499,30 @@ export class RpcDataSource extends AbstractDataSource {
|
|
|
506
499
|
return next(context);
|
|
507
500
|
};
|
|
508
501
|
}
|
|
502
|
+
/**
|
|
503
|
+
* RPC is the terminal claimer on the asset axis: it claims every EVM pin it
|
|
504
|
+
* has a provider for, even on chains claimed by higher-priority sources.
|
|
505
|
+
* Pins outside the regular RPC assignment get an asset-scoped poll (see
|
|
506
|
+
* `subscribe`).
|
|
507
|
+
*
|
|
508
|
+
* @param customAssets - Candidate CAIP-19 asset IDs still unclaimed.
|
|
509
|
+
* @param assignedChains - Chains assigned to RPC; availability fallback
|
|
510
|
+
* before network state is applied.
|
|
511
|
+
* @returns The claimed subset of `customAssets`.
|
|
512
|
+
*/
|
|
513
|
+
claimCustomAssets(customAssets, assignedChains) {
|
|
514
|
+
const available = new Set(__classPrivateFieldGet(this, _RpcDataSource_activeChains, "f").length > 0 ? __classPrivateFieldGet(this, _RpcDataSource_activeChains, "f") : assignedChains);
|
|
515
|
+
return customAssets.filter((assetId) => {
|
|
516
|
+
try {
|
|
517
|
+
const parsed = parseCaipAssetType(assetId);
|
|
518
|
+
return (parsed.chain.namespace === KnownCaipNamespace.Eip155 &&
|
|
519
|
+
available.has(parsed.chainId));
|
|
520
|
+
}
|
|
521
|
+
catch {
|
|
522
|
+
return false;
|
|
523
|
+
}
|
|
524
|
+
});
|
|
525
|
+
}
|
|
509
526
|
/**
|
|
510
527
|
* Subscribe to updates for the given request.
|
|
511
528
|
* Starts polling through BalanceFetcher and TokenDetector.
|
|
@@ -523,14 +540,18 @@ export class RpcDataSource extends AbstractDataSource {
|
|
|
523
540
|
const chainsToSubscribe = __classPrivateFieldGet(this, _RpcDataSource_activeChains, "f").length > 0
|
|
524
541
|
? request.chainIds.filter((chainId) => __classPrivateFieldGet(this, _RpcDataSource_activeChains, "f").includes(chainId))
|
|
525
542
|
: request.chainIds;
|
|
543
|
+
// Pins claimed on chains outside the regular RPC assignment get an
|
|
544
|
+
// asset-scoped poll below.
|
|
545
|
+
const supplementalChains = __classPrivateFieldGet(this, _RpcDataSource_instances, "m", _RpcDataSource_getSupplementalCustomAssetChains).call(this, request, chainsToSubscribe);
|
|
526
546
|
log('Subscribe requested', {
|
|
527
547
|
subscriptionId,
|
|
528
548
|
isUpdate,
|
|
529
549
|
accounts: request.accountsWithSupportedChains.map((a) => a.account.id),
|
|
530
550
|
chainsToSubscribe,
|
|
551
|
+
supplementalChains,
|
|
531
552
|
activeChainsFallback: __classPrivateFieldGet(this, _RpcDataSource_activeChains, "f").length === 0,
|
|
532
553
|
});
|
|
533
|
-
if (chainsToSubscribe.length === 0) {
|
|
554
|
+
if (chainsToSubscribe.length === 0 && supplementalChains.length === 0) {
|
|
534
555
|
log('No active chains to subscribe');
|
|
535
556
|
return;
|
|
536
557
|
}
|
|
@@ -570,8 +591,6 @@ export class RpcDataSource extends AbstractDataSource {
|
|
|
570
591
|
};
|
|
571
592
|
const balanceToken = __classPrivateFieldGet(this, _RpcDataSource_balanceFetcher, "f").startPolling(balanceInput);
|
|
572
593
|
balancePollingTokens.push(balanceToken);
|
|
573
|
-
// Token detection is only relevant for "regular" subscriptions —
|
|
574
|
-
// a customAssetsOnly subscription should never run detection.
|
|
575
594
|
if (request.customAssetsOnly !== true &&
|
|
576
595
|
__classPrivateFieldGet(this, _RpcDataSource_tokenDetectionEnabled, "f").call(this) &&
|
|
577
596
|
__classPrivateFieldGet(this, _RpcDataSource_useExternalService, "f").call(this)) {
|
|
@@ -585,6 +604,51 @@ export class RpcDataSource extends AbstractDataSource {
|
|
|
585
604
|
}
|
|
586
605
|
}
|
|
587
606
|
}
|
|
607
|
+
// Asset-scoped polls on chains another source claimed: poll ONLY the
|
|
608
|
+
// claimed pins to avoid double-polling tracked balances. Pin changes
|
|
609
|
+
// re-run the subscription pass, which rebuilds these polls.
|
|
610
|
+
// Asset-scoped polls on chains another source claimed (v6 only).
|
|
611
|
+
if (__classPrivateFieldGet(this, _RpcDataSource_isBalanceV6Enabled, "f").call(this) && supplementalChains.length > 0) {
|
|
612
|
+
const supplemental = new Set(supplementalChains);
|
|
613
|
+
const claimedAssetsByChain = new Map();
|
|
614
|
+
for (const assetId of request.customAssets ?? []) {
|
|
615
|
+
try {
|
|
616
|
+
const { chainId } = parseCaipAssetType(assetId);
|
|
617
|
+
if (supplemental.has(chainId)) {
|
|
618
|
+
const chainAssets = claimedAssetsByChain.get(chainId) ?? [];
|
|
619
|
+
chainAssets.push(assetId);
|
|
620
|
+
claimedAssetsByChain.set(chainId, chainAssets);
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
catch {
|
|
624
|
+
// Skip unparseable asset IDs
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
// request.customAssets is flat; ownership comes from controller state.
|
|
628
|
+
const customAssetsByAccount = __classPrivateFieldGet(this, _RpcDataSource_instances, "m", _RpcDataSource_getCustomAssetsByAccount).call(this);
|
|
629
|
+
for (const { account } of request.accountsWithSupportedChains) {
|
|
630
|
+
const pinned = new Set(customAssetsByAccount[account.id] ?? []);
|
|
631
|
+
if (pinned.size === 0) {
|
|
632
|
+
continue;
|
|
633
|
+
}
|
|
634
|
+
for (const [chainId, chainAssets] of claimedAssetsByChain) {
|
|
635
|
+
// Sorted so the polling input (the dedupe key) is deterministic.
|
|
636
|
+
const assetIds = chainAssets
|
|
637
|
+
.filter((assetId) => pinned.has(assetId))
|
|
638
|
+
.sort();
|
|
639
|
+
if (assetIds.length === 0) {
|
|
640
|
+
continue;
|
|
641
|
+
}
|
|
642
|
+
const balanceInput = {
|
|
643
|
+
chainId: caipChainIdToHex(chainId),
|
|
644
|
+
accountId: account.id,
|
|
645
|
+
accountAddress: account.address,
|
|
646
|
+
assetIds,
|
|
647
|
+
};
|
|
648
|
+
balancePollingTokens.push(__classPrivateFieldGet(this, _RpcDataSource_balanceFetcher, "f").startPolling(balanceInput));
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
}
|
|
588
652
|
// Store subscription data
|
|
589
653
|
const accounts = request.accountsWithSupportedChains.map((entry) => entry.account);
|
|
590
654
|
__classPrivateFieldGet(this, _RpcDataSource_activeSubscriptions, "f").set(subscriptionId, {
|
|
@@ -636,7 +700,7 @@ export class RpcDataSource extends AbstractDataSource {
|
|
|
636
700
|
__classPrivateFieldGet(this, _RpcDataSource_providerCache, "f").clear();
|
|
637
701
|
}
|
|
638
702
|
}
|
|
639
|
-
_RpcDataSource_messenger = new WeakMap(), _RpcDataSource_onActiveChainsUpdated = new WeakMap(), _RpcDataSource_getNativeAssetForChain = new WeakMap(), _RpcDataSource_timeout = new WeakMap(), _RpcDataSource_tokenDetectionEnabled = new WeakMap(), _RpcDataSource_useExternalService = new WeakMap(), _RpcDataSource_isOnboarded = new WeakMap(), _RpcDataSource_activeChains = new WeakMap(), _RpcDataSource_chainStatuses = new WeakMap(), _RpcDataSource_providerCache = new WeakMap(), _RpcDataSource_activeSubscriptions = new WeakMap(), _RpcDataSource_unsubscribeTransactionConfirmed = new WeakMap(), _RpcDataSource_multicallClient = new WeakMap(), _RpcDataSource_balanceFetcher = new WeakMap(), _RpcDataSource_tokenDetector = new WeakMap(), _RpcDataSource_getAssetType = new WeakMap(), _RpcDataSource_instances = new WeakSet(), _RpcDataSource_convertToHumanReadable = function _RpcDataSource_convertToHumanReadable(rawBalance, decimals) {
|
|
703
|
+
_RpcDataSource_messenger = new WeakMap(), _RpcDataSource_onActiveChainsUpdated = new WeakMap(), _RpcDataSource_getNativeAssetForChain = new WeakMap(), _RpcDataSource_timeout = new WeakMap(), _RpcDataSource_tokenDetectionEnabled = new WeakMap(), _RpcDataSource_useExternalService = new WeakMap(), _RpcDataSource_isOnboarded = new WeakMap(), _RpcDataSource_isBalanceV6Enabled = new WeakMap(), _RpcDataSource_activeChains = new WeakMap(), _RpcDataSource_chainStatuses = new WeakMap(), _RpcDataSource_providerCache = new WeakMap(), _RpcDataSource_activeSubscriptions = new WeakMap(), _RpcDataSource_unsubscribeTransactionConfirmed = new WeakMap(), _RpcDataSource_multicallClient = new WeakMap(), _RpcDataSource_balanceFetcher = new WeakMap(), _RpcDataSource_tokenDetector = new WeakMap(), _RpcDataSource_getAssetType = new WeakMap(), _RpcDataSource_instances = new WeakSet(), _RpcDataSource_convertToHumanReadable = function _RpcDataSource_convertToHumanReadable(rawBalance, decimals) {
|
|
640
704
|
if (!Number.isFinite(decimals) || decimals < 0) {
|
|
641
705
|
log('Invalid decimals — defaulting balance to "0"', {
|
|
642
706
|
rawBalance,
|
|
@@ -1005,6 +1069,81 @@ async function _RpcDataSource_fetchDecimalsViaRpc(chainId, tokenAddress) {
|
|
|
1005
1069
|
catch {
|
|
1006
1070
|
return undefined;
|
|
1007
1071
|
}
|
|
1072
|
+
}, _RpcDataSource_getSupplementalCustomAssetChains = function _RpcDataSource_getSupplementalCustomAssetChains(request, chainsToSubscribe) {
|
|
1073
|
+
if (!request.customAssets || request.customAssets.length === 0) {
|
|
1074
|
+
return [];
|
|
1075
|
+
}
|
|
1076
|
+
const covered = new Set(chainsToSubscribe);
|
|
1077
|
+
const chains = new Set();
|
|
1078
|
+
for (const assetId of request.customAssets) {
|
|
1079
|
+
let parsed;
|
|
1080
|
+
try {
|
|
1081
|
+
parsed = parseCaipAssetType(assetId);
|
|
1082
|
+
}
|
|
1083
|
+
catch {
|
|
1084
|
+
continue;
|
|
1085
|
+
}
|
|
1086
|
+
const { chainId } = parsed;
|
|
1087
|
+
if (parsed.chain.namespace === KnownCaipNamespace.Eip155 &&
|
|
1088
|
+
!covered.has(chainId) &&
|
|
1089
|
+
(__classPrivateFieldGet(this, _RpcDataSource_activeChains, "f").length === 0 ||
|
|
1090
|
+
__classPrivateFieldGet(this, _RpcDataSource_activeChains, "f").includes(chainId))) {
|
|
1091
|
+
chains.add(chainId);
|
|
1092
|
+
}
|
|
1093
|
+
}
|
|
1094
|
+
return [...chains];
|
|
1095
|
+
}, _RpcDataSource_appendRequestCustomErc20sV5 = function _RpcDataSource_appendRequestCustomErc20sV5(assetsToFetch, customAssets, chainId, existingMetadata) {
|
|
1096
|
+
for (const assetId of customAssets) {
|
|
1097
|
+
try {
|
|
1098
|
+
const parsed = parseCaipAssetType(assetId);
|
|
1099
|
+
const assetChainId = `${parsed.chain.namespace}:${parsed.chain.reference}`;
|
|
1100
|
+
if (assetChainId === chainId &&
|
|
1101
|
+
__classPrivateFieldGet(this, _RpcDataSource_getAssetType, "f").call(this, assetId) === 'erc20') {
|
|
1102
|
+
const tokenAddress = parsed.assetReference.toLowerCase();
|
|
1103
|
+
const normalizedId = normalizeAssetId(assetId);
|
|
1104
|
+
const decimals = existingMetadata[normalizedId]?.decimals;
|
|
1105
|
+
assetsToFetch.push({
|
|
1106
|
+
assetId,
|
|
1107
|
+
address: tokenAddress,
|
|
1108
|
+
decimals,
|
|
1109
|
+
});
|
|
1110
|
+
}
|
|
1111
|
+
}
|
|
1112
|
+
catch {
|
|
1113
|
+
// Skip unparseable asset IDs
|
|
1114
|
+
}
|
|
1115
|
+
}
|
|
1116
|
+
}, _RpcDataSource_appendRequestCustomErc20sV6 = function _RpcDataSource_appendRequestCustomErc20sV6(assetsToFetch, customAssets, chainId, existingMetadata, pinnedByAccount) {
|
|
1117
|
+
for (const assetId of customAssets) {
|
|
1118
|
+
try {
|
|
1119
|
+
const parsed = parseCaipAssetType(assetId);
|
|
1120
|
+
const assetChainId = `${parsed.chain.namespace}:${parsed.chain.reference}`;
|
|
1121
|
+
const normalizedId = normalizeAssetId(assetId);
|
|
1122
|
+
if (assetChainId === chainId &&
|
|
1123
|
+
pinnedByAccount.has(normalizedId) &&
|
|
1124
|
+
__classPrivateFieldGet(this, _RpcDataSource_getAssetType, "f").call(this, assetId) === 'erc20') {
|
|
1125
|
+
const tokenAddress = parsed.assetReference.toLowerCase();
|
|
1126
|
+
const decimals = existingMetadata[normalizedId]?.decimals;
|
|
1127
|
+
assetsToFetch.push({
|
|
1128
|
+
assetId,
|
|
1129
|
+
address: tokenAddress,
|
|
1130
|
+
decimals,
|
|
1131
|
+
});
|
|
1132
|
+
}
|
|
1133
|
+
}
|
|
1134
|
+
catch {
|
|
1135
|
+
// Skip unparseable asset IDs
|
|
1136
|
+
}
|
|
1137
|
+
}
|
|
1138
|
+
}, _RpcDataSource_getCustomAssetsByAccount = function _RpcDataSource_getCustomAssetsByAccount() {
|
|
1139
|
+
try {
|
|
1140
|
+
const state = __classPrivateFieldGet(this, _RpcDataSource_messenger, "f").call('AssetsController:getState');
|
|
1141
|
+
return (state.customAssets ?? {});
|
|
1142
|
+
}
|
|
1143
|
+
catch (error) {
|
|
1144
|
+
log('Failed to get customAssets from state', { error });
|
|
1145
|
+
return {};
|
|
1146
|
+
}
|
|
1008
1147
|
}, _RpcDataSource_getExistingAssetsMetadata = function _RpcDataSource_getExistingAssetsMetadata() {
|
|
1009
1148
|
try {
|
|
1010
1149
|
const state = __classPrivateFieldGet(this, _RpcDataSource_messenger, "f").call('AssetsController:getState');
|