@metamask-previews/assets-controller 11.0.0-preview-44376e0 → 11.0.0-preview-4343321
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 +0 -3
- package/dist/AssetsController.cjs.map +1 -1
- package/dist/AssetsController.d.cts +2 -2
- package/dist/AssetsController.d.cts.map +1 -1
- package/dist/AssetsController.d.mts +2 -2
- package/dist/AssetsController.d.mts.map +1 -1
- package/dist/AssetsController.mjs.map +1 -1
- package/dist/data-sources/AccountsApiDataSource.cjs +8 -50
- package/dist/data-sources/AccountsApiDataSource.cjs.map +1 -1
- package/dist/data-sources/AccountsApiDataSource.d.cts +1 -2
- package/dist/data-sources/AccountsApiDataSource.d.cts.map +1 -1
- package/dist/data-sources/AccountsApiDataSource.d.mts +1 -2
- package/dist/data-sources/AccountsApiDataSource.d.mts.map +1 -1
- package/dist/data-sources/AccountsApiDataSource.mjs +8 -50
- package/dist/data-sources/AccountsApiDataSource.mjs.map +1 -1
- package/dist/index.cjs +1 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +0 -2
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +0 -2
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +0 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/dist/utils/snaps-assets-migration.cjs +0 -171
- package/dist/utils/snaps-assets-migration.cjs.map +0 -1
- package/dist/utils/snaps-assets-migration.d.cts +0 -113
- package/dist/utils/snaps-assets-migration.d.cts.map +0 -1
- package/dist/utils/snaps-assets-migration.d.mts +0 -113
- package/dist/utils/snaps-assets-migration.d.mts.map +0 -1
- package/dist/utils/snaps-assets-migration.mjs +0 -162
- package/dist/utils/snaps-assets-migration.mjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AccountsApiDataSource.mjs","sourceRoot":"","sources":["../../src/data-sources/AccountsApiDataSource.ts"],"names":[],"mappings":";;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AAK,CAAC,QAAQ,EAAE,CAAC;YAClC,qEAAqE;YACrE,IAAI,IAAI,CAAC,QAAQ,KAAK,OAAO,EAAE,CAAC;gBAC9B,SAAS;YACX,CAAC;YAED,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC,EAAE,CAAC;gBAC9B,aAAa,CAAC,SAAS,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAG5C,CAAC;YACJ,CAAC;YAED,+DAA+D;YAC/D,MAAM,iBAAiB,GAAG,gBAAgB,CACxC,IAAI,CAAC,OAAwB,CAC9B,CAAC;YAEF,mCAAmC;YACnC,aAAa,CAAC,SAAS,CAAC,CAAC,iBAAiB,CAAC,GAAG;gBAC5C,MAAM,EAAE,IAAI,CAAC,OAAO;aACrB,CAAC;QACJ,CAAC;IACH,CAAC;IAED,OAAO,EAAE,aAAa,EAAE,CAAC;AAC3B,CAAC","sourcesContent":["import type {\n V5BalanceItem,\n V6AccountBalancesEntry,\n} from '@metamask/core-backend';\nimport { ApiPlatformClient } from '@metamask/core-backend';\nimport type {\n FeatureFlags,\n RemoteFeatureFlagControllerGetStateAction,\n RemoteFeatureFlagControllerStateChangeEvent,\n} from '@metamask/remote-feature-flag-controller';\nimport {\n isCaipChainId,\n KnownCaipNamespace,\n toCaipChainId,\n} from '@metamask/utils';\n\nimport type { AssetsControllerMessenger } from '../AssetsController';\nimport { projectLogger, createModuleLogger } from '../logger';\nimport type {\n ChainId,\n Caip19AssetId,\n AssetBalance,\n DataRequest,\n DataResponse,\n Middleware,\n AssetsControllerStateInternal,\n} from '../types';\nimport { fetchWithTimeout, normalizeAssetId } from '../utils';\nimport {\n getMigrationStages,\n shouldSupportChain,\n} from '../utils/snaps-assets-migration';\nimport type {\n DataSourceState,\n SubscriptionRequest,\n} from './AbstractDataSource';\nimport { AbstractDataSource } from './AbstractDataSource';\n\n// ============================================================================\n// CONSTANTS\n// ============================================================================\n\nconst CONTROLLER_NAME = 'AccountsApiDataSource';\nconst DEFAULT_POLL_INTERVAL = 30_000;\nconst DEFAULT_FETCH_TIMEOUT_MS = 15_000;\n\nconst log = createModuleLogger(projectLogger, CONTROLLER_NAME);\n\n// ============================================================================\n// MESSENGER TYPES\n// ============================================================================\n\n// Allowed actions that AccountsApiDataSource can call. Balances are fetched via\n// ApiPlatformClient directly (no BackendApiClient actions needed); the messenger\n// is used to read the Accounts API v6 balances feature flag and to subscribe to\n// `RemoteFeatureFlagController:stateChange` (see constructor) so migration flag\n// changes refresh the active chains.\nexport type AccountsApiDataSourceAllowedActions =\n RemoteFeatureFlagControllerGetStateAction;\n\n// Allowed events that AccountsApiDataSource subscribes to. Migration flag\n// changes trigger a refresh of the chains surfaced as active.\nexport type AccountsApiDataSourceAllowedEvents =\n RemoteFeatureFlagControllerStateChangeEvent;\n\n// ============================================================================\n// STATE\n// ============================================================================\n\nexport type AccountsApiDataSourceState = DataSourceState;\n\nconst defaultState: AccountsApiDataSourceState = {\n activeChains: [],\n};\n\n// ============================================================================\n// OPTIONS\n// ============================================================================\n\n/** Optional configuration for AccountsApiDataSource. */\nexport type AccountsApiDataSourceConfig = {\n /** Polling interval in ms (default: 30000) */\n pollInterval?: number;\n /**\n * Function returning whether token detection is enabled (default: () => true).\n * When it returns false, balances are only returned for tokens already in state.\n * Using a getter avoids stale values when the user toggles the preference at runtime.\n */\n tokenDetectionEnabled?: () => boolean;\n /**\n * Timeout in ms for a single balances fetch call (default: 15000).\n * When it fires, every requested chain is marked as errored so the\n * middleware hands them off to the next data source (e.g. RPC fallback).\n */\n fetchTimeoutMs?: number;\n};\n\nexport type AccountsApiDataSourceOptions = AccountsApiDataSourceConfig & {\n /**\n * The AssetsController messenger (shared by all data sources). Used to read\n * the `assetsAccountsApiV6` remote feature flag.\n */\n messenger: AssetsControllerMessenger;\n /** ApiPlatformClient for API calls with caching */\n queryApiClient: ApiPlatformClient;\n /** Called when active chains are updated. Pass dataSourceName so the controller knows the source. */\n onActiveChainsUpdated: (\n dataSourceName: string,\n chains: ChainId[],\n previousChains: ChainId[],\n ) => void;\n state?: Partial<AccountsApiDataSourceState>;\n};\n\n// ============================================================================\n// HELPER FUNCTIONS\n// ============================================================================\n\nfunction decimalToChainId(decimalChainId: number | string): ChainId {\n // Handle both decimal numbers and already-formatted CAIP chain IDs\n if (typeof decimalChainId === 'string') {\n if (isCaipChainId(decimalChainId)) {\n return decimalChainId;\n }\n return toCaipChainId(KnownCaipNamespace.Eip155, decimalChainId);\n }\n return toCaipChainId(KnownCaipNamespace.Eip155, String(decimalChainId));\n}\n\n/**\n * Convert a CAIP-2 chain ID from the API response to our ChainId type.\n * Handles both formats: \"eip155:1\" or just \"1\" (decimal).\n * Uses @metamask/utils for CAIP parsing.\n *\n * @param chainIdStr - The chain ID string to convert.\n * @returns The normalized ChainId.\n */\nfunction caipChainIdToChainId(chainIdStr: string): ChainId {\n if (isCaipChainId(chainIdStr)) {\n return chainIdStr;\n }\n return toCaipChainId(KnownCaipNamespace.Eip155, chainIdStr);\n}\n\n/**\n * Filter a response to only include balances for assets already in state.\n * Used when tokenDetectionEnabled is false to prevent adding new tokens.\n *\n * @param response - The fetch response to filter.\n * @param assetsState - Current assets controller state to check existing balances against.\n * @returns A new response with only known asset balances.\n */\nexport function filterResponseToKnownAssets(\n response: DataResponse,\n assetsState: AssetsControllerStateInternal,\n): DataResponse {\n if (!response.assetsBalance) {\n return response;\n }\n\n const filteredBalance: Record<\n string,\n Record<Caip19AssetId, AssetBalance>\n > = {};\n\n for (const [accountId, accountBalances] of Object.entries(\n response.assetsBalance,\n )) {\n const existingBalances = assetsState.assetsBalance[accountId];\n if (!existingBalances) {\n // Account has no balances in state yet — skip all its tokens\n continue;\n }\n\n const filtered: Record<Caip19AssetId, AssetBalance> = {};\n for (const [assetId, balance] of Object.entries(accountBalances)) {\n // Only include assets already tracked in state\n if (assetId in existingBalances) {\n filtered[assetId as Caip19AssetId] = balance;\n }\n }\n\n if (Object.keys(filtered).length > 0) {\n filteredBalance[accountId] = filtered;\n }\n }\n\n return {\n ...response,\n assetsBalance:\n Object.keys(filteredBalance).length > 0 ? filteredBalance : undefined,\n };\n}\n\n// ============================================================================\n// ACCOUNTS API DATA SOURCE\n// ============================================================================\n\n/**\n * Data source for fetching balances from the MetaMask Accounts API.\n *\n * Uses ApiPlatformClient (queryApiClient) for all API calls. Does not use the\n * messenger. Reports active chains via onActiveChainsUpdated callback.\n */\nexport class AccountsApiDataSource extends AbstractDataSource<\n typeof CONTROLLER_NAME,\n AccountsApiDataSourceState\n> {\n readonly #onActiveChainsUpdated: (\n dataSourceName: string,\n chains: ChainId[],\n previousChains: ChainId[],\n ) => void;\n\n readonly #pollInterval: number;\n\n readonly #fetchTimeoutMs: number;\n\n /** Getter avoids stale value when user toggles token detection at runtime. */\n readonly #tokenDetectionEnabled: () => boolean;\n\n /** Shared AssetsController messenger, used to read remote feature flags. */\n readonly #messenger: AssetsControllerMessenger;\n\n /** ApiPlatformClient for cached API calls */\n readonly #apiClient: ApiPlatformClient;\n\n /** Chains refresh timer */\n #chainsRefreshTimer: ReturnType<typeof setInterval> | null = null;\n\n /** State accessor from subscriptions (for filtering when tokenDetectionEnabled is false) */\n #getAssetsState?: () => AssetsControllerStateInternal;\n\n constructor(options: AccountsApiDataSourceOptions) {\n super(CONTROLLER_NAME, {\n ...defaultState,\n ...options.state,\n });\n\n this.#onActiveChainsUpdated = options.onActiveChainsUpdated;\n this.#pollInterval = options.pollInterval ?? DEFAULT_POLL_INTERVAL;\n this.#fetchTimeoutMs = options.fetchTimeoutMs ?? DEFAULT_FETCH_TIMEOUT_MS;\n this.#tokenDetectionEnabled =\n options.tokenDetectionEnabled ?? ((): boolean => true);\n this.#messenger = options.messenger;\n this.#apiClient = options.queryApiClient;\n\n // The Snaps → AssetsController migration flags gate which migration networks\n // (Solana, Stellar, Tron) are surfaced as active chains (see\n // `#shouldSupportChain`). Mirror core-backend's AccountActivityService and\n // react to remote feature flag changes so newly-enabled chains are picked up\n // (and disabled ones dropped) without waiting for the periodic refresh.\n this.#messenger.subscribe(\n // eslint-disable-next-line no-restricted-syntax\n 'RemoteFeatureFlagController:stateChange',\n // Promise result intentionally not awaited\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n async () => await this.#handleMigrationFeatureFlagsChanged(),\n // Only react to changes in the set of migration stages. The messenger\n // compares selector results with strict equality, so the selector must\n // return a primitive rather than a fresh object.\n (state) => getMigrationStages(state.remoteFeatureFlags).join(','),\n );\n\n this.#initializeActiveChains().catch(console.error);\n }\n\n /**\n * Handle a change to the Snaps → AssetsController migration flags: re-fetch\n * active chains so newly-enabled migration networks are surfaced (and disabled\n * ones dropped) without waiting for the periodic refresh. The refresh invokes\n * `onActiveChainsUpdated` when the set changes, which drives re-subscription.\n */\n async #handleMigrationFeatureFlagsChanged(): Promise<void> {\n try {\n await this.#refreshActiveChains();\n } catch (error) {\n log('Failed to refresh active chains after feature flag change', {\n error,\n });\n }\n }\n\n /**\n * Whether the Accounts API v6 balances endpoint is enabled, read from the\n * RemoteFeatureFlagController (`assetsAccountsApiV6`). Read on demand (per\n * fetch) rather than cached so the value can be toggled at runtime, and behaves\n * the same across clients (extension, mobile). Defaults to `false` when the\n * flag is unset or the controller is unavailable.\n *\n * The flag is a LaunchDarkly JSON variation shaped `{ value: boolean }` (same\n * shape as `backendWebSocketConnection`), so the nested `value` is read rather\n * than treating the flag as a plain boolean.\n *\n * @returns `true` when the v6 balances endpoint should be used.\n */\n #isBalanceV6Enabled(): boolean {\n try {\n const { remoteFeatureFlags } = this.#messenger.call(\n 'RemoteFeatureFlagController:getState',\n );\n const flag = remoteFeatureFlags?.assetsAccountsApiV6;\n return (\n typeof flag === 'object' &&\n flag !== null &&\n Boolean((flag as { value?: unknown }).value)\n );\n } catch {\n return false;\n }\n }\n\n /**\n * Read the remote feature flags from the RemoteFeatureFlagController, or\n * `undefined` when the controller is unavailable (fail-safe: migration\n * networks then resolve to `Off` and are excluded).\n *\n * @returns The remote feature flags, or `undefined` when unavailable.\n */\n #getRemoteFeatureFlags(): FeatureFlags | undefined {\n try {\n return this.#messenger.call('RemoteFeatureFlagController:getState')\n .remoteFeatureFlags;\n } catch {\n return undefined;\n }\n }\n\n // ============================================================================\n // INITIALIZATION\n // ============================================================================\n\n async #initializeActiveChains(): Promise<void> {\n try {\n const chains = await this.#fetchActiveChains();\n const previous = [...this.state.activeChains];\n this.updateActiveChains(chains, (updatedChains) =>\n this.#onActiveChainsUpdated(this.getName(), updatedChains, previous),\n );\n\n // Periodically refresh active chains (every 20 minutes)\n this.#chainsRefreshTimer = setInterval(\n () => {\n this.#refreshActiveChains().catch(console.error);\n },\n 20 * 60 * 1000,\n );\n } catch (error) {\n log('Failed to fetch active chains', error);\n }\n }\n\n async #refreshActiveChains(): Promise<void> {\n try {\n const chains = await this.#fetchActiveChains();\n const previousChains = new Set(this.state.activeChains);\n const newChains = new Set(chains);\n\n // Check if chains changed\n const added = chains.filter((chain) => !previousChains.has(chain));\n const removed = Array.from(previousChains).filter(\n (chain) => !newChains.has(chain),\n );\n\n if (added.length > 0 || removed.length > 0) {\n const previous = [...this.state.activeChains];\n this.updateActiveChains(chains, (updatedChains) =>\n this.#onActiveChainsUpdated(this.getName(), updatedChains, previous),\n );\n }\n } catch (error) {\n log('Failed to refresh active chains', error);\n }\n }\n\n /**\n * Re-fetch supported networks from the Accounts API and update `activeChains`\n * when the list changed. Used when the selected EVM network switches so\n * chain claiming is not stuck on an empty init-time list.\n *\n * @returns Resolves when supported networks have been re-fetched.\n */\n refreshActiveChains(): Promise<void> {\n return this.#refreshActiveChains();\n }\n\n async #fetchActiveChains(): Promise<ChainId[]> {\n const response = await this.#apiClient.accounts.fetchV2SupportedNetworks();\n\n // Use fullSupport networks as active chains, gated by the Snaps →\n // AssetsController migration FF: non-migration namespaces (e.g. `eip155`)\n // are always surfaced, while migration networks (Solana, Stellar, Tron) are\n // only surfaced once their per-network stage reaches\n // ReadAssetsControllerWithFallback.\n const remoteFeatureFlags = this.#getRemoteFeatureFlags();\n return response.fullSupport\n .map(decimalToChainId)\n .filter((chainId) => shouldSupportChain(chainId, remoteFeatureFlags));\n }\n\n // ============================================================================\n // ACCOUNT SCOPE HELPERS\n // ============================================================================\n\n // ============================================================================\n // FETCH\n // ============================================================================\n\n async fetch(request: DataRequest): Promise<DataResponse> {\n let response: DataResponse = {};\n\n // Filter to only chains supported by Accounts API\n const supportedChains = new Set(this.state.activeChains);\n const chainsToFetch = request.chainIds.filter((chainId) =>\n supportedChains.has(chainId),\n );\n\n if (chainsToFetch.length === 0) {\n // Mark unsupported chains as errors so they pass to next middleware\n for (const chainId of request.chainIds) {\n if (!supportedChains.has(chainId)) {\n response.errors = response.errors ?? {};\n response.errors[chainId] = 'Chain not supported by Accounts API';\n }\n }\n return response;\n }\n\n try {\n // Build CAIP-10 account IDs (e.g., \"eip155:1:0x1234...\")\n // Use pre-computed supportedChains per account from the request\n const accountIds = request.accountsWithSupportedChains.flatMap(\n ({ account, supportedChains: accountChains }) =>\n chainsToFetch\n .filter((chainId) => accountChains.includes(chainId))\n .map((chainId) => `${chainId}:${account.address}`),\n );\n\n // Skip API call if no valid account-chain combinations\n if (accountIds.length === 0) {\n return response;\n }\n\n const fetchOptions = request.forceUpdate\n ? { staleTime: 0, gcTime: 0 }\n : undefined;\n\n // Feature-flagged: v6 endpoint with a fallback to legacy v5. The flag is\n // read here (not cached) so a runtime toggle can revert v6 -> v5.\n const { unprocessedNetworks, assetsBalance } = this.#isBalanceV6Enabled()\n ? await this.#fetchV6Balances(accountIds, fetchOptions, request)\n : await this.#fetchV5Balances(accountIds, fetchOptions, request);\n\n // Handle unprocessed networks - these will be passed to next middleware\n if (unprocessedNetworks.length > 0) {\n const unprocessedChainIds =\n unprocessedNetworks.map(caipChainIdToChainId);\n\n // Add unprocessed chains to errors so middleware passes them to next data source\n response.errors = response.errors ?? {};\n for (const chainId of unprocessedChainIds) {\n response.errors[chainId] = 'Unprocessed by Accounts API';\n }\n }\n\n response.assetsBalance = assetsBalance;\n response.updateMode = 'merge';\n } catch (error) {\n log('Fetch FAILED', { error, chains: chainsToFetch });\n\n // On error, mark all chains as errors so they can be handled by next middleware\n response.errors = response.errors ?? {};\n for (const chainId of chainsToFetch) {\n response.errors[chainId] =\n `Fetch failed: ${error instanceof Error ? error.message : String(error)}`;\n }\n }\n\n // Mark unsupported chains as errors so they pass to next middleware\n for (const chainId of request.chainIds) {\n if (!supportedChains.has(chainId)) {\n response.errors = response.errors ?? {};\n response.errors[chainId] = 'Chain not supported by Accounts API';\n }\n }\n\n // When token detection is disabled, filter out tokens not already in state\n if (!this.#tokenDetectionEnabled() && this.#getAssetsState) {\n response = filterResponseToKnownAssets(response, this.#getAssetsState());\n }\n\n return response;\n }\n\n /**\n * Fetch balances from the legacy v5 endpoint and process them.\n *\n * @param accountIds - CAIP-10 account IDs to fetch balances for.\n * @param fetchOptions - Cache/fetch options (e.g. force update settings).\n * @param request - The original data request containing accounts to map.\n * @returns Unprocessed networks and processed asset balances by account.\n */\n async #fetchV5Balances(\n accountIds: string[],\n fetchOptions: { staleTime: number; gcTime: number } | undefined,\n request: DataRequest,\n ): Promise<{\n unprocessedNetworks: string[];\n assetsBalance: Record<string, Record<Caip19AssetId, AssetBalance>>;\n }> {\n const apiResponse = await fetchWithTimeout(\n () =>\n this.#apiClient.accounts.fetchV5MultiAccountBalances(\n accountIds,\n undefined,\n fetchOptions,\n ),\n this.#fetchTimeoutMs,\n );\n\n const { assetsBalance } = this.#processV5Balances(\n apiResponse.balances,\n request,\n );\n\n return {\n unprocessedNetworks: apiResponse.unprocessedNetworks,\n assetsBalance,\n };\n }\n\n /**\n * Fetch balances from the v6 endpoint and process them.\n *\n * @param accountIds - CAIP-10 account IDs to fetch balances for.\n * @param fetchOptions - Cache/fetch options (e.g. force update settings).\n * @param request - The original data request containing accounts to map.\n * @returns Unprocessed networks and processed asset balances by account.\n */\n async #fetchV6Balances(\n accountIds: string[],\n fetchOptions: { staleTime: number; gcTime: number } | undefined,\n request: DataRequest,\n ): Promise<{\n unprocessedNetworks: string[];\n assetsBalance: Record<string, Record<Caip19AssetId, AssetBalance>>;\n }> {\n const apiResponse = await fetchWithTimeout(\n () =>\n this.#apiClient.accounts.fetchV6MultiAccountBalances(\n accountIds,\n undefined,\n fetchOptions,\n ),\n this.#fetchTimeoutMs,\n );\n\n const { assetsBalance } = this.#processV6Balances(\n apiResponse.accounts,\n request,\n );\n\n return {\n unprocessedNetworks: apiResponse.unprocessedNetworks,\n assetsBalance,\n };\n }\n\n /**\n * Build a lookup of lowercased account address to the request's account ID.\n *\n * @param request - The original data request containing accounts to map.\n * @returns Map of lowercase address to account ID.\n */\n #buildAddressToAccountIdMap(request: DataRequest): Map<string, string> {\n const addressToAccountId = new Map<string, string>();\n for (const { account } of request.accountsWithSupportedChains) {\n if (account.address) {\n addressToAccountId.set(account.address.toLowerCase(), account.id);\n }\n }\n return addressToAccountId;\n }\n\n /**\n * Process V5 API balances response.\n * V5 returns a flat array of balance items, each with accountId and assetId.\n *\n * @param balances - Array of balance items from the V5 API response.\n * @param request - The original data request containing accounts to map.\n * @returns Object containing processed asset balances by account.\n */\n #processV5Balances(\n balances: V5BalanceItem[],\n request: DataRequest,\n ): {\n assetsBalance: Record<string, Record<Caip19AssetId, AssetBalance>>;\n } {\n const assetsBalance: Record<\n string,\n Record<Caip19AssetId, AssetBalance>\n > = {};\n\n // Build a map of lowercase addresses to account IDs for efficient lookup\n const addressToAccountId = this.#buildAddressToAccountIdMap(request);\n\n // V5 response: array of { accountId, assetId, balance, ... }\n for (const item of balances) {\n // Extract address from CAIP-10 account ID (e.g., \"eip155:1:0x1234...\" -> \"0x1234...\")\n const addressParts = item.accountId.split(':');\n if (addressParts.length < 3) {\n continue;\n }\n const address = addressParts[2].toLowerCase();\n\n // Find the matching account ID from request\n const accountId = addressToAccountId.get(address);\n if (!accountId) {\n // This is normal - API returns balances for all chains, but request may only have one account\n continue;\n }\n\n if (!assetsBalance[accountId]) {\n assetsBalance[accountId] = {};\n }\n\n // Normalize asset ID (checksum EVM addresses for ERC20 tokens)\n const normalizedAssetId = normalizeAssetId(item.assetId as Caip19AssetId);\n\n // Store balance as returned by API\n assetsBalance[accountId][normalizedAssetId] = {\n amount: item.balance,\n };\n }\n\n return { assetsBalance };\n }\n\n /**\n * Process V6 API balances response.\n * V6 groups balances per account (`accounts: [{ accountId, balances }]`).\n * Only `category: 'token'` rows are consumed here to preserve parity with\n * the v5 token-balance behavior; DeFi positions are ignored.\n *\n * @param accounts - Per-account balance entries from the V6 API response.\n * @param request - The original data request containing accounts to map.\n * @returns Object containing processed asset balances by account.\n */\n #processV6Balances(\n accounts: V6AccountBalancesEntry[],\n request: DataRequest,\n ): {\n assetsBalance: Record<string, Record<Caip19AssetId, AssetBalance>>;\n } {\n const assetsBalance = Object.create(null) as Record<\n string,\n Record<Caip19AssetId, AssetBalance>\n >;\n\n // Build a map of lowercase addresses to account IDs for efficient lookup\n const addressToAccountId = this.#buildAddressToAccountIdMap(request);\n\n for (const entry of accounts) {\n // Extract address from CAIP-10 account ID (e.g., \"eip155:1:0x1234...\" -> \"0x1234...\")\n const addressParts = entry.accountId.split(':');\n if (addressParts.length < 3) {\n continue;\n }\n const address = addressParts[2].toLowerCase();\n\n // Find the matching account ID from request\n const accountId = addressToAccountId.get(address);\n if (!accountId) {\n // This is normal - API returns balances for all chains, but request may only have one account\n continue;\n }\n\n for (const item of entry.balances) {\n // Only consume token balances; DeFi positions are handled elsewhere.\n if (item.category !== 'token') {\n continue;\n }\n\n if (!assetsBalance[accountId]) {\n assetsBalance[accountId] = Object.create(null) as Record<\n Caip19AssetId,\n AssetBalance\n >;\n }\n\n // Normalize asset ID (checksum EVM addresses for ERC20 tokens)\n const normalizedAssetId = normalizeAssetId(\n item.assetId as Caip19AssetId,\n );\n\n // Store balance as returned by API\n assetsBalance[accountId][normalizedAssetId] = {\n amount: item.balance,\n };\n }\n }\n\n return { assetsBalance };\n }\n\n // ============================================================================\n // MIDDLEWARE\n // ============================================================================\n\n /**\n * Get the middleware for fetching balances via Accounts API.\n * This middleware:\n * - Supports multiple accounts in a single request\n * - Uses unprocessedNetworks from API response to determine what to pass to next middleware\n * - Merges response into context\n * - Removes handled chains from request for next middleware\n *\n * @returns The middleware function for the assets pipeline.\n */\n get assetsMiddleware(): Middleware {\n return async (context, next) => {\n const { request } = context;\n\n // If no chains requested, skip to next middleware\n if (request.chainIds.length === 0) {\n return next(context);\n }\n\n let successfullyHandledChains: ChainId[] = [];\n\n try {\n const response = await this.fetch(request);\n\n // Merge response into context\n if (response.assetsBalance) {\n context.response.assetsBalance ??= {};\n for (const [accountId, accountBalances] of Object.entries(\n response.assetsBalance,\n )) {\n context.response.assetsBalance[accountId] = {\n ...context.response.assetsBalance[accountId],\n ...accountBalances,\n };\n }\n }\n\n // Determine successfully handled chains (exclude unprocessed/error chains)\n const unprocessedChains = new Set(Object.keys(response.errors ?? {}));\n successfullyHandledChains = request.chainIds.filter(\n (chainId) => !unprocessedChains.has(chainId),\n );\n\n // When token detection is off and we filtered out all balance data (e.g. new\n // account with empty state), do not claim any chain as handled so that RPC\n // middleware can still process them and fetch native balances (ETH, MATIC, etc.).\n if (\n !this.#tokenDetectionEnabled() &&\n (!response.assetsBalance ||\n Object.keys(response.assetsBalance).length === 0)\n ) {\n successfullyHandledChains = [];\n }\n } catch (error) {\n log('Middleware fetch failed', { error });\n successfullyHandledChains = [];\n }\n\n // Remove successfully handled chains from request for next middleware\n if (successfullyHandledChains.length > 0) {\n const remainingChains = request.chainIds.filter(\n (chainId) => !successfullyHandledChains.includes(chainId),\n );\n\n return next({\n ...context,\n request: {\n ...request,\n chainIds: remainingChains,\n },\n });\n }\n\n // No chains handled - pass context unchanged\n return next(context);\n };\n }\n\n // ============================================================================\n // SUBSCRIBE\n // ============================================================================\n\n async subscribe(subscriptionRequest: SubscriptionRequest): Promise<void> {\n const { request, subscriptionId, isUpdate } = subscriptionRequest;\n\n // Store state accessor for filtering when tokenDetectionEnabled is false\n if (subscriptionRequest.getAssetsState) {\n this.#getAssetsState = subscriptionRequest.getAssetsState;\n }\n\n // Try all requested chains - API will handle unsupported ones via unprocessedNetworks\n const chainsToSubscribe = request.chainIds;\n\n if (chainsToSubscribe.length === 0) {\n return;\n }\n\n // Handle subscription update - update both chains AND request (for accounts)\n if (isUpdate) {\n const existing = this.activeSubscriptions.get(subscriptionId);\n if (existing) {\n existing.chains = chainsToSubscribe;\n existing.request = request;\n return;\n }\n }\n\n // Clean up existing subscription if any\n await this.unsubscribe(subscriptionId);\n\n const pollInterval = request.updateInterval ?? this.#pollInterval;\n\n // Create poll function for this subscription\n const pollFn = async (): Promise<void> => {\n try {\n const subscription = this.activeSubscriptions.get(subscriptionId);\n if (!subscription?.request) {\n return;\n }\n\n // Use stored request (which gets updated on account changes)\n const fetchResponse = await this.fetch({\n ...subscription.request,\n chainIds: subscription.chains,\n });\n\n // Report update to AssetsController via callback\n await subscription.onAssetsUpdate(fetchResponse);\n } catch (error) {\n log('Subscription poll failed', { subscriptionId, error });\n }\n };\n\n // Set up polling\n const timer = setInterval(() => {\n pollFn().catch(console.error);\n }, pollInterval);\n\n // Store subscription with request for account updates\n this.activeSubscriptions.set(subscriptionId, {\n cleanup: () => {\n clearInterval(timer);\n },\n chains: chainsToSubscribe,\n request,\n onAssetsUpdate: subscriptionRequest.onAssetsUpdate,\n });\n\n // Initial fetch\n await pollFn();\n }\n\n // ============================================================================\n // CLEANUP\n // ============================================================================\n\n destroy(): void {\n if (this.#chainsRefreshTimer) {\n clearInterval(this.#chainsRefreshTimer);\n }\n\n super.destroy();\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"AccountsApiDataSource.mjs","sourceRoot":"","sources":["../../src/data-sources/AccountsApiDataSource.ts"],"names":[],"mappings":";;;;;;;;;;;;AAIA,OAAO,EAAE,iBAAiB,EAAE,+BAA+B;AAE3D,OAAO,EACL,aAAa,EACb,kBAAkB,EAClB,aAAa,EACd,wBAAwB;AAGzB,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,sBAAkB;AAU9D,OAAO,EAAE,gBAAgB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AC;YACf,8FAA8F;YAC9F,SAAS;QACX,CAAC;QAED,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,QAAQ,EAAE,CAAC;YAClC,qEAAqE;YACrE,IAAI,IAAI,CAAC,QAAQ,KAAK,OAAO,EAAE,CAAC;gBAC9B,SAAS;YACX,CAAC;YAED,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC,EAAE,CAAC;gBAC9B,aAAa,CAAC,SAAS,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAG5C,CAAC;YACJ,CAAC;YAED,+DAA+D;YAC/D,MAAM,iBAAiB,GAAG,gBAAgB,CACxC,IAAI,CAAC,OAAwB,CAC9B,CAAC;YAEF,mCAAmC;YACnC,aAAa,CAAC,SAAS,CAAC,CAAC,iBAAiB,CAAC,GAAG;gBAC5C,MAAM,EAAE,IAAI,CAAC,OAAO;aACrB,CAAC;QACJ,CAAC;IACH,CAAC;IAED,OAAO,EAAE,aAAa,EAAE,CAAC;AAC3B,CAAC","sourcesContent":["import type {\n V5BalanceItem,\n V6AccountBalancesEntry,\n} from '@metamask/core-backend';\nimport { ApiPlatformClient } from '@metamask/core-backend';\nimport type { RemoteFeatureFlagControllerGetStateAction } from '@metamask/remote-feature-flag-controller';\nimport {\n isCaipChainId,\n KnownCaipNamespace,\n toCaipChainId,\n} from '@metamask/utils';\n\nimport type { AssetsControllerMessenger } from '../AssetsController';\nimport { projectLogger, createModuleLogger } from '../logger';\nimport type {\n ChainId,\n Caip19AssetId,\n AssetBalance,\n DataRequest,\n DataResponse,\n Middleware,\n AssetsControllerStateInternal,\n} from '../types';\nimport { fetchWithTimeout, normalizeAssetId } from '../utils';\nimport type {\n DataSourceState,\n SubscriptionRequest,\n} from './AbstractDataSource';\nimport { AbstractDataSource } from './AbstractDataSource';\n\n// ============================================================================\n// CONSTANTS\n// ============================================================================\n\nconst CONTROLLER_NAME = 'AccountsApiDataSource';\nconst DEFAULT_POLL_INTERVAL = 30_000;\nconst DEFAULT_FETCH_TIMEOUT_MS = 15_000;\n\nconst log = createModuleLogger(projectLogger, CONTROLLER_NAME);\n\n// ============================================================================\n// MESSENGER TYPES\n// ============================================================================\n\n// Allowed actions that AccountsApiDataSource can call. Balances are fetched via\n// ApiPlatformClient directly (no BackendApiClient actions needed); the messenger\n// is only used to read the Accounts API v6 balances feature flag.\nexport type AccountsApiDataSourceAllowedActions =\n RemoteFeatureFlagControllerGetStateAction;\n\n// ============================================================================\n// STATE\n// ============================================================================\n\nexport type AccountsApiDataSourceState = DataSourceState;\n\nconst defaultState: AccountsApiDataSourceState = {\n activeChains: [],\n};\n\n// ============================================================================\n// OPTIONS\n// ============================================================================\n\n/** Optional configuration for AccountsApiDataSource. */\nexport type AccountsApiDataSourceConfig = {\n /** Polling interval in ms (default: 30000) */\n pollInterval?: number;\n /**\n * Function returning whether token detection is enabled (default: () => true).\n * When it returns false, balances are only returned for tokens already in state.\n * Using a getter avoids stale values when the user toggles the preference at runtime.\n */\n tokenDetectionEnabled?: () => boolean;\n /**\n * Timeout in ms for a single balances fetch call (default: 15000).\n * When it fires, every requested chain is marked as errored so the\n * middleware hands them off to the next data source (e.g. RPC fallback).\n */\n fetchTimeoutMs?: number;\n};\n\nexport type AccountsApiDataSourceOptions = AccountsApiDataSourceConfig & {\n /**\n * The AssetsController messenger (shared by all data sources). Used to read\n * the `assetsAccountsApiV6` remote feature flag.\n */\n messenger: AssetsControllerMessenger;\n /** ApiPlatformClient for API calls with caching */\n queryApiClient: ApiPlatformClient;\n /** Called when active chains are updated. Pass dataSourceName so the controller knows the source. */\n onActiveChainsUpdated: (\n dataSourceName: string,\n chains: ChainId[],\n previousChains: ChainId[],\n ) => void;\n state?: Partial<AccountsApiDataSourceState>;\n};\n\n// ============================================================================\n// HELPER FUNCTIONS\n// ============================================================================\n\nfunction decimalToChainId(decimalChainId: number | string): ChainId {\n // Handle both decimal numbers and already-formatted CAIP chain IDs\n if (typeof decimalChainId === 'string') {\n if (isCaipChainId(decimalChainId)) {\n return decimalChainId;\n }\n return toCaipChainId(KnownCaipNamespace.Eip155, decimalChainId);\n }\n return toCaipChainId(KnownCaipNamespace.Eip155, String(decimalChainId));\n}\n\n/**\n * Convert a CAIP-2 chain ID from the API response to our ChainId type.\n * Handles both formats: \"eip155:1\" or just \"1\" (decimal).\n * Uses @metamask/utils for CAIP parsing.\n *\n * @param chainIdStr - The chain ID string to convert.\n * @returns The normalized ChainId.\n */\nfunction caipChainIdToChainId(chainIdStr: string): ChainId {\n if (isCaipChainId(chainIdStr)) {\n return chainIdStr;\n }\n return toCaipChainId(KnownCaipNamespace.Eip155, chainIdStr);\n}\n\n/**\n * Filter a response to only include balances for assets already in state.\n * Used when tokenDetectionEnabled is false to prevent adding new tokens.\n *\n * @param response - The fetch response to filter.\n * @param assetsState - Current assets controller state to check existing balances against.\n * @returns A new response with only known asset balances.\n */\nexport function filterResponseToKnownAssets(\n response: DataResponse,\n assetsState: AssetsControllerStateInternal,\n): DataResponse {\n if (!response.assetsBalance) {\n return response;\n }\n\n const filteredBalance: Record<\n string,\n Record<Caip19AssetId, AssetBalance>\n > = {};\n\n for (const [accountId, accountBalances] of Object.entries(\n response.assetsBalance,\n )) {\n const existingBalances = assetsState.assetsBalance[accountId];\n if (!existingBalances) {\n // Account has no balances in state yet — skip all its tokens\n continue;\n }\n\n const filtered: Record<Caip19AssetId, AssetBalance> = {};\n for (const [assetId, balance] of Object.entries(accountBalances)) {\n // Only include assets already tracked in state\n if (assetId in existingBalances) {\n filtered[assetId as Caip19AssetId] = balance;\n }\n }\n\n if (Object.keys(filtered).length > 0) {\n filteredBalance[accountId] = filtered;\n }\n }\n\n return {\n ...response,\n assetsBalance:\n Object.keys(filteredBalance).length > 0 ? filteredBalance : undefined,\n };\n}\n\n// ============================================================================\n// ACCOUNTS API DATA SOURCE\n// ============================================================================\n\n/**\n * Data source for fetching balances from the MetaMask Accounts API.\n *\n * Uses ApiPlatformClient (queryApiClient) for all API calls. Does not use the\n * messenger. Reports active chains via onActiveChainsUpdated callback.\n */\nexport class AccountsApiDataSource extends AbstractDataSource<\n typeof CONTROLLER_NAME,\n AccountsApiDataSourceState\n> {\n readonly #onActiveChainsUpdated: (\n dataSourceName: string,\n chains: ChainId[],\n previousChains: ChainId[],\n ) => void;\n\n readonly #pollInterval: number;\n\n readonly #fetchTimeoutMs: number;\n\n /** Getter avoids stale value when user toggles token detection at runtime. */\n readonly #tokenDetectionEnabled: () => boolean;\n\n /** Shared AssetsController messenger, used to read remote feature flags. */\n readonly #messenger: AssetsControllerMessenger;\n\n /** ApiPlatformClient for cached API calls */\n readonly #apiClient: ApiPlatformClient;\n\n /** Chains refresh timer */\n #chainsRefreshTimer: ReturnType<typeof setInterval> | null = null;\n\n /** State accessor from subscriptions (for filtering when tokenDetectionEnabled is false) */\n #getAssetsState?: () => AssetsControllerStateInternal;\n\n constructor(options: AccountsApiDataSourceOptions) {\n super(CONTROLLER_NAME, {\n ...defaultState,\n ...options.state,\n });\n\n this.#onActiveChainsUpdated = options.onActiveChainsUpdated;\n this.#pollInterval = options.pollInterval ?? DEFAULT_POLL_INTERVAL;\n this.#fetchTimeoutMs = options.fetchTimeoutMs ?? DEFAULT_FETCH_TIMEOUT_MS;\n this.#tokenDetectionEnabled =\n options.tokenDetectionEnabled ?? ((): boolean => true);\n this.#messenger = options.messenger;\n this.#apiClient = options.queryApiClient;\n\n this.#initializeActiveChains().catch(console.error);\n }\n\n /**\n * Whether the Accounts API v6 balances endpoint is enabled, read from the\n * RemoteFeatureFlagController (`assetsAccountsApiV6`). Read on demand (per\n * fetch) rather than cached so the value can be toggled at runtime, and behaves\n * the same across clients (extension, mobile). Defaults to `false` when the\n * flag is unset or the controller is unavailable.\n *\n * The flag is a LaunchDarkly JSON variation shaped `{ value: boolean }` (same\n * shape as `backendWebSocketConnection`), so the nested `value` is read rather\n * than treating the flag as a plain boolean.\n *\n * @returns `true` when the v6 balances endpoint should be used.\n */\n #isBalanceV6Enabled(): boolean {\n try {\n const { remoteFeatureFlags } = this.#messenger.call(\n 'RemoteFeatureFlagController:getState',\n );\n const flag = remoteFeatureFlags?.assetsAccountsApiV6;\n return (\n typeof flag === 'object' &&\n flag !== null &&\n Boolean((flag as { value?: unknown }).value)\n );\n } catch {\n return false;\n }\n }\n\n // ============================================================================\n // INITIALIZATION\n // ============================================================================\n\n async #initializeActiveChains(): Promise<void> {\n try {\n const chains = await this.#fetchActiveChains();\n const previous = [...this.state.activeChains];\n this.updateActiveChains(chains, (updatedChains) =>\n this.#onActiveChainsUpdated(this.getName(), updatedChains, previous),\n );\n\n // Periodically refresh active chains (every 20 minutes)\n this.#chainsRefreshTimer = setInterval(\n () => {\n this.#refreshActiveChains().catch(console.error);\n },\n 20 * 60 * 1000,\n );\n } catch (error) {\n log('Failed to fetch active chains', error);\n }\n }\n\n async #refreshActiveChains(): Promise<void> {\n try {\n const chains = await this.#fetchActiveChains();\n const previousChains = new Set(this.state.activeChains);\n const newChains = new Set(chains);\n\n // Check if chains changed\n const added = chains.filter((chain) => !previousChains.has(chain));\n const removed = Array.from(previousChains).filter(\n (chain) => !newChains.has(chain),\n );\n\n if (added.length > 0 || removed.length > 0) {\n const previous = [...this.state.activeChains];\n this.updateActiveChains(chains, (updatedChains) =>\n this.#onActiveChainsUpdated(this.getName(), updatedChains, previous),\n );\n }\n } catch (error) {\n log('Failed to refresh active chains', error);\n }\n }\n\n /**\n * Re-fetch supported networks from the Accounts API and update `activeChains`\n * when the list changed. Used when the selected EVM network switches so\n * chain claiming is not stuck on an empty init-time list.\n *\n * @returns Resolves when supported networks have been re-fetched.\n */\n refreshActiveChains(): Promise<void> {\n return this.#refreshActiveChains();\n }\n\n async #fetchActiveChains(): Promise<ChainId[]> {\n const response = await this.#apiClient.accounts.fetchV2SupportedNetworks();\n\n // Use fullSupport networks as active chains\n return (\n response.fullSupport\n .map(decimalToChainId)\n // TODO Restore solana when there is a fix for how we handle non-evm chains here\n .filter((chainId) => chainId.startsWith('eip155:'))\n );\n }\n\n // ============================================================================\n // ACCOUNT SCOPE HELPERS\n // ============================================================================\n\n // ============================================================================\n // FETCH\n // ============================================================================\n\n async fetch(request: DataRequest): Promise<DataResponse> {\n let response: DataResponse = {};\n\n // Filter to only chains supported by Accounts API\n const supportedChains = new Set(this.state.activeChains);\n const chainsToFetch = request.chainIds.filter((chainId) =>\n supportedChains.has(chainId),\n );\n\n if (chainsToFetch.length === 0) {\n // Mark unsupported chains as errors so they pass to next middleware\n for (const chainId of request.chainIds) {\n if (!supportedChains.has(chainId)) {\n response.errors = response.errors ?? {};\n response.errors[chainId] = 'Chain not supported by Accounts API';\n }\n }\n return response;\n }\n\n try {\n // Build CAIP-10 account IDs (e.g., \"eip155:1:0x1234...\")\n // Use pre-computed supportedChains per account from the request\n const accountIds = request.accountsWithSupportedChains.flatMap(\n ({ account, supportedChains: accountChains }) =>\n chainsToFetch\n .filter((chainId) => accountChains.includes(chainId))\n .map((chainId) => `${chainId}:${account.address}`),\n );\n\n // Skip API call if no valid account-chain combinations\n if (accountIds.length === 0) {\n return response;\n }\n\n const fetchOptions = request.forceUpdate\n ? { staleTime: 0, gcTime: 0 }\n : undefined;\n\n // Feature-flagged: v6 endpoint with a fallback to legacy v5. The flag is\n // read here (not cached) so a runtime toggle can revert v6 -> v5.\n const { unprocessedNetworks, assetsBalance } = this.#isBalanceV6Enabled()\n ? await this.#fetchV6Balances(accountIds, fetchOptions, request)\n : await this.#fetchV5Balances(accountIds, fetchOptions, request);\n\n // Handle unprocessed networks - these will be passed to next middleware\n if (unprocessedNetworks.length > 0) {\n const unprocessedChainIds =\n unprocessedNetworks.map(caipChainIdToChainId);\n\n // Add unprocessed chains to errors so middleware passes them to next data source\n response.errors = response.errors ?? {};\n for (const chainId of unprocessedChainIds) {\n response.errors[chainId] = 'Unprocessed by Accounts API';\n }\n }\n\n response.assetsBalance = assetsBalance;\n response.updateMode = 'merge';\n } catch (error) {\n log('Fetch FAILED', { error, chains: chainsToFetch });\n\n // On error, mark all chains as errors so they can be handled by next middleware\n response.errors = response.errors ?? {};\n for (const chainId of chainsToFetch) {\n response.errors[chainId] =\n `Fetch failed: ${error instanceof Error ? error.message : String(error)}`;\n }\n }\n\n // Mark unsupported chains as errors so they pass to next middleware\n for (const chainId of request.chainIds) {\n if (!supportedChains.has(chainId)) {\n response.errors = response.errors ?? {};\n response.errors[chainId] = 'Chain not supported by Accounts API';\n }\n }\n\n // When token detection is disabled, filter out tokens not already in state\n if (!this.#tokenDetectionEnabled() && this.#getAssetsState) {\n response = filterResponseToKnownAssets(response, this.#getAssetsState());\n }\n\n return response;\n }\n\n /**\n * Fetch balances from the legacy v5 endpoint and process them.\n *\n * @param accountIds - CAIP-10 account IDs to fetch balances for.\n * @param fetchOptions - Cache/fetch options (e.g. force update settings).\n * @param request - The original data request containing accounts to map.\n * @returns Unprocessed networks and processed asset balances by account.\n */\n async #fetchV5Balances(\n accountIds: string[],\n fetchOptions: { staleTime: number; gcTime: number } | undefined,\n request: DataRequest,\n ): Promise<{\n unprocessedNetworks: string[];\n assetsBalance: Record<string, Record<Caip19AssetId, AssetBalance>>;\n }> {\n const apiResponse = await fetchWithTimeout(\n () =>\n this.#apiClient.accounts.fetchV5MultiAccountBalances(\n accountIds,\n undefined,\n fetchOptions,\n ),\n this.#fetchTimeoutMs,\n );\n\n const { assetsBalance } = this.#processV5Balances(\n apiResponse.balances,\n request,\n );\n\n return {\n unprocessedNetworks: apiResponse.unprocessedNetworks,\n assetsBalance,\n };\n }\n\n /**\n * Fetch balances from the v6 endpoint and process them.\n *\n * @param accountIds - CAIP-10 account IDs to fetch balances for.\n * @param fetchOptions - Cache/fetch options (e.g. force update settings).\n * @param request - The original data request containing accounts to map.\n * @returns Unprocessed networks and processed asset balances by account.\n */\n async #fetchV6Balances(\n accountIds: string[],\n fetchOptions: { staleTime: number; gcTime: number } | undefined,\n request: DataRequest,\n ): Promise<{\n unprocessedNetworks: string[];\n assetsBalance: Record<string, Record<Caip19AssetId, AssetBalance>>;\n }> {\n const apiResponse = await fetchWithTimeout(\n () =>\n this.#apiClient.accounts.fetchV6MultiAccountBalances(\n accountIds,\n undefined,\n fetchOptions,\n ),\n this.#fetchTimeoutMs,\n );\n\n const { assetsBalance } = this.#processV6Balances(\n apiResponse.accounts,\n request,\n );\n\n return {\n unprocessedNetworks: apiResponse.unprocessedNetworks,\n assetsBalance,\n };\n }\n\n /**\n * Build a lookup of lowercased account address to the request's account ID.\n *\n * @param request - The original data request containing accounts to map.\n * @returns Map of lowercase address to account ID.\n */\n #buildAddressToAccountIdMap(request: DataRequest): Map<string, string> {\n const addressToAccountId = new Map<string, string>();\n for (const { account } of request.accountsWithSupportedChains) {\n if (account.address) {\n addressToAccountId.set(account.address.toLowerCase(), account.id);\n }\n }\n return addressToAccountId;\n }\n\n /**\n * Process V5 API balances response.\n * V5 returns a flat array of balance items, each with accountId and assetId.\n *\n * @param balances - Array of balance items from the V5 API response.\n * @param request - The original data request containing accounts to map.\n * @returns Object containing processed asset balances by account.\n */\n #processV5Balances(\n balances: V5BalanceItem[],\n request: DataRequest,\n ): {\n assetsBalance: Record<string, Record<Caip19AssetId, AssetBalance>>;\n } {\n const assetsBalance: Record<\n string,\n Record<Caip19AssetId, AssetBalance>\n > = {};\n\n // Build a map of lowercase addresses to account IDs for efficient lookup\n const addressToAccountId = this.#buildAddressToAccountIdMap(request);\n\n // V5 response: array of { accountId, assetId, balance, ... }\n for (const item of balances) {\n // Extract address from CAIP-10 account ID (e.g., \"eip155:1:0x1234...\" -> \"0x1234...\")\n const addressParts = item.accountId.split(':');\n if (addressParts.length < 3) {\n continue;\n }\n const address = addressParts[2].toLowerCase();\n\n // Find the matching account ID from request\n const accountId = addressToAccountId.get(address);\n if (!accountId) {\n // This is normal - API returns balances for all chains, but request may only have one account\n continue;\n }\n\n if (!assetsBalance[accountId]) {\n assetsBalance[accountId] = {};\n }\n\n // Normalize asset ID (checksum EVM addresses for ERC20 tokens)\n const normalizedAssetId = normalizeAssetId(item.assetId as Caip19AssetId);\n\n // Store balance as returned by API\n assetsBalance[accountId][normalizedAssetId] = {\n amount: item.balance,\n };\n }\n\n return { assetsBalance };\n }\n\n /**\n * Process V6 API balances response.\n * V6 groups balances per account (`accounts: [{ accountId, balances }]`).\n * Only `category: 'token'` rows are consumed here to preserve parity with\n * the v5 token-balance behavior; DeFi positions are ignored.\n *\n * @param accounts - Per-account balance entries from the V6 API response.\n * @param request - The original data request containing accounts to map.\n * @returns Object containing processed asset balances by account.\n */\n #processV6Balances(\n accounts: V6AccountBalancesEntry[],\n request: DataRequest,\n ): {\n assetsBalance: Record<string, Record<Caip19AssetId, AssetBalance>>;\n } {\n const assetsBalance = Object.create(null) as Record<\n string,\n Record<Caip19AssetId, AssetBalance>\n >;\n\n // Build a map of lowercase addresses to account IDs for efficient lookup\n const addressToAccountId = this.#buildAddressToAccountIdMap(request);\n\n for (const entry of accounts) {\n // Extract address from CAIP-10 account ID (e.g., \"eip155:1:0x1234...\" -> \"0x1234...\")\n const addressParts = entry.accountId.split(':');\n if (addressParts.length < 3) {\n continue;\n }\n const address = addressParts[2].toLowerCase();\n\n // Find the matching account ID from request\n const accountId = addressToAccountId.get(address);\n if (!accountId) {\n // This is normal - API returns balances for all chains, but request may only have one account\n continue;\n }\n\n for (const item of entry.balances) {\n // Only consume token balances; DeFi positions are handled elsewhere.\n if (item.category !== 'token') {\n continue;\n }\n\n if (!assetsBalance[accountId]) {\n assetsBalance[accountId] = Object.create(null) as Record<\n Caip19AssetId,\n AssetBalance\n >;\n }\n\n // Normalize asset ID (checksum EVM addresses for ERC20 tokens)\n const normalizedAssetId = normalizeAssetId(\n item.assetId as Caip19AssetId,\n );\n\n // Store balance as returned by API\n assetsBalance[accountId][normalizedAssetId] = {\n amount: item.balance,\n };\n }\n }\n\n return { assetsBalance };\n }\n\n // ============================================================================\n // MIDDLEWARE\n // ============================================================================\n\n /**\n * Get the middleware for fetching balances via Accounts API.\n * This middleware:\n * - Supports multiple accounts in a single request\n * - Uses unprocessedNetworks from API response to determine what to pass to next middleware\n * - Merges response into context\n * - Removes handled chains from request for next middleware\n *\n * @returns The middleware function for the assets pipeline.\n */\n get assetsMiddleware(): Middleware {\n return async (context, next) => {\n const { request } = context;\n\n // If no chains requested, skip to next middleware\n if (request.chainIds.length === 0) {\n return next(context);\n }\n\n let successfullyHandledChains: ChainId[] = [];\n\n try {\n const response = await this.fetch(request);\n\n // Merge response into context\n if (response.assetsBalance) {\n context.response.assetsBalance ??= {};\n for (const [accountId, accountBalances] of Object.entries(\n response.assetsBalance,\n )) {\n context.response.assetsBalance[accountId] = {\n ...context.response.assetsBalance[accountId],\n ...accountBalances,\n };\n }\n }\n\n // Determine successfully handled chains (exclude unprocessed/error chains)\n const unprocessedChains = new Set(Object.keys(response.errors ?? {}));\n successfullyHandledChains = request.chainIds.filter(\n (chainId) => !unprocessedChains.has(chainId),\n );\n\n // When token detection is off and we filtered out all balance data (e.g. new\n // account with empty state), do not claim any chain as handled so that RPC\n // middleware can still process them and fetch native balances (ETH, MATIC, etc.).\n if (\n !this.#tokenDetectionEnabled() &&\n (!response.assetsBalance ||\n Object.keys(response.assetsBalance).length === 0)\n ) {\n successfullyHandledChains = [];\n }\n } catch (error) {\n log('Middleware fetch failed', { error });\n successfullyHandledChains = [];\n }\n\n // Remove successfully handled chains from request for next middleware\n if (successfullyHandledChains.length > 0) {\n const remainingChains = request.chainIds.filter(\n (chainId) => !successfullyHandledChains.includes(chainId),\n );\n\n return next({\n ...context,\n request: {\n ...request,\n chainIds: remainingChains,\n },\n });\n }\n\n // No chains handled - pass context unchanged\n return next(context);\n };\n }\n\n // ============================================================================\n // SUBSCRIBE\n // ============================================================================\n\n async subscribe(subscriptionRequest: SubscriptionRequest): Promise<void> {\n const { request, subscriptionId, isUpdate } = subscriptionRequest;\n\n // Store state accessor for filtering when tokenDetectionEnabled is false\n if (subscriptionRequest.getAssetsState) {\n this.#getAssetsState = subscriptionRequest.getAssetsState;\n }\n\n // Try all requested chains - API will handle unsupported ones via unprocessedNetworks\n const chainsToSubscribe = request.chainIds;\n\n if (chainsToSubscribe.length === 0) {\n return;\n }\n\n // Handle subscription update - update both chains AND request (for accounts)\n if (isUpdate) {\n const existing = this.activeSubscriptions.get(subscriptionId);\n if (existing) {\n existing.chains = chainsToSubscribe;\n existing.request = request;\n return;\n }\n }\n\n // Clean up existing subscription if any\n await this.unsubscribe(subscriptionId);\n\n const pollInterval = request.updateInterval ?? this.#pollInterval;\n\n // Create poll function for this subscription\n const pollFn = async (): Promise<void> => {\n try {\n const subscription = this.activeSubscriptions.get(subscriptionId);\n if (!subscription?.request) {\n return;\n }\n\n // Use stored request (which gets updated on account changes)\n const fetchResponse = await this.fetch({\n ...subscription.request,\n chainIds: subscription.chains,\n });\n\n // Report update to AssetsController via callback\n await subscription.onAssetsUpdate(fetchResponse);\n } catch (error) {\n log('Subscription poll failed', { subscriptionId, error });\n }\n };\n\n // Set up polling\n const timer = setInterval(() => {\n pollFn().catch(console.error);\n }, pollInterval);\n\n // Store subscription with request for account updates\n this.activeSubscriptions.set(subscriptionId, {\n cleanup: () => {\n clearInterval(timer);\n },\n chains: chainsToSubscribe,\n request,\n onAssetsUpdate: subscriptionRequest.onAssetsUpdate,\n });\n\n // Initial fetch\n await pollFn();\n }\n\n // ============================================================================\n // CLEANUP\n // ============================================================================\n\n destroy(): void {\n // Clean up timers\n if (this.#chainsRefreshTimer) {\n clearInterval(this.#chainsRefreshTimer);\n }\n\n // Clean up subscriptions\n super.destroy();\n }\n}\n"]}
|
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getInternalAccountsForGroup = exports.getGroupIdForAccount = exports.getAggregatedBalanceForAccount = exports.calculateBalanceChangeForAccountGroup = exports.calculateBalanceForAllWallets = exports.formatStateForTransactionPay = exports.formatExchangeRatesForBridge = exports.normalizeAssetId = exports.RpcFallbackMiddleware = exports.DetectionMiddleware = exports.CustomAssetGraduationMiddleware = exports.PriceDataSource = exports.TokenDataSource = exports.extractChainFromAssetId = exports.getChainIdsCaveat = exports.KEYRING_PERMISSION = exports.SNAP_DATA_SOURCE_NAME = exports.createSnapDataSource = exports.SnapDataSource = exports.createRpcDataSource = exports.RpcDataSource = exports.createBackendWebsocketDataSource = exports.BackendWebsocketDataSource = exports.AccountsApiDataSource = exports.AbstractDataSource = exports.
|
|
3
|
+
exports.getInternalAccountsForGroup = exports.getGroupIdForAccount = exports.getAggregatedBalanceForAccount = exports.calculateBalanceChangeForAccountGroup = exports.calculateBalanceForAllWallets = exports.formatStateForTransactionPay = exports.formatExchangeRatesForBridge = exports.normalizeAssetId = exports.RpcFallbackMiddleware = exports.DetectionMiddleware = exports.CustomAssetGraduationMiddleware = exports.PriceDataSource = exports.TokenDataSource = exports.extractChainFromAssetId = exports.getChainIdsCaveat = exports.KEYRING_PERMISSION = exports.SNAP_DATA_SOURCE_NAME = exports.createSnapDataSource = exports.SnapDataSource = exports.createRpcDataSource = exports.RpcDataSource = exports.createBackendWebsocketDataSource = exports.BackendWebsocketDataSource = exports.AccountsApiDataSource = exports.AbstractDataSource = exports.getDefaultAssetMetadata = exports.getDefaultTrackedAssetsForChain = exports.buildDefaultAssetsInfo = exports.DEFAULT_ASSET_METADATA = exports.CHAINS_WITH_DEFAULT_TRACKED_ASSETS = exports.DEFAULT_TRACKED_ASSETS_BY_CHAIN = exports.AssetsDataSourceError = exports.getDefaultAssetsControllerState = exports.AssetsController = void 0;
|
|
4
4
|
// Main controller export
|
|
5
5
|
var AssetsController_1 = require("./AssetsController.cjs");
|
|
6
6
|
Object.defineProperty(exports, "AssetsController", { enumerable: true, get: function () { return AssetsController_1.AssetsController; } });
|
|
@@ -14,15 +14,6 @@ Object.defineProperty(exports, "DEFAULT_ASSET_METADATA", { enumerable: true, get
|
|
|
14
14
|
Object.defineProperty(exports, "buildDefaultAssetsInfo", { enumerable: true, get: function () { return defaults_1.buildDefaultAssetsInfo; } });
|
|
15
15
|
Object.defineProperty(exports, "getDefaultTrackedAssetsForChain", { enumerable: true, get: function () { return defaults_1.getDefaultTrackedAssetsForChain; } });
|
|
16
16
|
Object.defineProperty(exports, "getDefaultAssetMetadata", { enumerable: true, get: function () { return defaults_1.getDefaultAssetMetadata; } });
|
|
17
|
-
// Snaps → AssetsController assets migration
|
|
18
|
-
var snaps_assets_migration_1 = require("./utils/snaps-assets-migration.cjs");
|
|
19
|
-
Object.defineProperty(exports, "SNAPS_ASSETS_MIGRATION_FLAG_KEYS", { enumerable: true, get: function () { return snaps_assets_migration_1.SNAPS_ASSETS_MIGRATION_FLAG_KEYS; } });
|
|
20
|
-
Object.defineProperty(exports, "SNAPS_ASSETS_MIGRATION_NAMESPACES", { enumerable: true, get: function () { return snaps_assets_migration_1.SNAPS_ASSETS_MIGRATION_NAMESPACES; } });
|
|
21
|
-
Object.defineProperty(exports, "SnapsAssetsMigrationStage", { enumerable: true, get: function () { return snaps_assets_migration_1.SnapsAssetsMigrationStage; } });
|
|
22
|
-
Object.defineProperty(exports, "getSnapsAssetsMigrationNamespace", { enumerable: true, get: function () { return snaps_assets_migration_1.getSnapsAssetsMigrationNamespace; } });
|
|
23
|
-
Object.defineProperty(exports, "isMigrationStageActive", { enumerable: true, get: function () { return snaps_assets_migration_1.isMigrationStageActive; } });
|
|
24
|
-
Object.defineProperty(exports, "isSnapsAssetsMigrationNamespace", { enumerable: true, get: function () { return snaps_assets_migration_1.isSnapsAssetsMigrationNamespace; } });
|
|
25
|
-
Object.defineProperty(exports, "parseSnapsAssetsMigrationStage", { enumerable: true, get: function () { return snaps_assets_migration_1.parseSnapsAssetsMigrationStage; } });
|
|
26
17
|
// Data sources - base class and types
|
|
27
18
|
var data_sources_1 = require("./data-sources/index.cjs");
|
|
28
19
|
Object.defineProperty(exports, "AbstractDataSource", { enumerable: true, get: function () { return data_sources_1.AbstractDataSource; } });
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,yBAAyB;AACzB,2DAG4B;AAF1B,oHAAA,gBAAgB,OAAA;AAChB,mIAAA,+BAA+B,OAAA;AAEjC,uCAAiD;AAAxC,+GAAA,qBAAqB,OAAA;AAC9B,2CAOoB;AANlB,2HAAA,+BAA+B,OAAA;AAC/B,8HAAA,kCAAkC,OAAA;AAClC,kHAAA,sBAAsB,OAAA;AACtB,kHAAA,sBAAsB,OAAA;AACtB,2HAAA,+BAA+B,OAAA;AAC/B,mHAAA,uBAAuB,OAAA;
|
|
1
|
+
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,yBAAyB;AACzB,2DAG4B;AAF1B,oHAAA,gBAAgB,OAAA;AAChB,mIAAA,+BAA+B,OAAA;AAEjC,uCAAiD;AAAxC,+GAAA,qBAAqB,OAAA;AAC9B,2CAOoB;AANlB,2HAAA,+BAA+B,OAAA;AAC/B,8HAAA,kCAAkC,OAAA;AAClC,kHAAA,sBAAsB,OAAA;AACtB,kHAAA,sBAAsB,OAAA;AACtB,2HAAA,+BAA+B,OAAA;AAC/B,mHAAA,uBAAuB,OAAA;AAuFzB,sCAAsC;AACtC,yDAAoD;AAA3C,kHAAA,kBAAkB,OAAA;AAI3B,6BAA6B;AAC7B,yDAAuD;AAA9C,qHAAA,qBAAqB,OAAA;AAQ9B,kCAAkC;AAClC,yDAGwB;AAFtB,0HAAA,0BAA0B,OAAA;AAC1B,gIAAA,gCAAgC,OAAA;AAQlC,qBAAqB;AACrB,yDAAoE;AAA3D,6GAAA,aAAa,OAAA;AAAE,mHAAA,mBAAmB,OAAA;AAS3C,gFAAgF;AAChF,yDASwB;AARtB,8GAAA,cAAc,OAAA;AACd,oHAAA,oBAAoB,OAAA;AACpB,qHAAA,qBAAqB,OAAA;AACrB,YAAY;AACZ,kHAAA,kBAAkB,OAAA;AAClB,oBAAoB;AACpB,iHAAA,iBAAiB,OAAA;AACjB,uHAAA,uBAAuB,OAAA;AAQzB,0BAA0B;AAC1B,yDAAkE;AAAzD,+GAAA,eAAe,OAAA;AAAE,+GAAA,eAAe,OAAA;AAQzC,cAAc;AACd,uDAIuB;AAHrB,8HAAA,+BAA+B,OAAA;AAC/B,kHAAA,mBAAmB,OAAA;AACnB,oHAAA,qBAAqB,OAAA;AAOvB,YAAY;AACZ,2CAIiB;AAHf,yGAAA,gBAAgB,OAAA;AAChB,qHAAA,4BAA4B,OAAA;AAC5B,qHAAA,4BAA4B,OAAA;AAS9B,YAAY;AACZ,mDAM6B;AAL3B,wHAAA,6BAA6B,OAAA;AAC7B,gIAAA,qCAAqC,OAAA;AACrC,yHAAA,8BAA8B,OAAA;AAC9B,+GAAA,oBAAoB,OAAA;AACpB,sHAAA,2BAA2B,OAAA","sourcesContent":["// Main controller export\nexport {\n AssetsController,\n getDefaultAssetsControllerState,\n} from './AssetsController';\nexport { AssetsDataSourceError } from './errors';\nexport {\n DEFAULT_TRACKED_ASSETS_BY_CHAIN,\n CHAINS_WITH_DEFAULT_TRACKED_ASSETS,\n DEFAULT_ASSET_METADATA,\n buildDefaultAssetsInfo,\n getDefaultTrackedAssetsForChain,\n getDefaultAssetMetadata,\n} from './defaults';\nexport type { PendingTokenMetadata } from './AssetsController';\n\n// State and messenger types\nexport type {\n AssetsControllerState,\n AssetsControllerMessenger,\n AssetsControllerOptions,\n AssetsControllerGetStateAction,\n AssetsControllerActions,\n AssetsControllerStateChangeEvent,\n AssetsControllerBalanceChangedEvent,\n AssetsControllerPriceChangedEvent,\n AssetsControllerAssetsDetectedEvent,\n AssetsControllerEvents,\n} from './AssetsController';\nexport type {\n AssetsControllerGetAssetsAction,\n AssetsControllerGetAssetsBalanceAction,\n AssetsControllerGetAssetMetadataAction,\n AssetsControllerGetAssetAction,\n AssetsControllerGetAssetsPriceAction,\n AssetsControllerAddCustomAssetAction,\n AssetsControllerRemoveCustomAssetAction,\n AssetsControllerGetCustomAssetsAction,\n AssetsControllerHideAssetAction,\n AssetsControllerUnhideAssetAction,\n AssetsControllerGetExchangeRatesForBridgeAction,\n AssetsControllerGetStateForTransactionPayAction,\n AssetsControllerSetSelectedCurrencyAction,\n} from './AssetsController-method-action-types';\n\n// Core types\nexport type {\n // CAIP types\n Caip19AssetId,\n AccountId,\n ChainId,\n // Asset types\n AssetType,\n TokenStandard,\n // Contract data types\n TokenFees,\n HoneypotStatus,\n StorageSlots,\n LocalizedDescription,\n // Metadata types\n BaseAssetMetadata,\n FungibleAssetMetadata,\n ERC721AssetMetadata,\n ERC1155AssetMetadata,\n AssetMetadata,\n // Price types\n BaseAssetPrice,\n FungibleAssetPrice,\n NFTAssetPrice,\n AssetPrice,\n // Balance types\n FungibleAssetBalance,\n ERC721AssetBalance,\n ERC1155AssetBalance,\n AssetBalance,\n // Data source types\n AccountWithSupportedChains,\n DataType,\n DataRequest,\n DataResponse,\n AssetsUpdateMode,\n // Middleware types\n Context,\n NextFunction,\n Middleware,\n AssetsDataSource,\n FetchContext,\n FetchNextFunction,\n FetchMiddleware,\n SubscriptionResponse,\n // Combined asset type\n Asset,\n // Event types\n BalanceChangeEvent,\n PriceChangeEvent,\n MetadataChangeEvent,\n AssetsDetectedEvent,\n} from './types';\n\n// Data sources - base class and types\nexport { AbstractDataSource } from './data-sources';\n\nexport type { DataSourceState, SubscriptionRequest } from './data-sources';\n\n// Data sources - AccountsApi\nexport { AccountsApiDataSource } from './data-sources';\n\nexport type {\n AccountsApiDataSourceConfig,\n AccountsApiDataSourceOptions,\n AccountsApiDataSourceState,\n} from './data-sources';\n\n// Data sources - BackendWebsocket\nexport {\n BackendWebsocketDataSource,\n createBackendWebsocketDataSource,\n} from './data-sources';\n\nexport type {\n BackendWebsocketDataSourceOptions,\n BackendWebsocketDataSourceState,\n} from './data-sources';\n\n// Data sources - RPC\nexport { RpcDataSource, createRpcDataSource } from './data-sources';\n\nexport type {\n RpcDataSourceConfig,\n RpcDataSourceOptions,\n RpcDataSourceState,\n ChainStatus,\n} from './data-sources';\n\n// Data sources - Unified Snap Data Source (dynamically discovers keyring snaps)\nexport {\n SnapDataSource,\n createSnapDataSource,\n SNAP_DATA_SOURCE_NAME,\n // Constants\n KEYRING_PERMISSION,\n // Utility functions\n getChainIdsCaveat,\n extractChainFromAssetId,\n} from './data-sources';\n\nexport type {\n SnapDataSourceState,\n SnapDataSourceOptions,\n} from './data-sources';\n\n// Enrichment data sources\nexport { TokenDataSource, PriceDataSource } from './data-sources';\n\nexport type {\n TokenDataSourceOptions,\n PriceDataSourceConfig,\n PriceDataSourceOptions,\n} from './data-sources';\n\n// Middlewares\nexport {\n CustomAssetGraduationMiddleware,\n DetectionMiddleware,\n RpcFallbackMiddleware,\n} from './middlewares';\nexport type {\n CustomAssetGraduationMiddlewareOptions,\n RpcFallbackMiddlewareOptions,\n} from './middlewares';\n\n// Utilities\nexport {\n normalizeAssetId,\n formatExchangeRatesForBridge,\n formatStateForTransactionPay,\n} from './utils';\nexport type {\n AccountForLegacyFormat,\n BridgeExchangeRatesFormat,\n LegacyToken,\n TransactionPayLegacyFormat,\n} from './utils';\n\n// Selectors\nexport {\n calculateBalanceForAllWallets,\n calculateBalanceChangeForAccountGroup,\n getAggregatedBalanceForAccount,\n getGroupIdForAccount,\n getInternalAccountsForGroup,\n} from './selectors/balance';\n\nexport type {\n AccountGroupBalance,\n AccountsById,\n AggregatedBalanceEntry,\n AggregatedBalanceForAccount,\n AllWalletsBalance,\n BalanceChangePeriod,\n BalanceChangeResult,\n EnabledNetworkMap,\n WalletBalance,\n} from './selectors/balance';\n"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -2,8 +2,6 @@ export { AssetsController, getDefaultAssetsControllerState, } from "./AssetsCont
|
|
|
2
2
|
export { AssetsDataSourceError } from "./errors.cjs";
|
|
3
3
|
export { DEFAULT_TRACKED_ASSETS_BY_CHAIN, CHAINS_WITH_DEFAULT_TRACKED_ASSETS, DEFAULT_ASSET_METADATA, buildDefaultAssetsInfo, getDefaultTrackedAssetsForChain, getDefaultAssetMetadata, } from "./defaults.cjs";
|
|
4
4
|
export type { PendingTokenMetadata } from "./AssetsController.cjs";
|
|
5
|
-
export { SNAPS_ASSETS_MIGRATION_FLAG_KEYS, SNAPS_ASSETS_MIGRATION_NAMESPACES, SnapsAssetsMigrationStage, getSnapsAssetsMigrationNamespace, isMigrationStageActive, isSnapsAssetsMigrationNamespace, parseSnapsAssetsMigrationStage, } from "./utils/snaps-assets-migration.cjs";
|
|
6
|
-
export type { SnapsAssetsMigrationNamespace } from "./utils/snaps-assets-migration.cjs";
|
|
7
5
|
export type { AssetsControllerState, AssetsControllerMessenger, AssetsControllerOptions, AssetsControllerGetStateAction, AssetsControllerActions, AssetsControllerStateChangeEvent, AssetsControllerBalanceChangedEvent, AssetsControllerPriceChangedEvent, AssetsControllerAssetsDetectedEvent, AssetsControllerEvents, } from "./AssetsController.cjs";
|
|
8
6
|
export type { AssetsControllerGetAssetsAction, AssetsControllerGetAssetsBalanceAction, AssetsControllerGetAssetMetadataAction, AssetsControllerGetAssetAction, AssetsControllerGetAssetsPriceAction, AssetsControllerAddCustomAssetAction, AssetsControllerRemoveCustomAssetAction, AssetsControllerGetCustomAssetsAction, AssetsControllerHideAssetAction, AssetsControllerUnhideAssetAction, AssetsControllerGetExchangeRatesForBridgeAction, AssetsControllerGetStateForTransactionPayAction, AssetsControllerSetSelectedCurrencyAction, } from "./AssetsController-method-action-types.cjs";
|
|
9
7
|
export type { Caip19AssetId, AccountId, ChainId, AssetType, TokenStandard, TokenFees, HoneypotStatus, StorageSlots, LocalizedDescription, BaseAssetMetadata, FungibleAssetMetadata, ERC721AssetMetadata, ERC1155AssetMetadata, AssetMetadata, BaseAssetPrice, FungibleAssetPrice, NFTAssetPrice, AssetPrice, FungibleAssetBalance, ERC721AssetBalance, ERC1155AssetBalance, AssetBalance, AccountWithSupportedChains, DataType, DataRequest, DataResponse, AssetsUpdateMode, Context, NextFunction, Middleware, AssetsDataSource, FetchContext, FetchNextFunction, FetchMiddleware, SubscriptionResponse, Asset, BalanceChangeEvent, PriceChangeEvent, MetadataChangeEvent, AssetsDetectedEvent, } from "./types.cjs";
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,gBAAgB,EAChB,+BAA+B,GAChC,+BAA2B;AAC5B,OAAO,EAAE,qBAAqB,EAAE,qBAAiB;AACjD,OAAO,EACL,+BAA+B,EAC/B,kCAAkC,EAClC,sBAAsB,EACtB,sBAAsB,EACtB,+BAA+B,EAC/B,uBAAuB,GACxB,uBAAmB;AACpB,YAAY,EAAE,oBAAoB,EAAE,+BAA2B;AAG/D,
|
|
1
|
+
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,gBAAgB,EAChB,+BAA+B,GAChC,+BAA2B;AAC5B,OAAO,EAAE,qBAAqB,EAAE,qBAAiB;AACjD,OAAO,EACL,+BAA+B,EAC/B,kCAAkC,EAClC,sBAAsB,EACtB,sBAAsB,EACtB,+BAA+B,EAC/B,uBAAuB,GACxB,uBAAmB;AACpB,YAAY,EAAE,oBAAoB,EAAE,+BAA2B;AAG/D,YAAY,EACV,qBAAqB,EACrB,yBAAyB,EACzB,uBAAuB,EACvB,8BAA8B,EAC9B,uBAAuB,EACvB,gCAAgC,EAChC,mCAAmC,EACnC,iCAAiC,EACjC,mCAAmC,EACnC,sBAAsB,GACvB,+BAA2B;AAC5B,YAAY,EACV,+BAA+B,EAC/B,sCAAsC,EACtC,sCAAsC,EACtC,8BAA8B,EAC9B,oCAAoC,EACpC,oCAAoC,EACpC,uCAAuC,EACvC,qCAAqC,EACrC,+BAA+B,EAC/B,iCAAiC,EACjC,+CAA+C,EAC/C,+CAA+C,EAC/C,yCAAyC,GAC1C,mDAA+C;AAGhD,YAAY,EAEV,aAAa,EACb,SAAS,EACT,OAAO,EAEP,SAAS,EACT,aAAa,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ACL,+BAA+B,EAC/B,mBAAmB,EACnB,qBAAqB,GACtB,gCAAsB;AACvB,YAAY,EACV,sCAAsC,EACtC,4BAA4B,GAC7B,gCAAsB;AAGvB,OAAO,EACL,gBAAgB,EAChB,4BAA4B,EAC5B,4BAA4B,GAC7B,0BAAgB;AACjB,YAAY,EACV,sBAAsB,EACtB,yBAAyB,EACzB,WAAW,EACX,0BAA0B,GAC3B,0BAAgB;AAGjB,OAAO,EACL,6BAA6B,EAC7B,qCAAqC,EACrC,8BAA8B,EAC9B,oBAAoB,EACpB,2BAA2B,GAC5B,gCAA4B;AAE7B,YAAY,EACV,mBAAmB,EACnB,YAAY,EACZ,sBAAsB,EACtB,2BAA2B,EAC3B,iBAAiB,EACjB,mBAAmB,EACnB,mBAAmB,EACnB,iBAAiB,EACjB,aAAa,GACd,gCAA4B"}
|
package/dist/index.d.mts
CHANGED
|
@@ -2,8 +2,6 @@ export { AssetsController, getDefaultAssetsControllerState, } from "./AssetsCont
|
|
|
2
2
|
export { AssetsDataSourceError } from "./errors.mjs";
|
|
3
3
|
export { DEFAULT_TRACKED_ASSETS_BY_CHAIN, CHAINS_WITH_DEFAULT_TRACKED_ASSETS, DEFAULT_ASSET_METADATA, buildDefaultAssetsInfo, getDefaultTrackedAssetsForChain, getDefaultAssetMetadata, } from "./defaults.mjs";
|
|
4
4
|
export type { PendingTokenMetadata } from "./AssetsController.mjs";
|
|
5
|
-
export { SNAPS_ASSETS_MIGRATION_FLAG_KEYS, SNAPS_ASSETS_MIGRATION_NAMESPACES, SnapsAssetsMigrationStage, getSnapsAssetsMigrationNamespace, isMigrationStageActive, isSnapsAssetsMigrationNamespace, parseSnapsAssetsMigrationStage, } from "./utils/snaps-assets-migration.mjs";
|
|
6
|
-
export type { SnapsAssetsMigrationNamespace } from "./utils/snaps-assets-migration.mjs";
|
|
7
5
|
export type { AssetsControllerState, AssetsControllerMessenger, AssetsControllerOptions, AssetsControllerGetStateAction, AssetsControllerActions, AssetsControllerStateChangeEvent, AssetsControllerBalanceChangedEvent, AssetsControllerPriceChangedEvent, AssetsControllerAssetsDetectedEvent, AssetsControllerEvents, } from "./AssetsController.mjs";
|
|
8
6
|
export type { AssetsControllerGetAssetsAction, AssetsControllerGetAssetsBalanceAction, AssetsControllerGetAssetMetadataAction, AssetsControllerGetAssetAction, AssetsControllerGetAssetsPriceAction, AssetsControllerAddCustomAssetAction, AssetsControllerRemoveCustomAssetAction, AssetsControllerGetCustomAssetsAction, AssetsControllerHideAssetAction, AssetsControllerUnhideAssetAction, AssetsControllerGetExchangeRatesForBridgeAction, AssetsControllerGetStateForTransactionPayAction, AssetsControllerSetSelectedCurrencyAction, } from "./AssetsController-method-action-types.mjs";
|
|
9
7
|
export type { Caip19AssetId, AccountId, ChainId, AssetType, TokenStandard, TokenFees, HoneypotStatus, StorageSlots, LocalizedDescription, BaseAssetMetadata, FungibleAssetMetadata, ERC721AssetMetadata, ERC1155AssetMetadata, AssetMetadata, BaseAssetPrice, FungibleAssetPrice, NFTAssetPrice, AssetPrice, FungibleAssetBalance, ERC721AssetBalance, ERC1155AssetBalance, AssetBalance, AccountWithSupportedChains, DataType, DataRequest, DataResponse, AssetsUpdateMode, Context, NextFunction, Middleware, AssetsDataSource, FetchContext, FetchNextFunction, FetchMiddleware, SubscriptionResponse, Asset, BalanceChangeEvent, PriceChangeEvent, MetadataChangeEvent, AssetsDetectedEvent, } from "./types.mjs";
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,gBAAgB,EAChB,+BAA+B,GAChC,+BAA2B;AAC5B,OAAO,EAAE,qBAAqB,EAAE,qBAAiB;AACjD,OAAO,EACL,+BAA+B,EAC/B,kCAAkC,EAClC,sBAAsB,EACtB,sBAAsB,EACtB,+BAA+B,EAC/B,uBAAuB,GACxB,uBAAmB;AACpB,YAAY,EAAE,oBAAoB,EAAE,+BAA2B;AAG/D,
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,gBAAgB,EAChB,+BAA+B,GAChC,+BAA2B;AAC5B,OAAO,EAAE,qBAAqB,EAAE,qBAAiB;AACjD,OAAO,EACL,+BAA+B,EAC/B,kCAAkC,EAClC,sBAAsB,EACtB,sBAAsB,EACtB,+BAA+B,EAC/B,uBAAuB,GACxB,uBAAmB;AACpB,YAAY,EAAE,oBAAoB,EAAE,+BAA2B;AAG/D,YAAY,EACV,qBAAqB,EACrB,yBAAyB,EACzB,uBAAuB,EACvB,8BAA8B,EAC9B,uBAAuB,EACvB,gCAAgC,EAChC,mCAAmC,EACnC,iCAAiC,EACjC,mCAAmC,EACnC,sBAAsB,GACvB,+BAA2B;AAC5B,YAAY,EACV,+BAA+B,EAC/B,sCAAsC,EACtC,sCAAsC,EACtC,8BAA8B,EAC9B,oCAAoC,EACpC,oCAAoC,EACpC,uCAAuC,EACvC,qCAAqC,EACrC,+BAA+B,EAC/B,iCAAiC,EACjC,+CAA+C,EAC/C,+CAA+C,EAC/C,yCAAyC,GAC1C,mDAA+C;AAGhD,YAAY,EAEV,aAAa,EACb,SAAS,EACT,OAAO,EAEP,SAAS,EACT,aAAa,EAEb,SAAS,EACT,cAAc,EACd,YAAY,EACZ,oBAAoB,EAEpB,iBAAiB,EACjB,qBAAqB,EACrB,mBAAmB,EACnB,oBAAoB,EACpB,aAAa,EAEb,cAAc,EACd,kBAAkB,EAClB,aAAa,EACb,UAAU,EAEV,oBAAoB,EACpB,kBAAkB,EAClB,mBAAmB,EACnB,YAAY,EAEZ,0BAA0B,EAC1B,QAAQ,EACR,WAAW,EACX,YAAY,EACZ,gBAAgB,EAEhB,OAAO,EACP,YAAY,EACZ,UAAU,EACV,gBAAgB,EAChB,YAAY,EACZ,iBAAiB,EACjB,eAAe,EACf,oBAAoB,EAEpB,KAAK,EAEL,kBAAkB,EAClB,gBAAgB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2B,EAC3B,iBAAiB,EACjB,mBAAmB,EACnB,mBAAmB,EACnB,iBAAiB,EACjB,aAAa,GACd,gCAA4B"}
|
package/dist/index.mjs
CHANGED
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
export { AssetsController, getDefaultAssetsControllerState } from "./AssetsController.mjs";
|
|
3
3
|
export { AssetsDataSourceError } from "./errors.mjs";
|
|
4
4
|
export { DEFAULT_TRACKED_ASSETS_BY_CHAIN, CHAINS_WITH_DEFAULT_TRACKED_ASSETS, DEFAULT_ASSET_METADATA, buildDefaultAssetsInfo, getDefaultTrackedAssetsForChain, getDefaultAssetMetadata } from "./defaults.mjs";
|
|
5
|
-
// Snaps → AssetsController assets migration
|
|
6
|
-
export { SNAPS_ASSETS_MIGRATION_FLAG_KEYS, SNAPS_ASSETS_MIGRATION_NAMESPACES, SnapsAssetsMigrationStage, getSnapsAssetsMigrationNamespace, isMigrationStageActive, isSnapsAssetsMigrationNamespace, parseSnapsAssetsMigrationStage } from "./utils/snaps-assets-migration.mjs";
|
|
7
5
|
// Data sources - base class and types
|
|
8
6
|
export { AbstractDataSource } from "./data-sources/index.mjs";
|
|
9
7
|
// Data sources - AccountsApi
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,yBAAyB;AACzB,OAAO,EACL,gBAAgB,EAChB,+BAA+B,EAChC,+BAA2B;AAC5B,OAAO,EAAE,qBAAqB,EAAE,qBAAiB;AACjD,OAAO,EACL,+BAA+B,EAC/B,kCAAkC,EAClC,sBAAsB,EACtB,sBAAsB,EACtB,+BAA+B,EAC/B,uBAAuB,EACxB,uBAAmB;
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,yBAAyB;AACzB,OAAO,EACL,gBAAgB,EAChB,+BAA+B,EAChC,+BAA2B;AAC5B,OAAO,EAAE,qBAAqB,EAAE,qBAAiB;AACjD,OAAO,EACL,+BAA+B,EAC/B,kCAAkC,EAClC,sBAAsB,EACtB,sBAAsB,EACtB,+BAA+B,EAC/B,uBAAuB,EACxB,uBAAmB;AAsFpB,sCAAsC;AACtC,OAAO,EAAE,kBAAkB,EAAE,iCAAuB;AAIpD,6BAA6B;AAC7B,OAAO,EAAE,qBAAqB,EAAE,iCAAuB;AAQvD,kCAAkC;AAClC,OAAO,EACL,0BAA0B,EAC1B,gCAAgC,EACjC,iCAAuB;AAOxB,qBAAqB;AACrB,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,iCAAuB;AASpE,gFAAgF;AAChF,OAAO,EACL,cAAc,EACd,oBAAoB,EACpB,qBAAqB;AACrB,YAAY;AACZ,kBAAkB;AAClB,oBAAoB;AACpB,iBAAiB,EACjB,uBAAuB,EACxB,iCAAuB;AAOxB,0BAA0B;AAC1B,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,iCAAuB;AAQlE,cAAc;AACd,OAAO,EACL,+BAA+B,EAC/B,mBAAmB,EACnB,qBAAqB,EACtB,gCAAsB;AAMvB,YAAY;AACZ,OAAO,EACL,gBAAgB,EAChB,4BAA4B,EAC5B,4BAA4B,EAC7B,0BAAgB;AAQjB,YAAY;AACZ,OAAO,EACL,6BAA6B,EAC7B,qCAAqC,EACrC,8BAA8B,EAC9B,oBAAoB,EACpB,2BAA2B,EAC5B,gCAA4B","sourcesContent":["// Main controller export\nexport {\n AssetsController,\n getDefaultAssetsControllerState,\n} from './AssetsController';\nexport { AssetsDataSourceError } from './errors';\nexport {\n DEFAULT_TRACKED_ASSETS_BY_CHAIN,\n CHAINS_WITH_DEFAULT_TRACKED_ASSETS,\n DEFAULT_ASSET_METADATA,\n buildDefaultAssetsInfo,\n getDefaultTrackedAssetsForChain,\n getDefaultAssetMetadata,\n} from './defaults';\nexport type { PendingTokenMetadata } from './AssetsController';\n\n// State and messenger types\nexport type {\n AssetsControllerState,\n AssetsControllerMessenger,\n AssetsControllerOptions,\n AssetsControllerGetStateAction,\n AssetsControllerActions,\n AssetsControllerStateChangeEvent,\n AssetsControllerBalanceChangedEvent,\n AssetsControllerPriceChangedEvent,\n AssetsControllerAssetsDetectedEvent,\n AssetsControllerEvents,\n} from './AssetsController';\nexport type {\n AssetsControllerGetAssetsAction,\n AssetsControllerGetAssetsBalanceAction,\n AssetsControllerGetAssetMetadataAction,\n AssetsControllerGetAssetAction,\n AssetsControllerGetAssetsPriceAction,\n AssetsControllerAddCustomAssetAction,\n AssetsControllerRemoveCustomAssetAction,\n AssetsControllerGetCustomAssetsAction,\n AssetsControllerHideAssetAction,\n AssetsControllerUnhideAssetAction,\n AssetsControllerGetExchangeRatesForBridgeAction,\n AssetsControllerGetStateForTransactionPayAction,\n AssetsControllerSetSelectedCurrencyAction,\n} from './AssetsController-method-action-types';\n\n// Core types\nexport type {\n // CAIP types\n Caip19AssetId,\n AccountId,\n ChainId,\n // Asset types\n AssetType,\n TokenStandard,\n // Contract data types\n TokenFees,\n HoneypotStatus,\n StorageSlots,\n LocalizedDescription,\n // Metadata types\n BaseAssetMetadata,\n FungibleAssetMetadata,\n ERC721AssetMetadata,\n ERC1155AssetMetadata,\n AssetMetadata,\n // Price types\n BaseAssetPrice,\n FungibleAssetPrice,\n NFTAssetPrice,\n AssetPrice,\n // Balance types\n FungibleAssetBalance,\n ERC721AssetBalance,\n ERC1155AssetBalance,\n AssetBalance,\n // Data source types\n AccountWithSupportedChains,\n DataType,\n DataRequest,\n DataResponse,\n AssetsUpdateMode,\n // Middleware types\n Context,\n NextFunction,\n Middleware,\n AssetsDataSource,\n FetchContext,\n FetchNextFunction,\n FetchMiddleware,\n SubscriptionResponse,\n // Combined asset type\n Asset,\n // Event types\n BalanceChangeEvent,\n PriceChangeEvent,\n MetadataChangeEvent,\n AssetsDetectedEvent,\n} from './types';\n\n// Data sources - base class and types\nexport { AbstractDataSource } from './data-sources';\n\nexport type { DataSourceState, SubscriptionRequest } from './data-sources';\n\n// Data sources - AccountsApi\nexport { AccountsApiDataSource } from './data-sources';\n\nexport type {\n AccountsApiDataSourceConfig,\n AccountsApiDataSourceOptions,\n AccountsApiDataSourceState,\n} from './data-sources';\n\n// Data sources - BackendWebsocket\nexport {\n BackendWebsocketDataSource,\n createBackendWebsocketDataSource,\n} from './data-sources';\n\nexport type {\n BackendWebsocketDataSourceOptions,\n BackendWebsocketDataSourceState,\n} from './data-sources';\n\n// Data sources - RPC\nexport { RpcDataSource, createRpcDataSource } from './data-sources';\n\nexport type {\n RpcDataSourceConfig,\n RpcDataSourceOptions,\n RpcDataSourceState,\n ChainStatus,\n} from './data-sources';\n\n// Data sources - Unified Snap Data Source (dynamically discovers keyring snaps)\nexport {\n SnapDataSource,\n createSnapDataSource,\n SNAP_DATA_SOURCE_NAME,\n // Constants\n KEYRING_PERMISSION,\n // Utility functions\n getChainIdsCaveat,\n extractChainFromAssetId,\n} from './data-sources';\n\nexport type {\n SnapDataSourceState,\n SnapDataSourceOptions,\n} from './data-sources';\n\n// Enrichment data sources\nexport { TokenDataSource, PriceDataSource } from './data-sources';\n\nexport type {\n TokenDataSourceOptions,\n PriceDataSourceConfig,\n PriceDataSourceOptions,\n} from './data-sources';\n\n// Middlewares\nexport {\n CustomAssetGraduationMiddleware,\n DetectionMiddleware,\n RpcFallbackMiddleware,\n} from './middlewares';\nexport type {\n CustomAssetGraduationMiddlewareOptions,\n RpcFallbackMiddlewareOptions,\n} from './middlewares';\n\n// Utilities\nexport {\n normalizeAssetId,\n formatExchangeRatesForBridge,\n formatStateForTransactionPay,\n} from './utils';\nexport type {\n AccountForLegacyFormat,\n BridgeExchangeRatesFormat,\n LegacyToken,\n TransactionPayLegacyFormat,\n} from './utils';\n\n// Selectors\nexport {\n calculateBalanceForAllWallets,\n calculateBalanceChangeForAccountGroup,\n getAggregatedBalanceForAccount,\n getGroupIdForAccount,\n getInternalAccountsForGroup,\n} from './selectors/balance';\n\nexport type {\n AccountGroupBalance,\n AccountsById,\n AggregatedBalanceEntry,\n AggregatedBalanceForAccount,\n AllWalletsBalance,\n BalanceChangePeriod,\n BalanceChangeResult,\n EnabledNetworkMap,\n WalletBalance,\n} from './selectors/balance';\n"]}
|
package/package.json
CHANGED
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.shouldSupportChain = exports.getMigrationStages = exports.isMigrationStageActive = exports.parseSnapsAssetsMigrationStage = exports.isSnapsAssetsMigrationNamespace = exports.getSnapsAssetsMigrationNamespace = exports.SNAPS_ASSETS_MIGRATION_FLAG_KEYS = exports.SNAPS_ASSETS_MIGRATION_NAMESPACES = exports.SnapsAssetsMigrationStage = void 0;
|
|
4
|
-
const utils_1 = require("@metamask/utils");
|
|
5
|
-
/**
|
|
6
|
-
* Per-network rollout stage for the Snaps → AssetsController assets migration.
|
|
7
|
-
*
|
|
8
|
-
* The stage is resolved per CAIP-2 chain id, so each migration network (Solana,
|
|
9
|
-
* Stellar, Tron) advances and rolls back independently. A network with no flag
|
|
10
|
-
* (or an unknown/malformed value) resolves to {@link Off}.
|
|
11
|
-
*/
|
|
12
|
-
var SnapsAssetsMigrationStage;
|
|
13
|
-
(function (SnapsAssetsMigrationStage) {
|
|
14
|
-
/**
|
|
15
|
-
* Status quo — the Snap uses its own AssetsService and the AssetsController
|
|
16
|
-
* does NOT ingest for the network.
|
|
17
|
-
*/
|
|
18
|
-
SnapsAssetsMigrationStage[SnapsAssetsMigrationStage["Off"] = 0] = "Off";
|
|
19
|
-
/**
|
|
20
|
-
* The AssetsController ingests for the network (Account Activity WebSocket +
|
|
21
|
-
* AccountsAPI) and reads route through it, falling back to the Snap's
|
|
22
|
-
* AssetsService when the controller has no value.
|
|
23
|
-
*/
|
|
24
|
-
SnapsAssetsMigrationStage[SnapsAssetsMigrationStage["ReadAssetsControllerWithFallback"] = 1] = "ReadAssetsControllerWithFallback";
|
|
25
|
-
/**
|
|
26
|
-
* Reads come from the AssetsController only (no fallback), but the Snap still
|
|
27
|
-
* tracks/persists in the background so rollback stays safe.
|
|
28
|
-
*/
|
|
29
|
-
SnapsAssetsMigrationStage[SnapsAssetsMigrationStage["ReadAssetsControllerWithoutFallback"] = 2] = "ReadAssetsControllerWithoutFallback";
|
|
30
|
-
/**
|
|
31
|
-
* The Snap stops tracking/persisting; the AssetsController is the only source.
|
|
32
|
-
*/
|
|
33
|
-
SnapsAssetsMigrationStage[SnapsAssetsMigrationStage["ReadAssetsControllerOnly"] = 3] = "ReadAssetsControllerOnly";
|
|
34
|
-
})(SnapsAssetsMigrationStage || (exports.SnapsAssetsMigrationStage = SnapsAssetsMigrationStage = {}));
|
|
35
|
-
/**
|
|
36
|
-
* CAIP-2 namespaces covered by the Snaps → AssetsController assets migration.
|
|
37
|
-
* Only chains in these namespaces are stage-gated; every other namespace
|
|
38
|
-
* (e.g. `eip155`) keeps its existing, ungated ingestion behavior.
|
|
39
|
-
*/
|
|
40
|
-
exports.SNAPS_ASSETS_MIGRATION_NAMESPACES = [
|
|
41
|
-
'solana',
|
|
42
|
-
'stellar',
|
|
43
|
-
'tron',
|
|
44
|
-
];
|
|
45
|
-
/**
|
|
46
|
-
* Per-network remote feature flag keys (LaunchDarkly) that drive the migration.
|
|
47
|
-
* Each flag's resolved value carries the {@link SnapsAssetsMigrationStage} for
|
|
48
|
-
* that network — see {@link parseSnapsAssetsMigrationStage}.
|
|
49
|
-
*/
|
|
50
|
-
exports.SNAPS_ASSETS_MIGRATION_FLAG_KEYS = {
|
|
51
|
-
solana: 'networkAssetsSnapsMigrationSolana',
|
|
52
|
-
stellar: 'networkAssetsSnapsMigrationStellar',
|
|
53
|
-
tron: 'networkAssetsSnapsMigrationTron',
|
|
54
|
-
};
|
|
55
|
-
/**
|
|
56
|
-
* Resolve the CAIP-2 namespace of a chain when it belongs to a migration
|
|
57
|
-
* network (Solana, Stellar, Tron).
|
|
58
|
-
*
|
|
59
|
-
* @param chainId - The CAIP-2 chain id.
|
|
60
|
-
* @returns The migration namespace, or `undefined` for any other chain.
|
|
61
|
-
*/
|
|
62
|
-
function getSnapsAssetsMigrationNamespace(chainId) {
|
|
63
|
-
try {
|
|
64
|
-
const { namespace } = (0, utils_1.parseCaipChainId)(chainId);
|
|
65
|
-
return exports.SNAPS_ASSETS_MIGRATION_NAMESPACES.includes(namespace)
|
|
66
|
-
? namespace
|
|
67
|
-
: undefined;
|
|
68
|
-
}
|
|
69
|
-
catch {
|
|
70
|
-
return undefined;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
exports.getSnapsAssetsMigrationNamespace = getSnapsAssetsMigrationNamespace;
|
|
74
|
-
/**
|
|
75
|
-
* Whether a CAIP-2 chain id belongs to a network covered by the assets
|
|
76
|
-
* migration (Solana, Stellar, Tron).
|
|
77
|
-
*
|
|
78
|
-
* @param chainId - The CAIP-2 chain id to check.
|
|
79
|
-
* @returns True when the chain's namespace is a migration namespace.
|
|
80
|
-
*/
|
|
81
|
-
function isSnapsAssetsMigrationNamespace(chainId) {
|
|
82
|
-
return getSnapsAssetsMigrationNamespace(chainId) !== undefined;
|
|
83
|
-
}
|
|
84
|
-
exports.isSnapsAssetsMigrationNamespace = isSnapsAssetsMigrationNamespace;
|
|
85
|
-
/**
|
|
86
|
-
* Coerce a resolved remote feature flag value into a {@link SnapsAssetsMigrationStage}.
|
|
87
|
-
*
|
|
88
|
-
* `RemoteFeatureFlagController` resolves a threshold-scoped flag to a
|
|
89
|
-
* `{ name, value }` variant, so the migration payload
|
|
90
|
-
* `{ featureVersion, minimumSnapVersion, stage }` (and thus `stage`) lives under
|
|
91
|
-
* `value` — the same nesting the sibling `assetsAccountsApiV6` flag uses. The
|
|
92
|
-
* top-level object is used as a fallback so a plain, unscoped `{ stage }`
|
|
93
|
-
* variation still resolves. Anything missing, malformed, or carrying an unknown
|
|
94
|
-
* `stage` resolves to {@link SnapsAssetsMigrationStage.Off}.
|
|
95
|
-
*
|
|
96
|
-
* @param flagValue - The resolved remote feature flag value for a network.
|
|
97
|
-
* @returns The migration stage.
|
|
98
|
-
*/
|
|
99
|
-
function parseSnapsAssetsMigrationStage(flagValue) {
|
|
100
|
-
if (typeof flagValue !== 'object' ||
|
|
101
|
-
flagValue === null ||
|
|
102
|
-
Array.isArray(flagValue)) {
|
|
103
|
-
return SnapsAssetsMigrationStage.Off;
|
|
104
|
-
}
|
|
105
|
-
const { value } = flagValue;
|
|
106
|
-
const payload = typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
107
|
-
? value
|
|
108
|
-
: flagValue;
|
|
109
|
-
const { stage } = payload;
|
|
110
|
-
switch (stage) {
|
|
111
|
-
case SnapsAssetsMigrationStage.ReadAssetsControllerWithFallback:
|
|
112
|
-
case SnapsAssetsMigrationStage.ReadAssetsControllerWithoutFallback:
|
|
113
|
-
case SnapsAssetsMigrationStage.ReadAssetsControllerOnly:
|
|
114
|
-
return stage;
|
|
115
|
-
default:
|
|
116
|
-
return SnapsAssetsMigrationStage.Off;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
exports.parseSnapsAssetsMigrationStage = parseSnapsAssetsMigrationStage;
|
|
120
|
-
/**
|
|
121
|
-
* Whether a network's migration stage is active, i.e. the AssetsController
|
|
122
|
-
* (rather than the Snap) is the source of assets for the network.
|
|
123
|
-
*
|
|
124
|
-
* A stage is active from {@link SnapsAssetsMigrationStage.ReadAssetsControllerWithFallback}
|
|
125
|
-
* onward and inactive at {@link SnapsAssetsMigrationStage.Off}.
|
|
126
|
-
*
|
|
127
|
-
* @param stage - The resolved per-network migration stage.
|
|
128
|
-
* @returns True when the migration is active for the network.
|
|
129
|
-
*/
|
|
130
|
-
function isMigrationStageActive(stage) {
|
|
131
|
-
return stage >= SnapsAssetsMigrationStage.ReadAssetsControllerWithFallback;
|
|
132
|
-
}
|
|
133
|
-
exports.isMigrationStageActive = isMigrationStageActive;
|
|
134
|
-
/**
|
|
135
|
-
* Resolve the Snaps → AssetsController migration stage for each migration
|
|
136
|
-
* network (Solana, Stellar, Tron) from the remote feature flags. The order
|
|
137
|
-
* matches {@link SNAPS_ASSETS_MIGRATION_NAMESPACES}, so the result can be joined
|
|
138
|
-
* into a stable primitive signature for change detection.
|
|
139
|
-
*
|
|
140
|
-
* @param remoteFeatureFlags - The remote feature flags state to resolve stages from.
|
|
141
|
-
* @returns An array of each migration namespace's resolved stage.
|
|
142
|
-
*/
|
|
143
|
-
function getMigrationStages(remoteFeatureFlags) {
|
|
144
|
-
return exports.SNAPS_ASSETS_MIGRATION_NAMESPACES.map((namespace) => parseSnapsAssetsMigrationStage(remoteFeatureFlags[exports.SNAPS_ASSETS_MIGRATION_FLAG_KEYS[namespace]]));
|
|
145
|
-
}
|
|
146
|
-
exports.getMigrationStages = getMigrationStages;
|
|
147
|
-
/**
|
|
148
|
-
* Whether a supported network should be surfaced as an active chain, gated by
|
|
149
|
-
* the Snaps → AssetsController migration feature flags.
|
|
150
|
-
*
|
|
151
|
-
* Non-migration namespaces (e.g. `eip155`) are always surfaced. Migration
|
|
152
|
-
* networks (Solana, Stellar, Tron) are only surfaced once their per-network
|
|
153
|
-
* stage reaches {@link SnapsAssetsMigrationStage.ReadAssetsControllerWithFallback};
|
|
154
|
-
* they are excluded when the stage is `Off` (also the fail-safe when the flag is
|
|
155
|
-
* missing or the flags are unavailable).
|
|
156
|
-
*
|
|
157
|
-
* @param chainId - The CAIP-2 chain id to check.
|
|
158
|
-
* @param remoteFeatureFlags - The remote feature flags state, or `undefined` when unavailable.
|
|
159
|
-
* @returns `true` when the chain should be surfaced as an active chain.
|
|
160
|
-
*/
|
|
161
|
-
function shouldSupportChain(chainId, remoteFeatureFlags) {
|
|
162
|
-
const namespace = getSnapsAssetsMigrationNamespace(chainId);
|
|
163
|
-
// Non-migration namespaces (e.g. `eip155`) are never gated.
|
|
164
|
-
if (!namespace) {
|
|
165
|
-
return true;
|
|
166
|
-
}
|
|
167
|
-
const stage = parseSnapsAssetsMigrationStage(remoteFeatureFlags?.[exports.SNAPS_ASSETS_MIGRATION_FLAG_KEYS[namespace]]);
|
|
168
|
-
return isMigrationStageActive(stage);
|
|
169
|
-
}
|
|
170
|
-
exports.shouldSupportChain = shouldSupportChain;
|
|
171
|
-
//# sourceMappingURL=snaps-assets-migration.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"snaps-assets-migration.cjs","sourceRoot":"","sources":["../../src/utils/snaps-assets-migration.ts"],"names":[],"mappings":";;;AAEA,2CAAmD;AAInD;;;;;;GAMG;AACH,IAAY,yBAqBX;AArBD,WAAY,yBAAyB;IACnC;;;OAGG;IACH,uEAAO,CAAA;IACP;;;;OAIG;IACH,iIAAoC,CAAA;IACpC;;;OAGG;IACH,uIAAuC,CAAA;IACvC;;OAEG;IACH,iHAA4B,CAAA;AAC9B,CAAC,EArBW,yBAAyB,yCAAzB,yBAAyB,QAqBpC;AAED;;;;GAIG;AACU,QAAA,iCAAiC,GAAG;IAC/C,QAAQ;IACR,SAAS;IACT,MAAM;CACE,CAAC;AAKX;;;;GAIG;AACU,QAAA,gCAAgC,GAGzC;IACF,MAAM,EAAE,mCAAmC;IAC3C,OAAO,EAAE,oCAAoC;IAC7C,IAAI,EAAE,iCAAiC;CACxC,CAAC;AAEF;;;;;;GAMG;AACH,SAAgB,gCAAgC,CAC9C,OAAgB;IAEhB,IAAI,CAAC;QACH,MAAM,EAAE,SAAS,EAAE,GAAG,IAAA,wBAAgB,EAAC,OAAO,CAAC,CAAC;QAChD,OAAQ,yCAAuD,CAAC,QAAQ,CACtE,SAAS,CACV;YACC,CAAC,CAAE,SAA2C;YAC9C,CAAC,CAAC,SAAS,CAAC;IAChB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC;AAbD,4EAaC;AAED;;;;;;GAMG;AACH,SAAgB,+BAA+B,CAAC,OAAgB;IAC9D,OAAO,gCAAgC,CAAC,OAAO,CAAC,KAAK,SAAS,CAAC;AACjE,CAAC;AAFD,0EAEC;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AC,CAAC;IAC5D,4DAA4D;IAC5D,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,KAAK,GAAG,8BAA8B,CAC1C,kBAAkB,EAAE,CAAC,wCAAgC,CAAC,SAAS,CAAC,CAAC,CAClE,CAAC;IACF,OAAO,sBAAsB,CAAC,KAAK,CAAC,CAAC;AACvC,CAAC;AAdD,gDAcC","sourcesContent":["import type { FeatureFlags } from '@metamask/remote-feature-flag-controller';\nimport type { Json } from '@metamask/utils';\nimport { parseCaipChainId } from '@metamask/utils';\n\nimport type { ChainId } from '../types';\n\n/**\n * Per-network rollout stage for the Snaps → AssetsController assets migration.\n *\n * The stage is resolved per CAIP-2 chain id, so each migration network (Solana,\n * Stellar, Tron) advances and rolls back independently. A network with no flag\n * (or an unknown/malformed value) resolves to {@link Off}.\n */\nexport enum SnapsAssetsMigrationStage {\n /**\n * Status quo — the Snap uses its own AssetsService and the AssetsController\n * does NOT ingest for the network.\n */\n Off = 0,\n /**\n * The AssetsController ingests for the network (Account Activity WebSocket +\n * AccountsAPI) and reads route through it, falling back to the Snap's\n * AssetsService when the controller has no value.\n */\n ReadAssetsControllerWithFallback = 1,\n /**\n * Reads come from the AssetsController only (no fallback), but the Snap still\n * tracks/persists in the background so rollback stays safe.\n */\n ReadAssetsControllerWithoutFallback = 2,\n /**\n * The Snap stops tracking/persisting; the AssetsController is the only source.\n */\n ReadAssetsControllerOnly = 3,\n}\n\n/**\n * CAIP-2 namespaces covered by the Snaps → AssetsController assets migration.\n * Only chains in these namespaces are stage-gated; every other namespace\n * (e.g. `eip155`) keeps its existing, ungated ingestion behavior.\n */\nexport const SNAPS_ASSETS_MIGRATION_NAMESPACES = [\n 'solana',\n 'stellar',\n 'tron',\n] as const;\n\nexport type SnapsAssetsMigrationNamespace =\n (typeof SNAPS_ASSETS_MIGRATION_NAMESPACES)[number];\n\n/**\n * Per-network remote feature flag keys (LaunchDarkly) that drive the migration.\n * Each flag's resolved value carries the {@link SnapsAssetsMigrationStage} for\n * that network — see {@link parseSnapsAssetsMigrationStage}.\n */\nexport const SNAPS_ASSETS_MIGRATION_FLAG_KEYS: Record<\n SnapsAssetsMigrationNamespace,\n string\n> = {\n solana: 'networkAssetsSnapsMigrationSolana',\n stellar: 'networkAssetsSnapsMigrationStellar',\n tron: 'networkAssetsSnapsMigrationTron',\n};\n\n/**\n * Resolve the CAIP-2 namespace of a chain when it belongs to a migration\n * network (Solana, Stellar, Tron).\n *\n * @param chainId - The CAIP-2 chain id.\n * @returns The migration namespace, or `undefined` for any other chain.\n */\nexport function getSnapsAssetsMigrationNamespace(\n chainId: ChainId,\n): SnapsAssetsMigrationNamespace | undefined {\n try {\n const { namespace } = parseCaipChainId(chainId);\n return (SNAPS_ASSETS_MIGRATION_NAMESPACES as readonly string[]).includes(\n namespace,\n )\n ? (namespace as SnapsAssetsMigrationNamespace)\n : undefined;\n } catch {\n return undefined;\n }\n}\n\n/**\n * Whether a CAIP-2 chain id belongs to a network covered by the assets\n * migration (Solana, Stellar, Tron).\n *\n * @param chainId - The CAIP-2 chain id to check.\n * @returns True when the chain's namespace is a migration namespace.\n */\nexport function isSnapsAssetsMigrationNamespace(chainId: ChainId): boolean {\n return getSnapsAssetsMigrationNamespace(chainId) !== undefined;\n}\n\n/**\n * Coerce a resolved remote feature flag value into a {@link SnapsAssetsMigrationStage}.\n *\n * `RemoteFeatureFlagController` resolves a threshold-scoped flag to a\n * `{ name, value }` variant, so the migration payload\n * `{ featureVersion, minimumSnapVersion, stage }` (and thus `stage`) lives under\n * `value` — the same nesting the sibling `assetsAccountsApiV6` flag uses. The\n * top-level object is used as a fallback so a plain, unscoped `{ stage }`\n * variation still resolves. Anything missing, malformed, or carrying an unknown\n * `stage` resolves to {@link SnapsAssetsMigrationStage.Off}.\n *\n * @param flagValue - The resolved remote feature flag value for a network.\n * @returns The migration stage.\n */\nexport function parseSnapsAssetsMigrationStage(\n flagValue: Json | undefined,\n): SnapsAssetsMigrationStage {\n if (\n typeof flagValue !== 'object' ||\n flagValue === null ||\n Array.isArray(flagValue)\n ) {\n return SnapsAssetsMigrationStage.Off;\n }\n\n const { value } = flagValue as { value?: unknown };\n const payload =\n typeof value === 'object' && value !== null && !Array.isArray(value)\n ? value\n : flagValue;\n\n const { stage } = payload as { stage?: unknown };\n switch (stage) {\n case SnapsAssetsMigrationStage.ReadAssetsControllerWithFallback:\n case SnapsAssetsMigrationStage.ReadAssetsControllerWithoutFallback:\n case SnapsAssetsMigrationStage.ReadAssetsControllerOnly:\n return stage;\n default:\n return SnapsAssetsMigrationStage.Off;\n }\n}\n\n/**\n * Whether a network's migration stage is active, i.e. the AssetsController\n * (rather than the Snap) is the source of assets for the network.\n *\n * A stage is active from {@link SnapsAssetsMigrationStage.ReadAssetsControllerWithFallback}\n * onward and inactive at {@link SnapsAssetsMigrationStage.Off}.\n *\n * @param stage - The resolved per-network migration stage.\n * @returns True when the migration is active for the network.\n */\nexport function isMigrationStageActive(\n stage: SnapsAssetsMigrationStage,\n): boolean {\n return stage >= SnapsAssetsMigrationStage.ReadAssetsControllerWithFallback;\n}\n\n/**\n * Resolve the Snaps → AssetsController migration stage for each migration\n * network (Solana, Stellar, Tron) from the remote feature flags. The order\n * matches {@link SNAPS_ASSETS_MIGRATION_NAMESPACES}, so the result can be joined\n * into a stable primitive signature for change detection.\n *\n * @param remoteFeatureFlags - The remote feature flags state to resolve stages from.\n * @returns An array of each migration namespace's resolved stage.\n */\nexport function getMigrationStages(\n remoteFeatureFlags: FeatureFlags,\n): SnapsAssetsMigrationStage[] {\n return SNAPS_ASSETS_MIGRATION_NAMESPACES.map((namespace) =>\n parseSnapsAssetsMigrationStage(\n remoteFeatureFlags[SNAPS_ASSETS_MIGRATION_FLAG_KEYS[namespace]],\n ),\n );\n}\n\n/**\n * Whether a supported network should be surfaced as an active chain, gated by\n * the Snaps → AssetsController migration feature flags.\n *\n * Non-migration namespaces (e.g. `eip155`) are always surfaced. Migration\n * networks (Solana, Stellar, Tron) are only surfaced once their per-network\n * stage reaches {@link SnapsAssetsMigrationStage.ReadAssetsControllerWithFallback};\n * they are excluded when the stage is `Off` (also the fail-safe when the flag is\n * missing or the flags are unavailable).\n *\n * @param chainId - The CAIP-2 chain id to check.\n * @param remoteFeatureFlags - The remote feature flags state, or `undefined` when unavailable.\n * @returns `true` when the chain should be surfaced as an active chain.\n */\nexport function shouldSupportChain(\n chainId: ChainId,\n remoteFeatureFlags: FeatureFlags | undefined,\n): boolean {\n const namespace = getSnapsAssetsMigrationNamespace(chainId);\n // Non-migration namespaces (e.g. `eip155`) are never gated.\n if (!namespace) {\n return true;\n }\n\n const stage = parseSnapsAssetsMigrationStage(\n remoteFeatureFlags?.[SNAPS_ASSETS_MIGRATION_FLAG_KEYS[namespace]],\n );\n return isMigrationStageActive(stage);\n}\n"]}
|