@metamask-previews/assets-controller 20.4.1-preview-730f5d72e → 20.4.1-preview-e9ac9ffe1
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 +8 -1
- package/dist/AssetsController.d.ts +3 -2
- package/dist/AssetsController.d.ts.map +1 -1
- package/dist/AssetsController.js +28 -394
- package/dist/AssetsController.js.map +1 -1
- package/dist/data-sources/AccountActivityDataSource.js +2 -2
- package/dist/data-sources/AccountActivityDataSource.js.map +1 -1
- package/dist/data-sources/AccountsApiDataSource.d.ts +3 -26
- package/dist/data-sources/AccountsApiDataSource.d.ts.map +1 -1
- package/dist/data-sources/AccountsApiDataSource.js +2 -203
- package/dist/data-sources/AccountsApiDataSource.js.map +1 -1
- package/dist/data-sources/RpcDataSource.d.ts +0 -6
- package/dist/data-sources/RpcDataSource.d.ts.map +1 -1
- package/dist/data-sources/RpcDataSource.js +4 -179
- package/dist/data-sources/RpcDataSource.js.map +1 -1
- package/dist/data-sources/SnapDataSource.d.ts +0 -2
- package/dist/data-sources/SnapDataSource.d.ts.map +1 -1
- package/dist/data-sources/SnapDataSource.js +1 -67
- package/dist/data-sources/SnapDataSource.js.map +1 -1
- package/dist/data-sources/evm-rpc-services/clients/MulticallClient.d.ts.map +1 -1
- package/dist/data-sources/evm-rpc-services/clients/MulticallClient.js +0 -1
- package/dist/data-sources/evm-rpc-services/clients/MulticallClient.js.map +1 -1
- package/dist/data-sources/evm-rpc-services/services/BalanceFetcher.d.ts +0 -12
- package/dist/data-sources/evm-rpc-services/services/BalanceFetcher.d.ts.map +1 -1
- package/dist/data-sources/evm-rpc-services/services/BalanceFetcher.js +9 -70
- package/dist/data-sources/evm-rpc-services/services/BalanceFetcher.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/middlewares/RpcFallbackMiddleware.d.ts +4 -18
- package/dist/middlewares/RpcFallbackMiddleware.d.ts.map +1 -1
- package/dist/middlewares/RpcFallbackMiddleware.js +5 -163
- package/dist/middlewares/RpcFallbackMiddleware.js.map +1 -1
- package/dist/middlewares/index.d.ts +0 -2
- package/dist/middlewares/index.d.ts.map +1 -1
- package/dist/middlewares/index.js +0 -1
- package/dist/middlewares/index.js.map +1 -1
- package/dist/pipeline/buildFastFetchSources.d.ts +6 -13
- package/dist/pipeline/buildFastFetchSources.d.ts.map +1 -1
- package/dist/pipeline/buildFastFetchSources.js +7 -15
- package/dist/pipeline/buildFastFetchSources.js.map +1 -1
- package/dist/pipeline/buildUpdateSources.d.ts +0 -3
- package/dist/pipeline/buildUpdateSources.d.ts.map +1 -1
- package/dist/pipeline/buildUpdateSources.js +1 -5
- package/dist/pipeline/buildUpdateSources.js.map +1 -1
- package/dist/pipeline/buildWsUpdateSources.d.ts +2 -5
- package/dist/pipeline/buildWsUpdateSources.d.ts.map +1 -1
- package/dist/pipeline/buildWsUpdateSources.js +9 -14
- package/dist/pipeline/buildWsUpdateSources.js.map +1 -1
- package/dist/types.d.ts +0 -8
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils/native-assets.d.ts.map +1 -1
- package/dist/utils/native-assets.js +0 -1
- package/dist/utils/native-assets.js.map +1 -1
- package/package.json +2 -2
- package/dist/middlewares/CustomAssetGraduationMiddleware.d.ts +0 -34
- package/dist/middlewares/CustomAssetGraduationMiddleware.d.ts.map +0 -1
- package/dist/middlewares/CustomAssetGraduationMiddleware.js +0 -117
- package/dist/middlewares/CustomAssetGraduationMiddleware.js.map +0 -1
- package/dist/utils/customAssetsRpcSupplement.d.ts +0 -60
- package/dist/utils/customAssetsRpcSupplement.d.ts.map +0 -1
- package/dist/utils/customAssetsRpcSupplement.js +0 -68
- package/dist/utils/customAssetsRpcSupplement.js.map +0 -1
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts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AAEF;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,EAAE,aAAa,EAAE,CAAC;IAC1B,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG;IAChC,OAAO,EAAE,aAAa,CAAC;IACvB,OAAO,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC;CACjC,CAAC"}
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AA4iBA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,UAAU,YAAY,CAC1B,SAAqB,EACrB,UAAsB;IAEtB,OAAO,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;QACzB,MAAM,cAAc,GAAG,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC;QAC7C,MAAM,SAAS,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,cAAc,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC;QAEtE,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;QACnB,CAAC;QAED,OAAO,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IAC/B,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import type { SupportedCurrency } from '@metamask/core-backend';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport type { CaipAssetType, CaipChainId, Json } from '@metamask/utils';\n\n/**\n * CAIP-19 compliant asset identifier\n * Format: \"{chainId}/{assetNamespace}:{assetReference}[/tokenId]\"\n *\n * Examples:\n * - Native: \"eip155:1/slip44:60\" (ETH)\n * - ERC20: \"eip155:1/erc20:0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\" (USDC)\n * - ERC721: \"eip155:1/erc721:0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D/1234\" (BAYC #1234)\n * - SPL: \"solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp/token:EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v\"\n */\nexport type Caip19AssetId = CaipAssetType;\n\n/**\n * InternalAccount UUID from AccountsController\n * Not the blockchain address!\n */\nexport type AccountId = string;\n\n/**\n * CAIP-2 chain identifier\n */\nexport type ChainId = CaipChainId;\n\n// ============================================================================\n// ASSET TYPES - Defined by metadata structure\n// ============================================================================\n\n/**\n * Asset types define the metadata structure, not blockchain implementation.\n * - \"fungible\" includes: native, erc20, spl - all share balance, symbol, decimals\n * - \"nft\" includes: erc721, erc1155 - include tokenId, image, attributes\n */\nexport type AssetType = 'fungible' | 'nft' | 'collectible';\n\n/**\n * Token standards - blockchain implementation details\n */\nexport type TokenStandard =\n | 'native'\n | 'erc20'\n | 'erc721'\n | 'erc1155'\n | 'spl'\n | string;\n\n// ============================================================================\n// METADATA TYPES (vary by asset type)\n// ============================================================================\n\n/**\n * UI preferences for an asset (stored in assetPreferences state, not in metadata).\n */\nexport type AssetPreferences = {\n /** Whether the asset is hidden from display */\n hidden?: boolean;\n};\n\n/**\n * Base metadata attributes shared by ALL asset types.\n */\nexport type BaseAssetMetadata = {\n /** Token standard - how it's implemented on the blockchain */\n type: TokenStandard;\n /** Display symbol (e.g., \"ETH\", \"USDC\") */\n symbol: string;\n /** Full name (e.g., \"Ethereum\", \"USD Coin\") */\n name: string;\n /** Token decimals (18 for ETH, 6 for USDC, etc.) */\n decimals: number;\n /** Logo URL or data URI */\n image?: string;\n};\n\n// ============================================================================\n// TOKEN CONTRACT DATA TYPES\n// ============================================================================\n\n/** Fee information for token transfers */\nexport type TokenFees = {\n avgFee: number;\n maxFee: number;\n minFee: number;\n};\n\n/** Honeypot detection status */\nexport type HoneypotStatus = {\n honeypotIs: boolean;\n goPlus?: boolean;\n};\n\n/** Storage slot information for the contract */\nexport type StorageSlots = {\n balance: number;\n approval: number;\n};\n\n/** Localized description */\nexport type LocalizedDescription = {\n en: string;\n};\n\n// ============================================================================\n// ASSET METADATA TYPES\n// ============================================================================\n\n/**\n * Metadata for fungible tokens.\n * Structure mirrors V3AssetResponse from the Tokens API.\n *\n * Differences from V3AssetResponse:\n * - `type` is derived from assetId namespace (not in API response)\n * - `image` maps from API's `iconUrl`\n * - `assetId` is not stored (used as the key)\n */\nexport type FungibleAssetMetadata = {\n /** Token type derived from assetId namespace */\n type: 'native' | 'erc20' | 'spl';\n /** CoinGecko ID for price lookups */\n coingeckoId?: string;\n /** Number of token list occurrences */\n occurrences?: number;\n /** DEX/aggregator integrations */\n aggregators?: string[];\n /** Asset labels/tags (e.g., \"stable_coin\") */\n labels?: string[];\n /** Whether the token supports ERC-20 permit */\n erc20Permit?: boolean;\n /** Fee information for token transfers */\n fees?: TokenFees;\n /** Honeypot detection status */\n honeypotStatus?: HoneypotStatus;\n /** Storage slot information for the contract */\n storage?: StorageSlots;\n /** Whether the contract is verified */\n isContractVerified?: boolean;\n /** Localized description */\n description?: LocalizedDescription;\n} & BaseAssetMetadata;\n\n/**\n * Metadata for ERC721 NFTs\n * Asset Type: \"nft\"\n */\nexport type ERC721AssetMetadata = {\n type: 'erc721';\n decimals: 0;\n /** Collection name */\n collectionName?: string;\n /** Collection size */\n collectionSize?: number;\n /** NFT traits/attributes - must be Json-serializable */\n traits?: Record<string, Json>;\n /** Rarity score */\n rarity?: number;\n /** Verification status */\n verified?: boolean;\n} & BaseAssetMetadata;\n\n/**\n * Metadata for ERC1155 multi-tokens\n */\nexport type ERC1155AssetMetadata = {\n type: 'erc1155';\n /** Token URI */\n tokenUri?: string;\n /** Token category */\n category?: string;\n /** Spam detection flag */\n isSpam?: boolean;\n} & BaseAssetMetadata;\n\n/**\n * Union type representing all possible asset metadata types.\n * All types must be JSON-serializable.\n */\nexport type AssetMetadata =\n | FungibleAssetMetadata\n | ERC721AssetMetadata\n | ERC1155AssetMetadata\n | (BaseAssetMetadata & { [key: string]: Json });\n\n// ============================================================================\n// PRICE TYPES (vary by asset type)\n// ============================================================================\n\n/**\n * Base price attributes.\n */\nexport type BaseAssetPrice = {\n /** Current price in selected currency */\n price: number;\n /** Timestamp of last price update */\n lastUpdated: number;\n};\n\n/**\n * Price data for fungible tokens (native, ERC20, SPL)\n * Matches V3SpotPricesResponse from the Price API.\n */\nexport type FungibleAssetPrice = BaseAssetPrice & {\n assetPriceType: 'fungible';\n /** CoinGecko ID */\n id?: string;\n /** Market capitalization */\n marketCap?: number;\n /** All-time high price */\n allTimeHigh?: number;\n /** All-time low price */\n allTimeLow?: number;\n /** 24h trading volume */\n totalVolume?: number;\n /** 24h high price */\n high1d?: number;\n /** 24h low price */\n low1d?: number;\n /** Circulating supply */\n circulatingSupply?: number;\n /** Fully diluted market cap */\n dilutedMarketCap?: number;\n /** 24h market cap change percentage */\n marketCapPercentChange1d?: number;\n /** 24h price change in USD */\n priceChange1d?: number;\n /** 5m price change percentage */\n pricePercentChange5m?: number;\n /** 1h price change percentage */\n pricePercentChange1h?: number;\n /** 4h price change percentage */\n pricePercentChange4h?: number;\n /** 24h price change percentage */\n pricePercentChange1d?: number;\n /** 7d price change percentage */\n pricePercentChange7d?: number;\n /** 14d price change percentage */\n pricePercentChange14d?: number;\n /** 30d price change percentage */\n pricePercentChange30d?: number;\n /** 200d price change percentage */\n pricePercentChange200d?: number;\n /** 1y price change percentage */\n pricePercentChange1y?: number;\n /** Current price in USD */\n usdPrice: number;\n};\n\n/**\n * Price data for NFT collections\n */\nexport type NFTAssetPrice = BaseAssetPrice & {\n assetPriceType: 'nft';\n /** Floor price */\n floorPrice?: number;\n /** Last sale price */\n lastSalePrice?: number;\n /** Collection trading volume */\n collectionVolume?: number;\n /** Average price */\n averagePrice?: number;\n /** Number of sales in 24h */\n sales24h?: number;\n};\n\n/**\n * Union type representing all possible asset price types.\n * All types must be JSON-serializable.\n */\nexport type AssetPrice = FungibleAssetPrice | NFTAssetPrice;\n\n// ============================================================================\n// BALANCE TYPES (vary by asset type)\n// ============================================================================\n\n/**\n * Balance data for fungible tokens (native, ERC20, SPL).\n */\nexport type FungibleAssetBalance = {\n /** Converted balance amount (e.g., \"1000\" for 1000 USDC) */\n amount: string;\n /**\n * Network-specific balance fields, when the source provides them. Stellar\n * native rows carry `spendableBalance` / `minimumReserveBalance`, and\n * trustlines carry `limit` / `authorized` / `sponsored`.\n */\n metadata?: Json;\n};\n\n/**\n * Balance data for ERC721 NFTs.\n * Each tokenId has its own CAIP-19 asset ID, so always \"1\".\n */\nexport type ERC721AssetBalance = {\n /** Always \"1\" for ERC721 (non-fungible) */\n amount: '1';\n};\n\n/**\n * Balance data for ERC1155 multi-tokens.\n */\nexport type ERC1155AssetBalance = {\n /** Quantity owned of this specific tokenId */\n amount: string;\n};\n\n/**\n * Union type representing all possible asset balance types.\n * All types must be JSON-serializable.\n */\nexport type AssetBalance =\n | FungibleAssetBalance\n | ERC721AssetBalance\n | ERC1155AssetBalance\n | { amount: string; [key: string]: Json };\n\n// ============================================================================\n// DATA SOURCE TYPES\n// ============================================================================\n\n/**\n * Data type dimension - what kind of data\n */\nexport type DataType = 'balance' | 'metadata' | 'price';\n\n/**\n * Account with its supported chains (enabled chains ∩ account scope).\n * Pre-computed by the controller so data sources do not need to implement\n * account-scope logic; they iterate over supportedChains for each account.\n */\nexport type AccountWithSupportedChains = {\n account: InternalAccount;\n supportedChains: ChainId[];\n};\n\n/**\n * Request for data from data sources\n */\nexport type DataRequest = {\n /** Accounts with their supported chains (enabled ∩ account scope). Data sources use this instead of computing accountSupportsChain. */\n accountsWithSupportedChains: AccountWithSupportedChains[];\n /** CAIP-2 chain IDs (union of chains in this request) */\n chainIds: ChainId[];\n /** Filter by asset types */\n assetTypes?: AssetType[];\n /** Which data to fetch */\n dataTypes: DataType[];\n /**\n * Optional scoped CAIP-19 asset IDs for this fetch (not the full pin list).\n * v5 force-update and v5 RPC fallback put pins here. v6 omits it: natives,\n * pins, and default tracked assets are read from controller state as\n * `includeAssetIds`; detected ERC-20 balances come back with the chain\n * snapshot. RPC fallback additionally refetches existing balances.\n */\n customAssets?: Caip19AssetId[];\n /**\n * When true, the data source should poll only the user's `customAssets`\n * for the requested chains and skip refreshing the regular tracked\n * balances. Used by the AssetsController to issue a supplemental RPC\n * subscription on chains that another data source is already covering\n * (Accounts API v5 path). Ignored when Accounts API v6 is enabled.\n */\n customAssetsOnly?: boolean;\n /** Force fresh fetch, bypass cache */\n forceUpdate?: boolean;\n /**\n * Bypass server-side HTTP caches in addition to the client-side ones that\n * `forceUpdate` already skips. Data sources backed by cached HTTP APIs\n * (e.g. the Accounts API with its 60s cache) append a random `bypassServerCache`\n * query param so the server re-reads instead of replaying a stale snapshot.\n * Use sparingly — e.g. right after a transaction confirms.\n */\n bypassServerCache?: boolean;\n /** Hint for polling interval (ms) - used by data sources that implement polling */\n updateInterval?: number;\n};\n\n/**\n * Response from data sources\n */\nexport type DataResponse = {\n /** Metadata for assets (shared across accounts) */\n assetsInfo?: Record<Caip19AssetId, AssetMetadata>;\n /** Price data for assets (shared across accounts) */\n assetsPrice?: Record<Caip19AssetId, AssetPrice>;\n /** Balance data per account */\n assetsBalance?: Record<AccountId, Record<Caip19AssetId, AssetBalance>>;\n /** Errors encountered, keyed by chain ID (chain-axis fallback + telemetry) */\n errors?: Record<ChainId, string>;\n /**\n * How to apply this response to state. See {@link AssetsUpdateMode}.\n * Defaults to `'merge'` if omitted.\n */\n updateMode?: AssetsUpdateMode;\n /**\n * When set with `updateMode: 'merge'`, balances on chains present in\n * `assetsBalance` replace the prior chain slice (stale tokens on those chains\n * are dropped). Custom assets on covered chains are preserved. Used for\n * Accounts API v5 `getAssets({ forceUpdate: true })`. Accounts API v6 uses\n * `updateMode: 'full'` instead.\n */\n replaceCoveredChainBalances?: boolean;\n};\n\n/**\n * Type of {@link DataResponse.updateMode}: how the controller applies the response to state.\n *\n * - **full**: Response is the full set for covered chains (those present in\n * `assetsBalance`). Assets in state on those chains but not in the response\n * are cleared, including custom assets (Accounts API v6 returns pins via\n * `includeAssetIds`). A chain the source could not answer in full is reported\n * in `errors` and left out of `assetsBalance` entirely, so it is never\n * covered. Use for Accounts API v6 and RpcDataSource v6 snapshots.\n * - **merge**: Only assets present in the response are updated; nothing is\n * removed, unless {@link DataResponse.replaceCoveredChainBalances} is set\n * (Accounts API v5 force refresh). Metadata and prices from the response\n * are applied. Use for event-driven updates and Accounts API v5.\n */\nexport type AssetsUpdateMode = 'full' | 'merge';\n\nexport type AssetsLoadingStatus = 'loading' | 'loaded';\n\n// ============================================================================\n// DATA SOURCE <-> CONTROLLER (DIRECT CALLS, NO MESSENGER PER SOURCE)\n// ============================================================================\n\n/**\n * Callbacks for data sources to report to AssetsController.\n * Passed to data sources so they report by direct call instead of messenger.\n */\nexport type AssetsControllerReport = {\n onActiveChainsUpdate: (dataSourceId: string, activeChains: ChainId[]) => void;\n onAssetsUpdate: (response: DataResponse, sourceId: string) => Promise<void>;\n};\n\n/** Request passed from controller to data source when subscribing */\nexport type DataSourceSubscriptionRequest = {\n request: DataRequest;\n subscriptionId: string;\n isUpdate: boolean;\n};\n\n/**\n * Interface for balance data sources that the controller calls directly.\n * No messenger is required for controller <-> data source communication.\n */\nexport type BalanceDataSource = {\n getAssetsMiddleware: () => Middleware;\n subscribe: (request: DataSourceSubscriptionRequest) => Promise<void>;\n unsubscribe: (subscriptionId: string) => Promise<void>;\n getName: () => string;\n};\n\n/**\n * Interface for the price data source (subscribe/unsubscribe + middleware).\n * Controller calls these methods directly.\n */\nexport type PriceDataSourceInterface = {\n getAssetsMiddleware: () => Middleware;\n subscribe: (request: DataSourceSubscriptionRequest) => Promise<void>;\n unsubscribe: (subscriptionId: string) => Promise<void>;\n};\n\n/**\n * Middleware-only source (e.g. detection, token enrichment).\n * Controller calls getAssetsMiddleware() directly.\n */\nexport type MiddlewareDataSource = {\n getAssetsMiddleware: () => Middleware;\n};\n\n// ============================================================================\n// CONTROLLER STATE\n// ============================================================================\n\n/**\n * State structure for AssetsController following normalized design.\n *\n * All values must stay JSON-serializable. UI preferences (e.g. hidden) live in\n * assetPreferences, not in metadata.\n *\n * Keys use CAIP identifiers:\n * - assetsInfo keys: CAIP-19 asset IDs (e.g., \"eip155:1/erc20:0x...\")\n * - assetsBalance outer keys: Account IDs (InternalAccount.id UUIDs)\n * - assetsBalance inner keys: CAIP-19 asset IDs\n * - assetsPrice keys: CAIP-19 asset IDs\n * - customAssets outer keys: Account IDs (InternalAccount.id UUIDs)\n * - customAssets inner values: CAIP-19 asset IDs array\n * - assetPreferences keys: CAIP-19 asset IDs\n */\nexport type AssetsControllerState = {\n /** Shared metadata for all assets (stored once per asset) */\n assetsInfo: Record<Caip19AssetId, AssetMetadata>;\n /** Per-account balance data */\n assetsBalance: Record<AccountId, Record<Caip19AssetId, AssetBalance>>;\n /** Price data for assets */\n assetsPrice: Record<Caip19AssetId, AssetPrice>;\n /** Custom assets added by users per account */\n customAssets: Record<AccountId, Caip19AssetId[]>;\n /** UI preferences per asset (e.g. hidden) - separate from metadata */\n assetPreferences: Record<Caip19AssetId, AssetPreferences>;\n /** Currently-active ISO 4217 currency code */\n selectedCurrency: SupportedCurrency;\n assetsLoadingStatus?: Record<AccountId, AssetsLoadingStatus>;\n /**\n * Per-account status of the background (Snap + RPC) fetch that runs after\n * the initial balance has resolved. Tracked on every forced fetch.\n */\n assetsBackgroundLoadingStatus?: Record<AccountId, AssetsLoadingStatus>;\n};\n\n// ============================================================================\n// UNIFIED MIDDLEWARE TYPES\n// ============================================================================\n\n/**\n * Base context for all middleware operations.\n * Contains the common interface shared by fetch and subscribe.\n */\nexport type Context = {\n /** The data request */\n request: DataRequest;\n /** The response data (mutated by middlewares) */\n response: DataResponse;\n /**\n * Optional breakdown of latency (ms) per data source, e.g. from parallel\n * middlewares. Keys are source names (often \"MiddlewareName.SourceName\").\n * Merged into the controller's durationByDataSource for tracing.\n */\n durationByDataSource?: Record<string, number>;\n};\n\n/**\n * Next function for middleware chain\n */\nexport type NextFunction = (context: Context) => Promise<Context>;\n\n/**\n * Middleware function - works for both fetch and subscribe operations.\n */\nexport type Middleware = (\n context: Context,\n next: NextFunction,\n) => Promise<Context>;\n\n/**\n * An assets data source: any object that can participate in the assets\n * middleware chain with a display name (e.g. for tracing). Used by\n * createParallelMiddleware and by the controller when executing the chain.\n */\nexport type AssetsDataSource = {\n getName(): string;\n assetsMiddleware: Middleware;\n};\n\n/**\n * Wraps a middleware to only execute if specific dataTypes are requested.\n *\n * @param dataTypes - DataTypes that must be in the request for middleware to run\n * @param middleware - The middleware to conditionally execute\n * @returns A middleware that skips execution if none of the dataTypes are requested\n *\n * @example\n * ```typescript\n * // Only runs for metadata requests\n * const metadataMiddleware = forDataTypes(['metadata'], async (ctx, next) => {\n * const result = await next(ctx);\n * // Enrich metadata...\n * return result;\n * });\n *\n * // Runs for balance or price requests\n * const balanceOrPriceMiddleware = forDataTypes(['balance', 'price'], async (ctx, next) => {\n * const result = await next(ctx);\n * // Process balances or prices...\n * return result;\n * });\n * ```\n */\nexport function forDataTypes(\n dataTypes: DataType[],\n middleware: Middleware,\n): Middleware {\n return async (ctx, next) => {\n const requestedTypes = ctx.request.dataTypes;\n const shouldRun = dataTypes.some((dt) => requestedTypes.includes(dt));\n\n if (!shouldRun) {\n return next(ctx);\n }\n\n return middleware(ctx, next);\n };\n}\n\n/**\n * Context for fetch operations.\n * Extends base Context - no additional fields needed for fetch.\n */\nexport type FetchContext = Context;\n\n// Legacy aliases for backwards compatibility\nexport type FetchNextFunction = NextFunction;\nexport type FetchMiddleware = Middleware;\n\n/**\n * Subscription response returned when subscribing to asset updates.\n */\nexport type SubscriptionResponse = {\n /** Chains actively subscribed */\n chains: ChainId[];\n /** Account ID being watched */\n accountId: AccountId;\n /** Asset types being watched */\n assetTypes: AssetType[];\n /** Data types being kept fresh */\n dataTypes: DataType[];\n /** Cleanup function */\n unsubscribe: () => void;\n};\n\n// ============================================================================\n// COMBINED ASSET TYPE (for UI)\n// ============================================================================\n\n/**\n * Combined asset type matching state structure: balance, metadata, price\n */\nexport type Asset = {\n /** CAIP-19 asset ID */\n id: Caip19AssetId;\n /** CAIP-2 chain ID (extracted from id) */\n chainId: ChainId;\n /** Balance data */\n balance: AssetBalance;\n /** Metadata (symbol, name, decimals, etc.) */\n metadata: AssetMetadata;\n /** Price data */\n price: AssetPrice;\n /** Computed fiat value (balance × price) */\n fiatValue: number;\n};\n\n// ============================================================================\n// EVENT TYPES\n// ============================================================================\n\n/**\n * Event emitted when balances change\n */\nexport type BalanceChangeEvent = {\n accountId: AccountId;\n assetId: Caip19AssetId;\n previousAmount: string;\n newAmount: string;\n timestamp: number;\n};\n\n/**\n * Event emitted when prices change\n */\nexport type PriceChangeEvent = {\n assetIds: Caip19AssetId[];\n timestamp: number;\n};\n\n/**\n * Event emitted when metadata changes\n */\nexport type MetadataChangeEvent = {\n assetId: Caip19AssetId;\n changes: Partial<AssetMetadata>;\n};\n"]}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAoiBA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,UAAU,YAAY,CAC1B,SAAqB,EACrB,UAAsB;IAEtB,OAAO,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;QACzB,MAAM,cAAc,GAAG,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC;QAC7C,MAAM,SAAS,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,cAAc,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC;QAEtE,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;QACnB,CAAC;QAED,OAAO,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IAC/B,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import type { SupportedCurrency } from '@metamask/core-backend';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport type { CaipAssetType, CaipChainId, Json } from '@metamask/utils';\n\n/**\n * CAIP-19 compliant asset identifier\n * Format: \"{chainId}/{assetNamespace}:{assetReference}[/tokenId]\"\n *\n * Examples:\n * - Native: \"eip155:1/slip44:60\" (ETH)\n * - ERC20: \"eip155:1/erc20:0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\" (USDC)\n * - ERC721: \"eip155:1/erc721:0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D/1234\" (BAYC #1234)\n * - SPL: \"solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp/token:EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v\"\n */\nexport type Caip19AssetId = CaipAssetType;\n\n/**\n * InternalAccount UUID from AccountsController\n * Not the blockchain address!\n */\nexport type AccountId = string;\n\n/**\n * CAIP-2 chain identifier\n */\nexport type ChainId = CaipChainId;\n\n// ============================================================================\n// ASSET TYPES - Defined by metadata structure\n// ============================================================================\n\n/**\n * Asset types define the metadata structure, not blockchain implementation.\n * - \"fungible\" includes: native, erc20, spl - all share balance, symbol, decimals\n * - \"nft\" includes: erc721, erc1155 - include tokenId, image, attributes\n */\nexport type AssetType = 'fungible' | 'nft' | 'collectible';\n\n/**\n * Token standards - blockchain implementation details\n */\nexport type TokenStandard =\n | 'native'\n | 'erc20'\n | 'erc721'\n | 'erc1155'\n | 'spl'\n | string;\n\n// ============================================================================\n// METADATA TYPES (vary by asset type)\n// ============================================================================\n\n/**\n * UI preferences for an asset (stored in assetPreferences state, not in metadata).\n */\nexport type AssetPreferences = {\n /** Whether the asset is hidden from display */\n hidden?: boolean;\n};\n\n/**\n * Base metadata attributes shared by ALL asset types.\n */\nexport type BaseAssetMetadata = {\n /** Token standard - how it's implemented on the blockchain */\n type: TokenStandard;\n /** Display symbol (e.g., \"ETH\", \"USDC\") */\n symbol: string;\n /** Full name (e.g., \"Ethereum\", \"USD Coin\") */\n name: string;\n /** Token decimals (18 for ETH, 6 for USDC, etc.) */\n decimals: number;\n /** Logo URL or data URI */\n image?: string;\n};\n\n// ============================================================================\n// TOKEN CONTRACT DATA TYPES\n// ============================================================================\n\n/** Fee information for token transfers */\nexport type TokenFees = {\n avgFee: number;\n maxFee: number;\n minFee: number;\n};\n\n/** Honeypot detection status */\nexport type HoneypotStatus = {\n honeypotIs: boolean;\n goPlus?: boolean;\n};\n\n/** Storage slot information for the contract */\nexport type StorageSlots = {\n balance: number;\n approval: number;\n};\n\n/** Localized description */\nexport type LocalizedDescription = {\n en: string;\n};\n\n// ============================================================================\n// ASSET METADATA TYPES\n// ============================================================================\n\n/**\n * Metadata for fungible tokens.\n * Structure mirrors V3AssetResponse from the Tokens API.\n *\n * Differences from V3AssetResponse:\n * - `type` is derived from assetId namespace (not in API response)\n * - `image` maps from API's `iconUrl`\n * - `assetId` is not stored (used as the key)\n */\nexport type FungibleAssetMetadata = {\n /** Token type derived from assetId namespace */\n type: 'native' | 'erc20' | 'spl';\n /** CoinGecko ID for price lookups */\n coingeckoId?: string;\n /** Number of token list occurrences */\n occurrences?: number;\n /** DEX/aggregator integrations */\n aggregators?: string[];\n /** Asset labels/tags (e.g., \"stable_coin\") */\n labels?: string[];\n /** Whether the token supports ERC-20 permit */\n erc20Permit?: boolean;\n /** Fee information for token transfers */\n fees?: TokenFees;\n /** Honeypot detection status */\n honeypotStatus?: HoneypotStatus;\n /** Storage slot information for the contract */\n storage?: StorageSlots;\n /** Whether the contract is verified */\n isContractVerified?: boolean;\n /** Localized description */\n description?: LocalizedDescription;\n} & BaseAssetMetadata;\n\n/**\n * Metadata for ERC721 NFTs\n * Asset Type: \"nft\"\n */\nexport type ERC721AssetMetadata = {\n type: 'erc721';\n decimals: 0;\n /** Collection name */\n collectionName?: string;\n /** Collection size */\n collectionSize?: number;\n /** NFT traits/attributes - must be Json-serializable */\n traits?: Record<string, Json>;\n /** Rarity score */\n rarity?: number;\n /** Verification status */\n verified?: boolean;\n} & BaseAssetMetadata;\n\n/**\n * Metadata for ERC1155 multi-tokens\n */\nexport type ERC1155AssetMetadata = {\n type: 'erc1155';\n /** Token URI */\n tokenUri?: string;\n /** Token category */\n category?: string;\n /** Spam detection flag */\n isSpam?: boolean;\n} & BaseAssetMetadata;\n\n/**\n * Union type representing all possible asset metadata types.\n * All types must be JSON-serializable.\n */\nexport type AssetMetadata =\n | FungibleAssetMetadata\n | ERC721AssetMetadata\n | ERC1155AssetMetadata\n | (BaseAssetMetadata & { [key: string]: Json });\n\n// ============================================================================\n// PRICE TYPES (vary by asset type)\n// ============================================================================\n\n/**\n * Base price attributes.\n */\nexport type BaseAssetPrice = {\n /** Current price in selected currency */\n price: number;\n /** Timestamp of last price update */\n lastUpdated: number;\n};\n\n/**\n * Price data for fungible tokens (native, ERC20, SPL)\n * Matches V3SpotPricesResponse from the Price API.\n */\nexport type FungibleAssetPrice = BaseAssetPrice & {\n assetPriceType: 'fungible';\n /** CoinGecko ID */\n id?: string;\n /** Market capitalization */\n marketCap?: number;\n /** All-time high price */\n allTimeHigh?: number;\n /** All-time low price */\n allTimeLow?: number;\n /** 24h trading volume */\n totalVolume?: number;\n /** 24h high price */\n high1d?: number;\n /** 24h low price */\n low1d?: number;\n /** Circulating supply */\n circulatingSupply?: number;\n /** Fully diluted market cap */\n dilutedMarketCap?: number;\n /** 24h market cap change percentage */\n marketCapPercentChange1d?: number;\n /** 24h price change in USD */\n priceChange1d?: number;\n /** 5m price change percentage */\n pricePercentChange5m?: number;\n /** 1h price change percentage */\n pricePercentChange1h?: number;\n /** 4h price change percentage */\n pricePercentChange4h?: number;\n /** 24h price change percentage */\n pricePercentChange1d?: number;\n /** 7d price change percentage */\n pricePercentChange7d?: number;\n /** 14d price change percentage */\n pricePercentChange14d?: number;\n /** 30d price change percentage */\n pricePercentChange30d?: number;\n /** 200d price change percentage */\n pricePercentChange200d?: number;\n /** 1y price change percentage */\n pricePercentChange1y?: number;\n /** Current price in USD */\n usdPrice: number;\n};\n\n/**\n * Price data for NFT collections\n */\nexport type NFTAssetPrice = BaseAssetPrice & {\n assetPriceType: 'nft';\n /** Floor price */\n floorPrice?: number;\n /** Last sale price */\n lastSalePrice?: number;\n /** Collection trading volume */\n collectionVolume?: number;\n /** Average price */\n averagePrice?: number;\n /** Number of sales in 24h */\n sales24h?: number;\n};\n\n/**\n * Union type representing all possible asset price types.\n * All types must be JSON-serializable.\n */\nexport type AssetPrice = FungibleAssetPrice | NFTAssetPrice;\n\n// ============================================================================\n// BALANCE TYPES (vary by asset type)\n// ============================================================================\n\n/**\n * Balance data for fungible tokens (native, ERC20, SPL).\n */\nexport type FungibleAssetBalance = {\n /** Converted balance amount (e.g., \"1000\" for 1000 USDC) */\n amount: string;\n /**\n * Network-specific balance fields, when the source provides them. Stellar\n * native rows carry `spendableBalance` / `minimumReserveBalance`, and\n * trustlines carry `limit` / `authorized` / `sponsored`.\n */\n metadata?: Json;\n};\n\n/**\n * Balance data for ERC721 NFTs.\n * Each tokenId has its own CAIP-19 asset ID, so always \"1\".\n */\nexport type ERC721AssetBalance = {\n /** Always \"1\" for ERC721 (non-fungible) */\n amount: '1';\n};\n\n/**\n * Balance data for ERC1155 multi-tokens.\n */\nexport type ERC1155AssetBalance = {\n /** Quantity owned of this specific tokenId */\n amount: string;\n};\n\n/**\n * Union type representing all possible asset balance types.\n * All types must be JSON-serializable.\n */\nexport type AssetBalance =\n | FungibleAssetBalance\n | ERC721AssetBalance\n | ERC1155AssetBalance\n | { amount: string; [key: string]: Json };\n\n// ============================================================================\n// DATA SOURCE TYPES\n// ============================================================================\n\n/**\n * Data type dimension - what kind of data\n */\nexport type DataType = 'balance' | 'metadata' | 'price';\n\n/**\n * Account with its supported chains (enabled chains ∩ account scope).\n * Pre-computed by the controller so data sources do not need to implement\n * account-scope logic; they iterate over supportedChains for each account.\n */\nexport type AccountWithSupportedChains = {\n account: InternalAccount;\n supportedChains: ChainId[];\n};\n\n/**\n * Request for data from data sources\n */\nexport type DataRequest = {\n /** Accounts with their supported chains (enabled ∩ account scope). Data sources use this instead of computing accountSupportsChain. */\n accountsWithSupportedChains: AccountWithSupportedChains[];\n /** CAIP-2 chain IDs (union of chains in this request) */\n chainIds: ChainId[];\n /** Filter by asset types */\n assetTypes?: AssetType[];\n /** Which data to fetch */\n dataTypes: DataType[];\n /**\n * Optional scoped CAIP-19 asset IDs for this fetch (not the full pin list).\n * v5 force-update and v5 RPC fallback put pins here. v6 omits it: natives,\n * pins, and default tracked assets are read from controller state as\n * `includeAssetIds`; detected ERC-20 balances come back with the chain\n * snapshot. RPC fallback additionally refetches existing balances.\n */\n customAssets?: Caip19AssetId[];\n /** Force fresh fetch, bypass cache */\n forceUpdate?: boolean;\n /**\n * Bypass server-side HTTP caches in addition to the client-side ones that\n * `forceUpdate` already skips. Data sources backed by cached HTTP APIs\n * (e.g. the Accounts API with its 60s cache) append a random `bypassServerCache`\n * query param so the server re-reads instead of replaying a stale snapshot.\n * Use sparingly — e.g. right after a transaction confirms.\n */\n bypassServerCache?: boolean;\n /** Hint for polling interval (ms) - used by data sources that implement polling */\n updateInterval?: number;\n};\n\n/**\n * Response from data sources\n */\nexport type DataResponse = {\n /** Metadata for assets (shared across accounts) */\n assetsInfo?: Record<Caip19AssetId, AssetMetadata>;\n /** Price data for assets (shared across accounts) */\n assetsPrice?: Record<Caip19AssetId, AssetPrice>;\n /** Balance data per account */\n assetsBalance?: Record<AccountId, Record<Caip19AssetId, AssetBalance>>;\n /** Errors encountered, keyed by chain ID (chain-axis fallback + telemetry) */\n errors?: Record<ChainId, string>;\n /**\n * How to apply this response to state. See {@link AssetsUpdateMode}.\n * Defaults to `'merge'` if omitted.\n */\n updateMode?: AssetsUpdateMode;\n /**\n * When set with `updateMode: 'merge'`, balances on chains present in\n * `assetsBalance` replace the prior chain slice (stale tokens on those chains\n * are dropped). Custom assets on covered chains are preserved. Used for\n * Accounts API v5 `getAssets({ forceUpdate: true })`. Accounts API v6 uses\n * `updateMode: 'full'` instead.\n */\n replaceCoveredChainBalances?: boolean;\n};\n\n/**\n * Type of {@link DataResponse.updateMode}: how the controller applies the response to state.\n *\n * - **full**: Response is the full set for covered chains (those present in\n * `assetsBalance`). Assets in state on those chains but not in the response\n * are cleared, including custom assets (Accounts API v6 returns pins via\n * `includeAssetIds`). A chain the source could not answer in full is reported\n * in `errors` and left out of `assetsBalance` entirely, so it is never\n * covered. Use for Accounts API v6 and RpcDataSource v6 snapshots.\n * - **merge**: Only assets present in the response are updated; nothing is\n * removed, unless {@link DataResponse.replaceCoveredChainBalances} is set\n * (Accounts API v5 force refresh). Metadata and prices from the response\n * are applied. Use for event-driven updates and Accounts API v5.\n */\nexport type AssetsUpdateMode = 'full' | 'merge';\n\nexport type AssetsLoadingStatus = 'loading' | 'loaded';\n\n// ============================================================================\n// DATA SOURCE <-> CONTROLLER (DIRECT CALLS, NO MESSENGER PER SOURCE)\n// ============================================================================\n\n/**\n * Callbacks for data sources to report to AssetsController.\n * Passed to data sources so they report by direct call instead of messenger.\n */\nexport type AssetsControllerReport = {\n onActiveChainsUpdate: (dataSourceId: string, activeChains: ChainId[]) => void;\n onAssetsUpdate: (response: DataResponse, sourceId: string) => Promise<void>;\n};\n\n/** Request passed from controller to data source when subscribing */\nexport type DataSourceSubscriptionRequest = {\n request: DataRequest;\n subscriptionId: string;\n isUpdate: boolean;\n};\n\n/**\n * Interface for balance data sources that the controller calls directly.\n * No messenger is required for controller <-> data source communication.\n */\nexport type BalanceDataSource = {\n getAssetsMiddleware: () => Middleware;\n subscribe: (request: DataSourceSubscriptionRequest) => Promise<void>;\n unsubscribe: (subscriptionId: string) => Promise<void>;\n getName: () => string;\n};\n\n/**\n * Interface for the price data source (subscribe/unsubscribe + middleware).\n * Controller calls these methods directly.\n */\nexport type PriceDataSourceInterface = {\n getAssetsMiddleware: () => Middleware;\n subscribe: (request: DataSourceSubscriptionRequest) => Promise<void>;\n unsubscribe: (subscriptionId: string) => Promise<void>;\n};\n\n/**\n * Middleware-only source (e.g. detection, token enrichment).\n * Controller calls getAssetsMiddleware() directly.\n */\nexport type MiddlewareDataSource = {\n getAssetsMiddleware: () => Middleware;\n};\n\n// ============================================================================\n// CONTROLLER STATE\n// ============================================================================\n\n/**\n * State structure for AssetsController following normalized design.\n *\n * All values must stay JSON-serializable. UI preferences (e.g. hidden) live in\n * assetPreferences, not in metadata.\n *\n * Keys use CAIP identifiers:\n * - assetsInfo keys: CAIP-19 asset IDs (e.g., \"eip155:1/erc20:0x...\")\n * - assetsBalance outer keys: Account IDs (InternalAccount.id UUIDs)\n * - assetsBalance inner keys: CAIP-19 asset IDs\n * - assetsPrice keys: CAIP-19 asset IDs\n * - customAssets outer keys: Account IDs (InternalAccount.id UUIDs)\n * - customAssets inner values: CAIP-19 asset IDs array\n * - assetPreferences keys: CAIP-19 asset IDs\n */\nexport type AssetsControllerState = {\n /** Shared metadata for all assets (stored once per asset) */\n assetsInfo: Record<Caip19AssetId, AssetMetadata>;\n /** Per-account balance data */\n assetsBalance: Record<AccountId, Record<Caip19AssetId, AssetBalance>>;\n /** Price data for assets */\n assetsPrice: Record<Caip19AssetId, AssetPrice>;\n /** Custom assets added by users per account */\n customAssets: Record<AccountId, Caip19AssetId[]>;\n /** UI preferences per asset (e.g. hidden) - separate from metadata */\n assetPreferences: Record<Caip19AssetId, AssetPreferences>;\n /** Currently-active ISO 4217 currency code */\n selectedCurrency: SupportedCurrency;\n assetsLoadingStatus?: Record<AccountId, AssetsLoadingStatus>;\n /**\n * Per-account status of the background (Snap + RPC) fetch that runs after\n * the initial balance has resolved. Tracked on every forced fetch.\n */\n assetsBackgroundLoadingStatus?: Record<AccountId, AssetsLoadingStatus>;\n};\n\n// ============================================================================\n// UNIFIED MIDDLEWARE TYPES\n// ============================================================================\n\n/**\n * Base context for all middleware operations.\n * Contains the common interface shared by fetch and subscribe.\n */\nexport type Context = {\n /** The data request */\n request: DataRequest;\n /** The response data (mutated by middlewares) */\n response: DataResponse;\n /**\n * Optional breakdown of latency (ms) per data source, e.g. from parallel\n * middlewares. Keys are source names (often \"MiddlewareName.SourceName\").\n * Merged into the controller's durationByDataSource for tracing.\n */\n durationByDataSource?: Record<string, number>;\n};\n\n/**\n * Next function for middleware chain\n */\nexport type NextFunction = (context: Context) => Promise<Context>;\n\n/**\n * Middleware function - works for both fetch and subscribe operations.\n */\nexport type Middleware = (\n context: Context,\n next: NextFunction,\n) => Promise<Context>;\n\n/**\n * An assets data source: any object that can participate in the assets\n * middleware chain with a display name (e.g. for tracing). Used by\n * createParallelMiddleware and by the controller when executing the chain.\n */\nexport type AssetsDataSource = {\n getName(): string;\n assetsMiddleware: Middleware;\n};\n\n/**\n * Wraps a middleware to only execute if specific dataTypes are requested.\n *\n * @param dataTypes - DataTypes that must be in the request for middleware to run\n * @param middleware - The middleware to conditionally execute\n * @returns A middleware that skips execution if none of the dataTypes are requested\n *\n * @example\n * ```typescript\n * // Only runs for metadata requests\n * const metadataMiddleware = forDataTypes(['metadata'], async (ctx, next) => {\n * const result = await next(ctx);\n * // Enrich metadata...\n * return result;\n * });\n *\n * // Runs for balance or price requests\n * const balanceOrPriceMiddleware = forDataTypes(['balance', 'price'], async (ctx, next) => {\n * const result = await next(ctx);\n * // Process balances or prices...\n * return result;\n * });\n * ```\n */\nexport function forDataTypes(\n dataTypes: DataType[],\n middleware: Middleware,\n): Middleware {\n return async (ctx, next) => {\n const requestedTypes = ctx.request.dataTypes;\n const shouldRun = dataTypes.some((dt) => requestedTypes.includes(dt));\n\n if (!shouldRun) {\n return next(ctx);\n }\n\n return middleware(ctx, next);\n };\n}\n\n/**\n * Context for fetch operations.\n * Extends base Context - no additional fields needed for fetch.\n */\nexport type FetchContext = Context;\n\n// Legacy aliases for backwards compatibility\nexport type FetchNextFunction = NextFunction;\nexport type FetchMiddleware = Middleware;\n\n/**\n * Subscription response returned when subscribing to asset updates.\n */\nexport type SubscriptionResponse = {\n /** Chains actively subscribed */\n chains: ChainId[];\n /** Account ID being watched */\n accountId: AccountId;\n /** Asset types being watched */\n assetTypes: AssetType[];\n /** Data types being kept fresh */\n dataTypes: DataType[];\n /** Cleanup function */\n unsubscribe: () => void;\n};\n\n// ============================================================================\n// COMBINED ASSET TYPE (for UI)\n// ============================================================================\n\n/**\n * Combined asset type matching state structure: balance, metadata, price\n */\nexport type Asset = {\n /** CAIP-19 asset ID */\n id: Caip19AssetId;\n /** CAIP-2 chain ID (extracted from id) */\n chainId: ChainId;\n /** Balance data */\n balance: AssetBalance;\n /** Metadata (symbol, name, decimals, etc.) */\n metadata: AssetMetadata;\n /** Price data */\n price: AssetPrice;\n /** Computed fiat value (balance × price) */\n fiatValue: number;\n};\n\n// ============================================================================\n// EVENT TYPES\n// ============================================================================\n\n/**\n * Event emitted when balances change\n */\nexport type BalanceChangeEvent = {\n accountId: AccountId;\n assetId: Caip19AssetId;\n previousAmount: string;\n newAmount: string;\n timestamp: number;\n};\n\n/**\n * Event emitted when prices change\n */\nexport type PriceChangeEvent = {\n assetIds: Caip19AssetId[];\n timestamp: number;\n};\n\n/**\n * Event emitted when metadata changes\n */\nexport type MetadataChangeEvent = {\n assetId: Caip19AssetId;\n changes: Partial<AssetMetadata>;\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"native-assets.d.ts","sourceRoot":"","sources":["../../src/utils/native-assets.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAU1D;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,aAAa,EAAE,QAAQ,CAAC,MAAM,CAAC,OAAO,EAAE,aAAa,CAAC,
|
|
1
|
+
{"version":3,"file":"native-assets.d.ts","sourceRoot":"","sources":["../../src/utils/native-assets.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAU1D;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,aAAa,EAAE,QAAQ,CAAC,MAAM,CAAC,OAAO,EAAE,aAAa,CAAC,CAyGlE,CAAC;AAQF;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAM/D;AAED;;;;;GAKG;AACH,wBAAgB,6BAA6B,IAAI,MAAM,CACrD,OAAO,EACP,aAAa,CACd,CAMA;AAED;;;;;;;;;GASG;AACH,wBAAsB,wBAAwB,IAAI,OAAO,CACvD,MAAM,CAAC,OAAO,EAAE,aAAa,CAAC,CAC/B,CAmCA"}
|
|
@@ -80,7 +80,6 @@ export const NATIVE_ASSETS = {
|
|
|
80
80
|
'eip155:68414': 'eip155:68414/erc20:0x0000000000000000000000000000000000000000', // MapleStory Universe - no slip44
|
|
81
81
|
'eip155:73115': 'eip155:73115/erc20:0x0000000000000000000000000000000000000000', // ICB Network - Native symbol: ICBX
|
|
82
82
|
'eip155:80094': 'eip155:80094/erc20:0x0000000000000000000000000000000000000000', // Berachain - Native symbol: Bera
|
|
83
|
-
'eip155:81457': 'eip155:81457/slip44:60', // Blast Mainnet - Native symbol: ETH
|
|
84
83
|
'eip155:88888': 'eip155:88888/erc20:0x0000000000000000000000000000000000000000', // Chiliz Chain - Native symbol: CHZ
|
|
85
84
|
'eip155:97741': 'eip155:97741/erc20:0x0000000000000000000000000000000000000000', // Pepe Unchained Mainnet - Native symbol: PEPU
|
|
86
85
|
'eip155:98866': 'eip155:98866/erc20:0x0000000000000000000000000000000000000000', // Plume Mainnet - Native symbol: Plume
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"native-assets.js","sourceRoot":"","sources":["../../src/utils/native-assets.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AAGpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD,MAAM,mBAAmB,GAAG,qCAAqC,CAAC;AAOlE;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,aAAa,GAA6C;IACrE,UAAU,EAAE,oBAAoB,EAAE,wCAAwC;IAC1E,WAAW,EAAE,qBAA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EAChB,CAAC;oBACD,SAAS;gBACX,CAAC;gBAED,MAAM,WAAW,GAAG,UAAU,KAAK,CAAC,OAAO,EAAa,CAAC;gBACzD,IAAI,CAAC,eAAe,CAAC,WAAW,CAAC,EAAE,CAAC;oBAClC,eAAe,CAAC,WAAW,CAAC;wBAC1B,UAAU,KAAK,CAAC,OAAO,WAAW,KAAK,CAAC,MAAM,EAAE,CAAC;gBACrD,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,sDAAsD;IACxD,CAAC;IAED,OAAO,eAAe,CAAC;AACzB,CAAC","sourcesContent":["import { fetchWithErrorHandling } from '@metamask/controller-utils';\n\nimport type { Caip19AssetId, ChainId } from '../types.js';\nimport { normalizeAssetId } from './normalizeAssetId.js';\n\nconst CHAINID_NETWORK_URL = 'https://chainid.network/chains.json';\n\ntype ChainIdNetworkEntry = {\n chainId: number;\n slip44?: number;\n};\n\n/**\n * Seed native CAIP-19 asset IDs, keyed by CAIP-2 chain ID.\n *\n * Covers Price API v3/spot-prices EVM natives plus the Bitcoin, Solana,\n * Stellar and Tron natives this controller ingests. chainid.network only\n * fills extra `eip155` gaps, so without the non-EVM rows an account holding\n * nothing on those networks gets an empty list instead of BTC/SOL/XLM/TRX\n * at 0.\n *\n * Price API v3/spot-prices chains only for EVM — verify support before adding:\n * https://github.com/consensys-vertical-apps/va-mmcx-price-api/blob/main/src/constants/slip44.ts\n * Include chain name + native symbol. Keep sorted by chain ID.\n */\nexport const NATIVE_ASSETS: Readonly<Record<ChainId, Caip19AssetId>> = {\n 'eip155:1': 'eip155:1/slip44:60', // Ethereum Mainnet - Native symbol: ETH\n 'eip155:10': 'eip155:10/slip44:60', // OP Mainnet - Native symbol: ETH\n 'eip155:25': 'eip155:25/slip44:394', // Cronos Mainnet - Native symbol: CRO\n 'eip155:30': 'eip155:30/slip44:137', // Rootstock Mainnet - Native symbol: RBTC\n 'eip155:42': 'eip155:42/erc20:0x0000000000000000000000000000000000000000', // Lukso - native symbol: LYX\n 'eip155:50': 'eip155:50/erc20:0x0000000000000000000000000000000000000000', // xdc-network - native symbol: XDC\n 'eip155:56': 'eip155:56/slip44:714', // BNB Smart Chain Mainnet - Native symbol: BNB\n 'eip155:57': 'eip155:57/slip44:57', // Syscoin Mainnet - Native symbol: SYS\n 'eip155:82': 'eip155:82/slip44:18000', // Meter Mainnet - Native symbol: MTR\n 'eip155:88': 'eip155:88/slip44:889', // TomoChain - Native symbol: TOMO\n 'eip155:100': 'eip155:100/erc20:0x0000000000000000000000000000000000000000', // Gnosis (formerly xDAI Chain) - Native symbol: xDAI\n 'eip155:106': 'eip155:106/slip44:5655640', // Velas EVM Mainnet - Native symbol: VLX\n 'eip155:122': 'eip155:122/erc20:0x0000000000000000000000000000000000000000', // Fuse Mainnet - Native symbol: FUSE\n 'eip155:128': 'eip155:128/slip44:1010', // Huobi ECO Chain Mainnet - Native symbol: HT\n 'eip155:137': 'eip155:137/slip44:966', // Polygon Mainnet - Native symbol: POL\n 'eip155:143': 'eip155:143/slip44:268435779', // Monad Mainnet - Native symbol: MON\n 'eip155:146': 'eip155:146/slip44:10007', // Sonic Mainnet - Native symbol: S\n 'eip155:166': 'eip155:166/slip44:11111166', // Nomina - Native symbol: NOM (no registered slip44; synthetic 11111<chainId>)\n 'eip155:196': 'eip155:196/erc20:0x0000000000000000000000000000000000000000', // X Layer Mainnet - Native symbol: OKB\n 'eip155:232': 'eip155:232/erc20:0x0000000000000000000000000000000000000000', // Lens Mainnet - Native symbol: GHO\n 'eip155:250': 'eip155:250/slip44:1007', // Fantom Opera - Native symbol: FTM\n 'eip155:252': 'eip155:252/erc20:0x0000000000000000000000000000000000000000', // Fraxtal - native symbol: FRAX\n 'eip155:288': 'eip155:288/slip44:60', // Boba Network (Ethereum L2) - Native symbol: ETH\n 'eip155:321': 'eip155:321/slip44:641', // KCC Mainnet - Native symbol: KCS\n 'eip155:324': 'eip155:324/slip44:60', // zkSync Era Mainnet (Ethereum L2) - Native symbol: ETH\n 'eip155:336': 'eip155:336/slip44:809', // Shiden - Native symbol: SDN\n 'eip155:361': 'eip155:361/slip44:589', // Theta Mainnet - Native symbol: TFUEL\n 'eip155:698': 'eip155:698/slip44:714', // Matchain - Native symbol: BNB\n 'eip155:747': 'eip155:747/slip44:539', // Flow evm - Native symbol: Flow\n 'eip155:988': 'eip155:988/erc20:0x0000000000000000000000000000000000000000', // Stable - Native symbol: USDT0\n 'eip155:999': 'eip155:999/slip44:2457', // HyperEVM - Native symbol: HYPE\n 'eip155:1088': 'eip155:1088/erc20:0xdeaddeaddeaddeaddeaddeaddeaddeaddead0000', // Metis Andromeda Mainnet (Ethereum L2) - Native symbol: METIS\n 'eip155:1101': 'eip155:1101/slip44:60', // Polygon zkEVM mainnet - Native symbol: ETH\n 'eip155:1284': 'eip155:1284/slip44:1284', // Moonbeam - Native symbol: GLMR\n 'eip155:1285': 'eip155:1285/slip44:1285', // Moonriver - Native symbol: MOVR\n 'eip155:1329': 'eip155:1329/slip44:19000118', // Sei Mainnet - Native symbol: SEI\n 'eip155:1776': 'eip155:1776/slip44:22000119', // Injective Mainnet - Native symbol: INJ\n 'eip155:1868': 'eip155:1868/erc20:0x0000000000000000000000000000000000000000', // Soneium - Native symbol: ETH\n 'eip155:2525': 'eip155:2525/erc20:0x0000000000000000000000000000000000000000', // inEVM Mainnet - Native symbol: INV\n 'eip155:2741': 'eip155:2741/erc20:0x0000000000000000000000000000000000000000', // Abstract - Native symbol: ETH\n 'eip155:4217': 'eip155:4217/slip44:60', // Tempo Mainnet - No native asset\n 'eip155:4326': 'eip155:4326/erc20:0x0000000000000000000000000000000000000000', // MegaETH Mainnet - Native symbol: ETH\n 'eip155:5000': 'eip155:5000/erc20:0xdeaddeaddeaddeaddeaddeaddeaddeaddead0000', // Mantle - Native symbol: MNT\n 'eip155:5031': 'eip155:5031/slip44:5031', // Somnia Mainnet - Native symbol: SOMI\n 'eip155:5042': 'eip155:5042/slip44:5042', // Arc - Native symbol: USDC\n 'eip155:7000': 'eip155:7000/slip44:7000', // ZetaChain - Native symbol: ZETA\n 'eip155:8453': 'eip155:8453/slip44:60', // Base - Native symbol: ETH\n 'eip155:4663': 'eip155:4663/slip44:60', // Robinhood Chain - Native symbol: ETH\n 'eip155:9745': 'eip155:9745/erc20:0x0000000000000000000000000000000000000000', // Plasma mainnet - native symbol: XPL\n 'eip155:10000': 'eip155:10000/slip44:145', // Smart Bitcoin Cash - Native symbol: BCH\n 'eip155:33139':\n 'eip155:33139/erc20:0x0000000000000000000000000000000000000000', // Apechain Mainnet - Native symbol: APE\n 'eip155:41923':\n 'eip155:41923/erc20:0x0000000000000000000000000000000000000000', // EDU Chain - Native symbol: EDU\n 'eip155:42161': 'eip155:42161/slip44:60', // Arbitrum One - Native symbol: ETH\n 'eip155:42220': 'eip155:42220/slip44:52752', // Celo Mainnet - Native symbol: CELO\n 'eip155:42262': 'eip155:42262/slip44:474', // Oasis Emerald - Native symbol: ROSE\n 'eip155:42431': 'eip155:42431/slip44:60', // Tempo Testnet Moderato - No native asset\n 'eip155:42793':\n 'eip155:42793/erc20:0x0000000000000000000000000000000000000000', // Etherlink - Native symbol: XTZ (Tezos L2)\n 'eip155:43111':\n 'eip155:43111/erc20:0x0000000000000000000000000000000000000000', // Hemi - Native symbol: ETH\n 'eip155:43114': 'eip155:43114/slip44:9005', // Avalanche C-Chain - Native symbol: AVAX\n 'eip155:57073': 'eip155:57073/slip44:60', // Ink Mainnet - Native symbol: ETH\n 'eip155:59144': 'eip155:59144/slip44:60', // Linea Mainnet - Native symbol: ETH\n 'eip155:60808':\n 'eip155:60808/erc20:0x0000000000000000000000000000000000000000', // BOB - Native symbol: ETH\n 'eip155:68414':\n 'eip155:68414/erc20:0x0000000000000000000000000000000000000000', // MapleStory Universe - no slip44\n 'eip155:73115':\n 'eip155:73115/erc20:0x0000000000000000000000000000000000000000', // ICB Network - Native symbol: ICBX\n 'eip155:80094':\n 'eip155:80094/erc20:0x0000000000000000000000000000000000000000', // Berachain - Native symbol: Bera\n 'eip155:81457': 'eip155:81457/slip44:60', // Blast Mainnet - Native symbol: ETH\n 'eip155:88888':\n 'eip155:88888/erc20:0x0000000000000000000000000000000000000000', // Chiliz Chain - Native symbol: CHZ\n 'eip155:97741':\n 'eip155:97741/erc20:0x0000000000000000000000000000000000000000', // Pepe Unchained Mainnet - Native symbol: PEPU\n 'eip155:98866':\n 'eip155:98866/erc20:0x0000000000000000000000000000000000000000', // Plume Mainnet - Native symbol: Plume\n 'eip155:167000': 'eip155:167000/slip44:60', // Taiko Mainnet - Native symbol: ETH\n 'eip155:333999': 'eip155:333999/slip44:1997', // Polis Mainnet - Native symbol: POLIS\n 'eip155:534352': 'eip155:534352/slip44:60', // Scroll Mainnet - Native symbol: ETH\n 'eip155:747474':\n 'eip155:747474/erc20:0x0000000000000000000000000000000000000000', // katana - Native symbol: ETH\n 'eip155:984122':\n 'eip155:984122/erc20:0x0000000000000000000000000000000000000000', // Forma - Native symbol: TIA (Celestia)\n 'eip155:1440000':\n 'eip155:1440000/erc20:0x0000000000000000000000000000000000000000', // xrpl-evm - native symbol: XRP\n 'eip155:1313161554': 'eip155:1313161554/slip44:60', // Aurora Mainnet (Ethereum L2 on NEAR) - Native symbol: ETH\n 'eip155:1666600000': 'eip155:1666600000/slip44:1023', // Harmony Mainnet Shard 0 - Native symbol: ONE\n 'eip155:16661': 'eip155:16661/slip44:16661', // 0G Chain - Native symbol: 0G\n 'bip122:000000000019d6689c085ae165831e93':\n 'bip122:000000000019d6689c085ae165831e93/slip44:0', // Bitcoin Mainnet - Native symbol: BTC\n 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp':\n 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp/slip44:501', // Solana Mainnet - Native symbol: SOL\n 'solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z':\n 'solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z/slip44:501', // Solana Testnet - Native symbol: SOL\n 'solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1':\n 'solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1/slip44:501', // Solana Devnet - Native symbol: SOL\n 'stellar:pubnet': 'stellar:pubnet/slip44:148', // Stellar Pubnet - Native symbol: XLM\n 'stellar:testnet': 'stellar:testnet/slip44:148', // Stellar Testnet - Native symbol: XLM\n 'tron:728126428': 'tron:728126428/slip44:195', // Tron Mainnet - Native symbol: TRX\n 'tron:3448148188': 'tron:3448148188/slip44:195', // Tron Nile - Native symbol: TRX\n 'tron:2494104990': 'tron:2494104990/slip44:195', // Tron Shasta - Native symbol: TRX\n};\n\nconst NATIVE_ASSET_IDS = new Set(\n Object.values(NATIVE_ASSETS).map((assetId) =>\n normalizeAssetId(assetId).toLowerCase(),\n ),\n);\n\n/**\n * Whether `assetId` is the native asset for a chain in {@link NATIVE_ASSETS}.\n * ERC-20 addresses are compared in checksummed form.\n *\n * @param assetId - CAIP-19 asset ID to check.\n * @returns True when the ID matches a seeded native asset.\n */\nexport function isNativeAssetId(assetId: Caip19AssetId): boolean {\n try {\n return NATIVE_ASSET_IDS.has(normalizeAssetId(assetId).toLowerCase());\n } catch {\n return false;\n }\n}\n\n/**\n * Builds a native asset map from {@link NATIVE_ASSETS}, normalizing each\n * CAIP-19 ID (ERC-20 addresses become EIP-55 checksummed).\n *\n * @returns A record mapping CAIP-2 chain IDs to their CAIP-19 native asset IDs.\n */\nexport function buildNativeAssetsFromConstant(): Record<\n ChainId,\n Caip19AssetId\n> {\n const nativeAssetsMap: Record<ChainId, Caip19AssetId> = {};\n for (const [chainId, nativeAssetId] of Object.entries(NATIVE_ASSETS)) {\n nativeAssetsMap[chainId as ChainId] = normalizeAssetId(nativeAssetId);\n }\n return nativeAssetsMap;\n}\n\n/**\n * Fetches chain data from chainid.network and merges it with the seed\n * native asset map built from {@link buildNativeAssetsFromConstant}.\n *\n * Remote entries only fill gaps — chains already present in the seed map\n * are never overwritten. Invalid entries (missing/negative chainId or slip44)\n * are silently skipped.\n *\n * @returns The merged native asset map.\n */\nexport async function buildNativeAssetsFromApi(): Promise<\n Record<ChainId, Caip19AssetId>\n> {\n const nativeAssetsMap = buildNativeAssetsFromConstant();\n\n try {\n const chains: ChainIdNetworkEntry[] | undefined =\n await fetchWithErrorHandling({\n url: CHAINID_NETWORK_URL,\n timeout: 10_000,\n });\n\n if (chains && Array.isArray(chains)) {\n for (const chain of chains) {\n if (\n !chain.chainId ||\n !chain.slip44 ||\n !Number.isInteger(chain.chainId) ||\n chain.chainId < 1 ||\n !Number.isInteger(chain.slip44) ||\n chain.slip44 < 1\n ) {\n continue;\n }\n\n const caipChainId = `eip155:${chain.chainId}` as ChainId;\n if (!nativeAssetsMap[caipChainId]) {\n nativeAssetsMap[caipChainId] =\n `eip155:${chain.chainId}/slip44:${chain.slip44}`;\n }\n }\n }\n } catch {\n // Non-fatal: caller should fall back to the seed map.\n }\n\n return nativeAssetsMap;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"native-assets.js","sourceRoot":"","sources":["../../src/utils/native-assets.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AAGpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD,MAAM,mBAAmB,GAAG,qCAAqC,CAAC;AAOlE;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,aAAa,GAA6C;IACrE,UAAU,EAAE,oBAAoB,EAAE,wCAAwC;IAC1E,WAAW,EAAE,qBAAqB,EAAE,kCAAkC;IACtE,WAAW,EAAE,sBAAsB,EAAE,sCAAsC;IAC3E,WAAW,EAAE,sBAAsB,EAAE,0CAA0C;IAC/E,WAAW,EAAE,4DAA4D,EAAE,6BAA6B;IACxG,WAAW,EAAE,4DAA4D,EAAE,mCAAmC;IAC9G,WAAW,EAAE,sBAAsB,EAAE,+CAA+C;IACpF,WAAW,EAAE,qBAAqB,EAAE,uCAAuC;IAC3E,WAAW,EAAE,wBAAwB,EAA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IAED,OAAO,eAAe,CAAC;AACzB,CAAC","sourcesContent":["import { fetchWithErrorHandling } from '@metamask/controller-utils';\n\nimport type { Caip19AssetId, ChainId } from '../types.js';\nimport { normalizeAssetId } from './normalizeAssetId.js';\n\nconst CHAINID_NETWORK_URL = 'https://chainid.network/chains.json';\n\ntype ChainIdNetworkEntry = {\n chainId: number;\n slip44?: number;\n};\n\n/**\n * Seed native CAIP-19 asset IDs, keyed by CAIP-2 chain ID.\n *\n * Covers Price API v3/spot-prices EVM natives plus the Bitcoin, Solana,\n * Stellar and Tron natives this controller ingests. chainid.network only\n * fills extra `eip155` gaps, so without the non-EVM rows an account holding\n * nothing on those networks gets an empty list instead of BTC/SOL/XLM/TRX\n * at 0.\n *\n * Price API v3/spot-prices chains only for EVM — verify support before adding:\n * https://github.com/consensys-vertical-apps/va-mmcx-price-api/blob/main/src/constants/slip44.ts\n * Include chain name + native symbol. Keep sorted by chain ID.\n */\nexport const NATIVE_ASSETS: Readonly<Record<ChainId, Caip19AssetId>> = {\n 'eip155:1': 'eip155:1/slip44:60', // Ethereum Mainnet - Native symbol: ETH\n 'eip155:10': 'eip155:10/slip44:60', // OP Mainnet - Native symbol: ETH\n 'eip155:25': 'eip155:25/slip44:394', // Cronos Mainnet - Native symbol: CRO\n 'eip155:30': 'eip155:30/slip44:137', // Rootstock Mainnet - Native symbol: RBTC\n 'eip155:42': 'eip155:42/erc20:0x0000000000000000000000000000000000000000', // Lukso - native symbol: LYX\n 'eip155:50': 'eip155:50/erc20:0x0000000000000000000000000000000000000000', // xdc-network - native symbol: XDC\n 'eip155:56': 'eip155:56/slip44:714', // BNB Smart Chain Mainnet - Native symbol: BNB\n 'eip155:57': 'eip155:57/slip44:57', // Syscoin Mainnet - Native symbol: SYS\n 'eip155:82': 'eip155:82/slip44:18000', // Meter Mainnet - Native symbol: MTR\n 'eip155:88': 'eip155:88/slip44:889', // TomoChain - Native symbol: TOMO\n 'eip155:100': 'eip155:100/erc20:0x0000000000000000000000000000000000000000', // Gnosis (formerly xDAI Chain) - Native symbol: xDAI\n 'eip155:106': 'eip155:106/slip44:5655640', // Velas EVM Mainnet - Native symbol: VLX\n 'eip155:122': 'eip155:122/erc20:0x0000000000000000000000000000000000000000', // Fuse Mainnet - Native symbol: FUSE\n 'eip155:128': 'eip155:128/slip44:1010', // Huobi ECO Chain Mainnet - Native symbol: HT\n 'eip155:137': 'eip155:137/slip44:966', // Polygon Mainnet - Native symbol: POL\n 'eip155:143': 'eip155:143/slip44:268435779', // Monad Mainnet - Native symbol: MON\n 'eip155:146': 'eip155:146/slip44:10007', // Sonic Mainnet - Native symbol: S\n 'eip155:166': 'eip155:166/slip44:11111166', // Nomina - Native symbol: NOM (no registered slip44; synthetic 11111<chainId>)\n 'eip155:196': 'eip155:196/erc20:0x0000000000000000000000000000000000000000', // X Layer Mainnet - Native symbol: OKB\n 'eip155:232': 'eip155:232/erc20:0x0000000000000000000000000000000000000000', // Lens Mainnet - Native symbol: GHO\n 'eip155:250': 'eip155:250/slip44:1007', // Fantom Opera - Native symbol: FTM\n 'eip155:252': 'eip155:252/erc20:0x0000000000000000000000000000000000000000', // Fraxtal - native symbol: FRAX\n 'eip155:288': 'eip155:288/slip44:60', // Boba Network (Ethereum L2) - Native symbol: ETH\n 'eip155:321': 'eip155:321/slip44:641', // KCC Mainnet - Native symbol: KCS\n 'eip155:324': 'eip155:324/slip44:60', // zkSync Era Mainnet (Ethereum L2) - Native symbol: ETH\n 'eip155:336': 'eip155:336/slip44:809', // Shiden - Native symbol: SDN\n 'eip155:361': 'eip155:361/slip44:589', // Theta Mainnet - Native symbol: TFUEL\n 'eip155:698': 'eip155:698/slip44:714', // Matchain - Native symbol: BNB\n 'eip155:747': 'eip155:747/slip44:539', // Flow evm - Native symbol: Flow\n 'eip155:988': 'eip155:988/erc20:0x0000000000000000000000000000000000000000', // Stable - Native symbol: USDT0\n 'eip155:999': 'eip155:999/slip44:2457', // HyperEVM - Native symbol: HYPE\n 'eip155:1088': 'eip155:1088/erc20:0xdeaddeaddeaddeaddeaddeaddeaddeaddead0000', // Metis Andromeda Mainnet (Ethereum L2) - Native symbol: METIS\n 'eip155:1101': 'eip155:1101/slip44:60', // Polygon zkEVM mainnet - Native symbol: ETH\n 'eip155:1284': 'eip155:1284/slip44:1284', // Moonbeam - Native symbol: GLMR\n 'eip155:1285': 'eip155:1285/slip44:1285', // Moonriver - Native symbol: MOVR\n 'eip155:1329': 'eip155:1329/slip44:19000118', // Sei Mainnet - Native symbol: SEI\n 'eip155:1776': 'eip155:1776/slip44:22000119', // Injective Mainnet - Native symbol: INJ\n 'eip155:1868': 'eip155:1868/erc20:0x0000000000000000000000000000000000000000', // Soneium - Native symbol: ETH\n 'eip155:2525': 'eip155:2525/erc20:0x0000000000000000000000000000000000000000', // inEVM Mainnet - Native symbol: INV\n 'eip155:2741': 'eip155:2741/erc20:0x0000000000000000000000000000000000000000', // Abstract - Native symbol: ETH\n 'eip155:4217': 'eip155:4217/slip44:60', // Tempo Mainnet - No native asset\n 'eip155:4326': 'eip155:4326/erc20:0x0000000000000000000000000000000000000000', // MegaETH Mainnet - Native symbol: ETH\n 'eip155:5000': 'eip155:5000/erc20:0xdeaddeaddeaddeaddeaddeaddeaddeaddead0000', // Mantle - Native symbol: MNT\n 'eip155:5031': 'eip155:5031/slip44:5031', // Somnia Mainnet - Native symbol: SOMI\n 'eip155:5042': 'eip155:5042/slip44:5042', // Arc - Native symbol: USDC\n 'eip155:7000': 'eip155:7000/slip44:7000', // ZetaChain - Native symbol: ZETA\n 'eip155:8453': 'eip155:8453/slip44:60', // Base - Native symbol: ETH\n 'eip155:4663': 'eip155:4663/slip44:60', // Robinhood Chain - Native symbol: ETH\n 'eip155:9745': 'eip155:9745/erc20:0x0000000000000000000000000000000000000000', // Plasma mainnet - native symbol: XPL\n 'eip155:10000': 'eip155:10000/slip44:145', // Smart Bitcoin Cash - Native symbol: BCH\n 'eip155:33139':\n 'eip155:33139/erc20:0x0000000000000000000000000000000000000000', // Apechain Mainnet - Native symbol: APE\n 'eip155:41923':\n 'eip155:41923/erc20:0x0000000000000000000000000000000000000000', // EDU Chain - Native symbol: EDU\n 'eip155:42161': 'eip155:42161/slip44:60', // Arbitrum One - Native symbol: ETH\n 'eip155:42220': 'eip155:42220/slip44:52752', // Celo Mainnet - Native symbol: CELO\n 'eip155:42262': 'eip155:42262/slip44:474', // Oasis Emerald - Native symbol: ROSE\n 'eip155:42431': 'eip155:42431/slip44:60', // Tempo Testnet Moderato - No native asset\n 'eip155:42793':\n 'eip155:42793/erc20:0x0000000000000000000000000000000000000000', // Etherlink - Native symbol: XTZ (Tezos L2)\n 'eip155:43111':\n 'eip155:43111/erc20:0x0000000000000000000000000000000000000000', // Hemi - Native symbol: ETH\n 'eip155:43114': 'eip155:43114/slip44:9005', // Avalanche C-Chain - Native symbol: AVAX\n 'eip155:57073': 'eip155:57073/slip44:60', // Ink Mainnet - Native symbol: ETH\n 'eip155:59144': 'eip155:59144/slip44:60', // Linea Mainnet - Native symbol: ETH\n 'eip155:60808':\n 'eip155:60808/erc20:0x0000000000000000000000000000000000000000', // BOB - Native symbol: ETH\n 'eip155:68414':\n 'eip155:68414/erc20:0x0000000000000000000000000000000000000000', // MapleStory Universe - no slip44\n 'eip155:73115':\n 'eip155:73115/erc20:0x0000000000000000000000000000000000000000', // ICB Network - Native symbol: ICBX\n 'eip155:80094':\n 'eip155:80094/erc20:0x0000000000000000000000000000000000000000', // Berachain - Native symbol: Bera\n 'eip155:88888':\n 'eip155:88888/erc20:0x0000000000000000000000000000000000000000', // Chiliz Chain - Native symbol: CHZ\n 'eip155:97741':\n 'eip155:97741/erc20:0x0000000000000000000000000000000000000000', // Pepe Unchained Mainnet - Native symbol: PEPU\n 'eip155:98866':\n 'eip155:98866/erc20:0x0000000000000000000000000000000000000000', // Plume Mainnet - Native symbol: Plume\n 'eip155:167000': 'eip155:167000/slip44:60', // Taiko Mainnet - Native symbol: ETH\n 'eip155:333999': 'eip155:333999/slip44:1997', // Polis Mainnet - Native symbol: POLIS\n 'eip155:534352': 'eip155:534352/slip44:60', // Scroll Mainnet - Native symbol: ETH\n 'eip155:747474':\n 'eip155:747474/erc20:0x0000000000000000000000000000000000000000', // katana - Native symbol: ETH\n 'eip155:984122':\n 'eip155:984122/erc20:0x0000000000000000000000000000000000000000', // Forma - Native symbol: TIA (Celestia)\n 'eip155:1440000':\n 'eip155:1440000/erc20:0x0000000000000000000000000000000000000000', // xrpl-evm - native symbol: XRP\n 'eip155:1313161554': 'eip155:1313161554/slip44:60', // Aurora Mainnet (Ethereum L2 on NEAR) - Native symbol: ETH\n 'eip155:1666600000': 'eip155:1666600000/slip44:1023', // Harmony Mainnet Shard 0 - Native symbol: ONE\n 'eip155:16661': 'eip155:16661/slip44:16661', // 0G Chain - Native symbol: 0G\n 'bip122:000000000019d6689c085ae165831e93':\n 'bip122:000000000019d6689c085ae165831e93/slip44:0', // Bitcoin Mainnet - Native symbol: BTC\n 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp':\n 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp/slip44:501', // Solana Mainnet - Native symbol: SOL\n 'solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z':\n 'solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z/slip44:501', // Solana Testnet - Native symbol: SOL\n 'solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1':\n 'solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1/slip44:501', // Solana Devnet - Native symbol: SOL\n 'stellar:pubnet': 'stellar:pubnet/slip44:148', // Stellar Pubnet - Native symbol: XLM\n 'stellar:testnet': 'stellar:testnet/slip44:148', // Stellar Testnet - Native symbol: XLM\n 'tron:728126428': 'tron:728126428/slip44:195', // Tron Mainnet - Native symbol: TRX\n 'tron:3448148188': 'tron:3448148188/slip44:195', // Tron Nile - Native symbol: TRX\n 'tron:2494104990': 'tron:2494104990/slip44:195', // Tron Shasta - Native symbol: TRX\n};\n\nconst NATIVE_ASSET_IDS = new Set(\n Object.values(NATIVE_ASSETS).map((assetId) =>\n normalizeAssetId(assetId).toLowerCase(),\n ),\n);\n\n/**\n * Whether `assetId` is the native asset for a chain in {@link NATIVE_ASSETS}.\n * ERC-20 addresses are compared in checksummed form.\n *\n * @param assetId - CAIP-19 asset ID to check.\n * @returns True when the ID matches a seeded native asset.\n */\nexport function isNativeAssetId(assetId: Caip19AssetId): boolean {\n try {\n return NATIVE_ASSET_IDS.has(normalizeAssetId(assetId).toLowerCase());\n } catch {\n return false;\n }\n}\n\n/**\n * Builds a native asset map from {@link NATIVE_ASSETS}, normalizing each\n * CAIP-19 ID (ERC-20 addresses become EIP-55 checksummed).\n *\n * @returns A record mapping CAIP-2 chain IDs to their CAIP-19 native asset IDs.\n */\nexport function buildNativeAssetsFromConstant(): Record<\n ChainId,\n Caip19AssetId\n> {\n const nativeAssetsMap: Record<ChainId, Caip19AssetId> = {};\n for (const [chainId, nativeAssetId] of Object.entries(NATIVE_ASSETS)) {\n nativeAssetsMap[chainId as ChainId] = normalizeAssetId(nativeAssetId);\n }\n return nativeAssetsMap;\n}\n\n/**\n * Fetches chain data from chainid.network and merges it with the seed\n * native asset map built from {@link buildNativeAssetsFromConstant}.\n *\n * Remote entries only fill gaps — chains already present in the seed map\n * are never overwritten. Invalid entries (missing/negative chainId or slip44)\n * are silently skipped.\n *\n * @returns The merged native asset map.\n */\nexport async function buildNativeAssetsFromApi(): Promise<\n Record<ChainId, Caip19AssetId>\n> {\n const nativeAssetsMap = buildNativeAssetsFromConstant();\n\n try {\n const chains: ChainIdNetworkEntry[] | undefined =\n await fetchWithErrorHandling({\n url: CHAINID_NETWORK_URL,\n timeout: 10_000,\n });\n\n if (chains && Array.isArray(chains)) {\n for (const chain of chains) {\n if (\n !chain.chainId ||\n !chain.slip44 ||\n !Number.isInteger(chain.chainId) ||\n chain.chainId < 1 ||\n !Number.isInteger(chain.slip44) ||\n chain.slip44 < 1\n ) {\n continue;\n }\n\n const caipChainId = `eip155:${chain.chainId}` as ChainId;\n if (!nativeAssetsMap[caipChainId]) {\n nativeAssetsMap[caipChainId] =\n `eip155:${chain.chainId}/slip44:${chain.slip44}`;\n }\n }\n }\n } catch {\n // Non-fatal: caller should fall back to the seed map.\n }\n\n return nativeAssetsMap;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask-previews/assets-controller",
|
|
3
|
-
"version": "20.4.1-preview-
|
|
3
|
+
"version": "20.4.1-preview-e9ac9ffe1",
|
|
4
4
|
"description": "Tracks assets balances/prices and handles token detection across all digital assets",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Ethereum",
|
|
@@ -80,7 +80,7 @@
|
|
|
80
80
|
"@metamask/remote-feature-flag-controller": "^7.0.0",
|
|
81
81
|
"@metamask/snaps-controllers": "^19.0.1",
|
|
82
82
|
"@metamask/snaps-utils": "^12.1.2",
|
|
83
|
-
"@metamask/transaction-controller": "^74.
|
|
83
|
+
"@metamask/transaction-controller": "^74.2.0",
|
|
84
84
|
"@metamask/utils": "^12.0.2",
|
|
85
85
|
"async-mutex": "^0.5.0",
|
|
86
86
|
"bignumber.js": "^9.1.2",
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import type { AccountId, AssetsControllerState, Caip19AssetId, Middleware } from '../types.js';
|
|
2
|
-
export type CustomAssetGraduationMiddlewareOptions = {
|
|
3
|
-
getSelectedAccountId: () => AccountId | undefined;
|
|
4
|
-
removeCustomAsset: (accountId: AccountId, assetId: Caip19AssetId) => void;
|
|
5
|
-
/** Current AssetsController state. Used to read customAssets for the selected account. */
|
|
6
|
-
getAssetsState: () => AssetsControllerState;
|
|
7
|
-
};
|
|
8
|
-
/**
|
|
9
|
-
* CustomAssetGraduationMiddleware removes EVM assets from `customAssets` when
|
|
10
|
-
* an upstream balance source (AccountsAPI / Websocket) reports a non-zero
|
|
11
|
-
* balance for them. Once a detector sees the asset with a real balance, it
|
|
12
|
-
* no longer needs to be tracked as "custom" — the regular detection flow
|
|
13
|
-
* will keep it fresh.
|
|
14
|
-
*
|
|
15
|
-
* Rules:
|
|
16
|
-
* - Only the selected account's custom assets are considered. Switching the
|
|
17
|
-
* selected account triggers a fresh fetch, which re-runs graduation
|
|
18
|
-
* against the new account's balances.
|
|
19
|
-
* - Only EVM (CAIP-2 namespace `eip155`) assets graduate. Non-EVM custom
|
|
20
|
-
* assets (Solana, BTC, Tron, etc. — served by Snap data sources) are left
|
|
21
|
-
* alone.
|
|
22
|
-
* - Only positive balances graduate. A zero balance from AccountsAPI means
|
|
23
|
-
* the API knows about the token but the user does not currently hold it;
|
|
24
|
-
* keeping it in `customAssets` ensures RPC keeps polling so a future
|
|
25
|
-
* incoming transfer is reflected promptly.
|
|
26
|
-
*/
|
|
27
|
-
export declare class CustomAssetGraduationMiddleware {
|
|
28
|
-
#private;
|
|
29
|
-
readonly name = "CustomAssetGraduationMiddleware";
|
|
30
|
-
constructor(options: CustomAssetGraduationMiddlewareOptions);
|
|
31
|
-
getName(): string;
|
|
32
|
-
get assetsMiddleware(): Middleware;
|
|
33
|
-
}
|
|
34
|
-
//# sourceMappingURL=CustomAssetGraduationMiddleware.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"CustomAssetGraduationMiddleware.d.ts","sourceRoot":"","sources":["../../src/middlewares/CustomAssetGraduationMiddleware.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,SAAS,EAET,qBAAqB,EACrB,aAAa,EACb,UAAU,EACX,MAAM,aAAa,CAAC;AAOrB,MAAM,MAAM,sCAAsC,GAAG;IACnD,oBAAoB,EAAE,MAAM,SAAS,GAAG,SAAS,CAAC;IAClD,iBAAiB,EAAE,CAAC,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,aAAa,KAAK,IAAI,CAAC;IAC1E,0FAA0F;IAC1F,cAAc,EAAE,MAAM,qBAAqB,CAAC;CAC7C,CAAC;AAEF;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,+BAA+B;;IAC1C,QAAQ,CAAC,IAAI,qCAAmB;IAWhC,YAAY,OAAO,EAAE,sCAAsC,EAI1D;IAED,OAAO,IAAI,MAAM,CAEhB;IAED,IAAI,gBAAgB,IAAI,UAAU,CAkDjC;CACF"}
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
import { KnownCaipNamespace } from '@metamask/utils';
|
|
2
|
-
import { projectLogger, createModuleLogger } from '../logger.js';
|
|
3
|
-
import { forDataTypes } from '../types.js';
|
|
4
|
-
import { safeNormalizeAssetId } from '../utils/index.js';
|
|
5
|
-
const CONTROLLER_NAME = 'CustomAssetGraduationMiddleware';
|
|
6
|
-
const log = createModuleLogger(projectLogger, CONTROLLER_NAME);
|
|
7
|
-
/**
|
|
8
|
-
* CustomAssetGraduationMiddleware removes EVM assets from `customAssets` when
|
|
9
|
-
* an upstream balance source (AccountsAPI / Websocket) reports a non-zero
|
|
10
|
-
* balance for them. Once a detector sees the asset with a real balance, it
|
|
11
|
-
* no longer needs to be tracked as "custom" — the regular detection flow
|
|
12
|
-
* will keep it fresh.
|
|
13
|
-
*
|
|
14
|
-
* Rules:
|
|
15
|
-
* - Only the selected account's custom assets are considered. Switching the
|
|
16
|
-
* selected account triggers a fresh fetch, which re-runs graduation
|
|
17
|
-
* against the new account's balances.
|
|
18
|
-
* - Only EVM (CAIP-2 namespace `eip155`) assets graduate. Non-EVM custom
|
|
19
|
-
* assets (Solana, BTC, Tron, etc. — served by Snap data sources) are left
|
|
20
|
-
* alone.
|
|
21
|
-
* - Only positive balances graduate. A zero balance from AccountsAPI means
|
|
22
|
-
* the API knows about the token but the user does not currently hold it;
|
|
23
|
-
* keeping it in `customAssets` ensures RPC keeps polling so a future
|
|
24
|
-
* incoming transfer is reflected promptly.
|
|
25
|
-
*/
|
|
26
|
-
export class CustomAssetGraduationMiddleware {
|
|
27
|
-
name = CONTROLLER_NAME;
|
|
28
|
-
#getSelectedAccountId;
|
|
29
|
-
#removeCustomAsset;
|
|
30
|
-
#getAssetsState;
|
|
31
|
-
constructor(options) {
|
|
32
|
-
this.#getSelectedAccountId = options.getSelectedAccountId;
|
|
33
|
-
this.#removeCustomAsset = options.removeCustomAsset;
|
|
34
|
-
this.#getAssetsState = options.getAssetsState;
|
|
35
|
-
}
|
|
36
|
-
getName() {
|
|
37
|
-
return this.name;
|
|
38
|
-
}
|
|
39
|
-
get assetsMiddleware() {
|
|
40
|
-
return forDataTypes(['balance'], async (ctx, next) => {
|
|
41
|
-
// Inspect the response BEFORE calling next() so we only consider
|
|
42
|
-
// balances populated by upstream middleware (AccountsApi / Websocket /
|
|
43
|
-
// Staked). This middleware is positioned in the pipeline before the
|
|
44
|
-
// RPC fallback — RPC intentionally carries custom assets and must
|
|
45
|
-
// never trigger graduation.
|
|
46
|
-
const accountId = this.#getSelectedAccountId();
|
|
47
|
-
if (!accountId) {
|
|
48
|
-
return next(ctx);
|
|
49
|
-
}
|
|
50
|
-
const state = this.#getAssetsState();
|
|
51
|
-
const customForAccount = state.customAssets?.[accountId] ?? [];
|
|
52
|
-
if (customForAccount.length === 0) {
|
|
53
|
-
return next(ctx);
|
|
54
|
-
}
|
|
55
|
-
const returnedBalances = ctx.response.assetsBalance?.[accountId] ?? {};
|
|
56
|
-
const returnedAssetIds = Object.keys(returnedBalances);
|
|
57
|
-
if (returnedAssetIds.length === 0) {
|
|
58
|
-
return next(ctx);
|
|
59
|
-
}
|
|
60
|
-
// customAssets state is stored with checksummed/normalized asset IDs.
|
|
61
|
-
// AccountsApiDataSource normalizes its response IDs, but
|
|
62
|
-
// AccountActivityDataSource does not — so we normalize the response
|
|
63
|
-
// side here to make the comparison robust to lower-case addresses
|
|
64
|
-
// delivered over the websocket.
|
|
65
|
-
const customSet = new Set(customForAccount);
|
|
66
|
-
for (const rawAssetId of returnedAssetIds) {
|
|
67
|
-
if (!isEvmAssetId(rawAssetId)) {
|
|
68
|
-
continue;
|
|
69
|
-
}
|
|
70
|
-
if (!hasPositiveBalance(returnedBalances[rawAssetId])) {
|
|
71
|
-
continue;
|
|
72
|
-
}
|
|
73
|
-
const normalizedAssetId = safeNormalizeAssetId(rawAssetId);
|
|
74
|
-
if (!customSet.has(normalizedAssetId)) {
|
|
75
|
-
continue;
|
|
76
|
-
}
|
|
77
|
-
log('Graduating custom asset', {
|
|
78
|
-
accountId,
|
|
79
|
-
assetId: normalizedAssetId,
|
|
80
|
-
});
|
|
81
|
-
this.#removeCustomAsset(accountId, normalizedAssetId);
|
|
82
|
-
}
|
|
83
|
-
return next(ctx);
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Check whether a CAIP-19 asset ID belongs to an EVM chain.
|
|
89
|
-
*
|
|
90
|
-
* @param assetId - The CAIP-19 asset ID to inspect.
|
|
91
|
-
* @returns `true` when the asset's chain namespace is `eip155`.
|
|
92
|
-
*/
|
|
93
|
-
function isEvmAssetId(assetId) {
|
|
94
|
-
// CAIP-19 format: <namespace>:<chainRef>/<assetNamespace>:<assetRef>
|
|
95
|
-
// The chain namespace is always the segment before the first colon.
|
|
96
|
-
const namespace = assetId.split(':')[0];
|
|
97
|
-
return namespace === KnownCaipNamespace.Eip155;
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Whether a balance entry reports a strictly positive amount. AccountsAPI
|
|
101
|
-
* may return zero for tokens it indexes but the user no longer holds; we
|
|
102
|
-
* treat those as non-graduating so RPC keeps polling and surfaces any
|
|
103
|
-
* future incoming transfer immediately.
|
|
104
|
-
*
|
|
105
|
-
* `AssetBalance.amount` is already a human-readable decimal string from
|
|
106
|
-
* both AccountsApi (e.g. "0.283549083429656057") and the websocket data
|
|
107
|
-
* source (which divides by `decimals` before emitting), so a `Number()`
|
|
108
|
-
* sign check is safe: `NaN`, `undefined`, empty strings, and zero all
|
|
109
|
-
* fail the comparison.
|
|
110
|
-
*
|
|
111
|
-
* @param balance - The balance entry from the response.
|
|
112
|
-
* @returns `true` when the balance amount represents a value greater than 0.
|
|
113
|
-
*/
|
|
114
|
-
function hasPositiveBalance(balance) {
|
|
115
|
-
return Number(balance?.amount) > 0;
|
|
116
|
-
}
|
|
117
|
-
//# sourceMappingURL=CustomAssetGraduationMiddleware.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"CustomAssetGraduationMiddleware.js","sourceRoot":"","sources":["../../src/middlewares/CustomAssetGraduationMiddleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAErD,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAQ3C,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAEzD,MAAM,eAAe,GAAG,iCAAiC,CAAC;AAE1D,MAAM,GAAG,GAAG,kBAAkB,CAAC,aAAa,EAAE,eAAe,CAAC,CAAC;AAS/D;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,OAAO,+BAA+B;IACjC,IAAI,GAAG,eAAe,CAAC;IAEvB,qBAAqB,CAA8B;IAEnD,kBAAkB,CAGjB;IAED,eAAe,CAA8B;IAEtD,YAAY,OAA+C;QACzD,IAAI,CAAC,qBAAqB,GAAG,OAAO,CAAC,oBAAoB,CAAC;QAC1D,IAAI,CAAC,kBAAkB,GAAG,OAAO,CAAC,iBAAiB,CAAC;QACpD,IAAI,CAAC,eAAe,GAAG,OAAO,CAAC,cAAc,CAAC;IAChD,CAAC;IAED,OAAO;QACL,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IAED,IAAI,gBAAgB;QAClB,OAAO,YAAY,CAAC,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;YACnD,iEAAiE;YACjE,uEAAuE;YACvE,oEAAoE;YACpE,kEAAkE;YAClE,4BAA4B;YAC5B,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AAE;oBAC7B,SAAS;oBACT,OAAO,EAAE,iBAAiB;iBAC3B,CAAC,CAAC;gBACH,IAAI,CAAC,kBAAkB,CAAC,SAAS,EAAE,iBAAiB,CAAC,CAAC;YACxD,CAAC;YAED,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;QACnB,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAED;;;;;GAKG;AACH,SAAS,YAAY,CAAC,OAAsB;IAC1C,qEAAqE;IACrE,oEAAoE;IACpE,MAAM,SAAS,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IACxC,OAAO,SAAS,KAAK,kBAAkB,CAAC,MAAM,CAAC;AACjD,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,SAAS,kBAAkB,CAAC,OAAiC;IAC3D,OAAO,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC;AACrC,CAAC","sourcesContent":["import { KnownCaipNamespace } from '@metamask/utils';\n\nimport { projectLogger, createModuleLogger } from '../logger.js';\nimport { forDataTypes } from '../types.js';\nimport type {\n AccountId,\n AssetBalance,\n AssetsControllerState,\n Caip19AssetId,\n Middleware,\n} from '../types.js';\nimport { safeNormalizeAssetId } from '../utils/index.js';\n\nconst CONTROLLER_NAME = 'CustomAssetGraduationMiddleware';\n\nconst log = createModuleLogger(projectLogger, CONTROLLER_NAME);\n\nexport type CustomAssetGraduationMiddlewareOptions = {\n getSelectedAccountId: () => AccountId | undefined;\n removeCustomAsset: (accountId: AccountId, assetId: Caip19AssetId) => void;\n /** Current AssetsController state. Used to read customAssets for the selected account. */\n getAssetsState: () => AssetsControllerState;\n};\n\n/**\n * CustomAssetGraduationMiddleware removes EVM assets from `customAssets` when\n * an upstream balance source (AccountsAPI / Websocket) reports a non-zero\n * balance for them. Once a detector sees the asset with a real balance, it\n * no longer needs to be tracked as \"custom\" — the regular detection flow\n * will keep it fresh.\n *\n * Rules:\n * - Only the selected account's custom assets are considered. Switching the\n * selected account triggers a fresh fetch, which re-runs graduation\n * against the new account's balances.\n * - Only EVM (CAIP-2 namespace `eip155`) assets graduate. Non-EVM custom\n * assets (Solana, BTC, Tron, etc. — served by Snap data sources) are left\n * alone.\n * - Only positive balances graduate. A zero balance from AccountsAPI means\n * the API knows about the token but the user does not currently hold it;\n * keeping it in `customAssets` ensures RPC keeps polling so a future\n * incoming transfer is reflected promptly.\n */\nexport class CustomAssetGraduationMiddleware {\n readonly name = CONTROLLER_NAME;\n\n readonly #getSelectedAccountId: () => AccountId | undefined;\n\n readonly #removeCustomAsset: (\n accountId: AccountId,\n assetId: Caip19AssetId,\n ) => void;\n\n readonly #getAssetsState: () => AssetsControllerState;\n\n constructor(options: CustomAssetGraduationMiddlewareOptions) {\n this.#getSelectedAccountId = options.getSelectedAccountId;\n this.#removeCustomAsset = options.removeCustomAsset;\n this.#getAssetsState = options.getAssetsState;\n }\n\n getName(): string {\n return this.name;\n }\n\n get assetsMiddleware(): Middleware {\n return forDataTypes(['balance'], async (ctx, next) => {\n // Inspect the response BEFORE calling next() so we only consider\n // balances populated by upstream middleware (AccountsApi / Websocket /\n // Staked). This middleware is positioned in the pipeline before the\n // RPC fallback — RPC intentionally carries custom assets and must\n // never trigger graduation.\n const accountId = this.#getSelectedAccountId();\n if (!accountId) {\n return next(ctx);\n }\n\n const state = this.#getAssetsState();\n const customForAccount = state.customAssets?.[accountId] ?? [];\n if (customForAccount.length === 0) {\n return next(ctx);\n }\n\n const returnedBalances = ctx.response.assetsBalance?.[accountId] ?? {};\n const returnedAssetIds = Object.keys(returnedBalances) as Caip19AssetId[];\n if (returnedAssetIds.length === 0) {\n return next(ctx);\n }\n\n // customAssets state is stored with checksummed/normalized asset IDs.\n // AccountsApiDataSource normalizes its response IDs, but\n // AccountActivityDataSource does not — so we normalize the response\n // side here to make the comparison robust to lower-case addresses\n // delivered over the websocket.\n const customSet = new Set(customForAccount);\n for (const rawAssetId of returnedAssetIds) {\n if (!isEvmAssetId(rawAssetId)) {\n continue;\n }\n if (!hasPositiveBalance(returnedBalances[rawAssetId])) {\n continue;\n }\n const normalizedAssetId = safeNormalizeAssetId(rawAssetId);\n if (!customSet.has(normalizedAssetId)) {\n continue;\n }\n log('Graduating custom asset', {\n accountId,\n assetId: normalizedAssetId,\n });\n this.#removeCustomAsset(accountId, normalizedAssetId);\n }\n\n return next(ctx);\n });\n }\n}\n\n/**\n * Check whether a CAIP-19 asset ID belongs to an EVM chain.\n *\n * @param assetId - The CAIP-19 asset ID to inspect.\n * @returns `true` when the asset's chain namespace is `eip155`.\n */\nfunction isEvmAssetId(assetId: Caip19AssetId): boolean {\n // CAIP-19 format: <namespace>:<chainRef>/<assetNamespace>:<assetRef>\n // The chain namespace is always the segment before the first colon.\n const namespace = assetId.split(':')[0];\n return namespace === KnownCaipNamespace.Eip155;\n}\n\n/**\n * Whether a balance entry reports a strictly positive amount. AccountsAPI\n * may return zero for tokens it indexes but the user no longer holds; we\n * treat those as non-graduating so RPC keeps polling and surfaces any\n * future incoming transfer immediately.\n *\n * `AssetBalance.amount` is already a human-readable decimal string from\n * both AccountsApi (e.g. \"0.283549083429656057\") and the websocket data\n * source (which divides by `decimals` before emitting), so a `Number()`\n * sign check is safe: `NaN`, `undefined`, empty strings, and zero all\n * fail the comparison.\n *\n * @param balance - The balance entry from the response.\n * @returns `true` when the balance amount represents a value greater than 0.\n */\nfunction hasPositiveBalance(balance: AssetBalance | undefined): boolean {\n return Number(balance?.amount) > 0;\n}\n"]}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import type { Caip19AssetId, ChainId } from '../types.js';
|
|
2
|
-
/**
|
|
3
|
-
* Inputs needed to decide whether `RpcDataSource` should run a supplemental
|
|
4
|
-
* `customAssetsOnly` subscription. All inputs are pre-computed by the caller
|
|
5
|
-
* (controller) so this helper is fully pure and deterministic.
|
|
6
|
-
*/
|
|
7
|
-
export type RpcCustomAssetsSupplementInput = {
|
|
8
|
-
/** Selected account IDs being considered for subscription. */
|
|
9
|
-
accountIds: string[];
|
|
10
|
-
/** `state.customAssets` slice — accountId → CAIP-19 asset IDs. */
|
|
11
|
-
customAssetsByAccount: Record<string, Caip19AssetId[]>;
|
|
12
|
-
/** Chains the regular RPC subscription already covers. */
|
|
13
|
-
rpcAssignedChains: Set<ChainId>;
|
|
14
|
-
/** Chains the RPC data source can serve (its current activeChains). */
|
|
15
|
-
rpcAvailableChains: Set<ChainId>;
|
|
16
|
-
/**
|
|
17
|
-
* Chains that are currently enabled for at least one selected account
|
|
18
|
-
* (i.e. keys of the controller's chainToAccounts map).
|
|
19
|
-
*/
|
|
20
|
-
enabledChains: Set<ChainId>;
|
|
21
|
-
};
|
|
22
|
-
/**
|
|
23
|
-
* The decision output: which chains and accounts need a supplemental
|
|
24
|
-
* `customAssetsOnly` RPC subscription.
|
|
25
|
-
*/
|
|
26
|
-
export type RpcCustomAssetsSupplementResult = {
|
|
27
|
-
/** Chains that need a supplemental customAssetsOnly RPC subscription. */
|
|
28
|
-
chains: ChainId[];
|
|
29
|
-
/** Accounts that own at least one customAsset on a supplemental chain. */
|
|
30
|
-
accountIds: Set<string>;
|
|
31
|
-
};
|
|
32
|
-
/**
|
|
33
|
-
* Decide which chains require a supplemental `customAssetsOnly` RPC
|
|
34
|
-
* subscription so that user-imported customAssets are **always** polled by
|
|
35
|
-
* RPC — even when AccountsApi or the websocket data source has already
|
|
36
|
-
* claimed the chain in the regular handoff.
|
|
37
|
-
*
|
|
38
|
-
* RPC is the sole balance fetcher for customAssets:
|
|
39
|
-
* - AccountsApi indexes a curated token list and may return zero (or no
|
|
40
|
-
* entry at all) for a user-imported token, even on supported chains.
|
|
41
|
-
* - The websocket data source is push-only: it relays balance deltas from
|
|
42
|
-
* transactions, so a user who never transacts won't see balance updates.
|
|
43
|
-
*
|
|
44
|
-
* To guarantee freshness, we subscribe RPC in `customAssetsOnly` mode on
|
|
45
|
-
* any chain that:
|
|
46
|
-
* 1. has at least one selected account with a customAsset there;
|
|
47
|
-
* 2. is supported by the RPC data source;
|
|
48
|
-
* 3. is **not** already covered by the regular RPC subscription
|
|
49
|
-
* (`rpcAssignedChains`) — otherwise customAssets are picked up there;
|
|
50
|
-
* 4. is currently enabled (in `chainToAccounts`); polling a disabled
|
|
51
|
-
* chain wastes resources because the user can't see its balances.
|
|
52
|
-
*
|
|
53
|
-
* Malformed asset IDs are silently skipped — they can't be parsed into a
|
|
54
|
-
* chain anyway and shouldn't crash the subscription pipeline.
|
|
55
|
-
*
|
|
56
|
-
* @param input - Decision inputs.
|
|
57
|
-
* @returns Chains and account IDs that require supplemental subscription.
|
|
58
|
-
*/
|
|
59
|
-
export declare function pickRpcCustomAssetsSupplement(input: RpcCustomAssetsSupplementInput): RpcCustomAssetsSupplementResult;
|
|
60
|
-
//# sourceMappingURL=customAssetsRpcSupplement.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"customAssetsRpcSupplement.d.ts","sourceRoot":"","sources":["../../src/utils/customAssetsRpcSupplement.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAE1D;;;;GAIG;AACH,MAAM,MAAM,8BAA8B,GAAG;IAC3C,8DAA8D;IAC9D,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,kEAAkE;IAClE,qBAAqB,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,EAAE,CAAC,CAAC;IACvD,0DAA0D;IAC1D,iBAAiB,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;IAChC,uEAAuE;IACvE,kBAAkB,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;IACjC;;;OAGG;IACH,aAAa,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;CAC7B,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,+BAA+B,GAAG;IAC5C,yEAAyE;IACzE,MAAM,EAAE,OAAO,EAAE,CAAC;IAClB,0EAA0E;IAC1E,UAAU,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;CACzB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,6BAA6B,CAC3C,KAAK,EAAE,8BAA8B,GACpC,+BAA+B,CA8CjC"}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { parseCaipAssetType } from '@metamask/utils';
|
|
2
|
-
/**
|
|
3
|
-
* Decide which chains require a supplemental `customAssetsOnly` RPC
|
|
4
|
-
* subscription so that user-imported customAssets are **always** polled by
|
|
5
|
-
* RPC — even when AccountsApi or the websocket data source has already
|
|
6
|
-
* claimed the chain in the regular handoff.
|
|
7
|
-
*
|
|
8
|
-
* RPC is the sole balance fetcher for customAssets:
|
|
9
|
-
* - AccountsApi indexes a curated token list and may return zero (or no
|
|
10
|
-
* entry at all) for a user-imported token, even on supported chains.
|
|
11
|
-
* - The websocket data source is push-only: it relays balance deltas from
|
|
12
|
-
* transactions, so a user who never transacts won't see balance updates.
|
|
13
|
-
*
|
|
14
|
-
* To guarantee freshness, we subscribe RPC in `customAssetsOnly` mode on
|
|
15
|
-
* any chain that:
|
|
16
|
-
* 1. has at least one selected account with a customAsset there;
|
|
17
|
-
* 2. is supported by the RPC data source;
|
|
18
|
-
* 3. is **not** already covered by the regular RPC subscription
|
|
19
|
-
* (`rpcAssignedChains`) — otherwise customAssets are picked up there;
|
|
20
|
-
* 4. is currently enabled (in `chainToAccounts`); polling a disabled
|
|
21
|
-
* chain wastes resources because the user can't see its balances.
|
|
22
|
-
*
|
|
23
|
-
* Malformed asset IDs are silently skipped — they can't be parsed into a
|
|
24
|
-
* chain anyway and shouldn't crash the subscription pipeline.
|
|
25
|
-
*
|
|
26
|
-
* @param input - Decision inputs.
|
|
27
|
-
* @returns Chains and account IDs that require supplemental subscription.
|
|
28
|
-
*/
|
|
29
|
-
export function pickRpcCustomAssetsSupplement(input) {
|
|
30
|
-
const { accountIds, customAssetsByAccount, rpcAssignedChains, rpcAvailableChains, enabledChains, } = input;
|
|
31
|
-
const chains = new Set();
|
|
32
|
-
const supplementalAccountIds = new Set();
|
|
33
|
-
for (const accountId of accountIds) {
|
|
34
|
-
const customForAccount = customAssetsByAccount[accountId];
|
|
35
|
-
if (!customForAccount || customForAccount.length === 0) {
|
|
36
|
-
continue;
|
|
37
|
-
}
|
|
38
|
-
// Mirror the controller's prior behavior: an account with any customAsset
|
|
39
|
-
// (even if all are filtered out below) is added to the candidate set.
|
|
40
|
-
// The empty-chains early-return in the caller still prevents a useless
|
|
41
|
-
// subscription, so this preserves observable behavior.
|
|
42
|
-
supplementalAccountIds.add(accountId);
|
|
43
|
-
for (const assetId of customForAccount) {
|
|
44
|
-
let chainId;
|
|
45
|
-
try {
|
|
46
|
-
chainId = parseCaipAssetType(assetId).chainId;
|
|
47
|
-
}
|
|
48
|
-
catch {
|
|
49
|
-
continue;
|
|
50
|
-
}
|
|
51
|
-
if (rpcAssignedChains.has(chainId)) {
|
|
52
|
-
continue;
|
|
53
|
-
}
|
|
54
|
-
if (!rpcAvailableChains.has(chainId)) {
|
|
55
|
-
continue;
|
|
56
|
-
}
|
|
57
|
-
if (!enabledChains.has(chainId)) {
|
|
58
|
-
continue;
|
|
59
|
-
}
|
|
60
|
-
chains.add(chainId);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
return {
|
|
64
|
-
chains: [...chains],
|
|
65
|
-
accountIds: supplementalAccountIds,
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
//# sourceMappingURL=customAssetsRpcSupplement.js.map
|