@metamask-previews/assets-controller 2.0.2-preview-980f677 → 2.0.2-preview-3d4d0d0ef
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +0 -8
- package/dist/AssetsController.cjs +27 -118
- package/dist/AssetsController.cjs.map +1 -1
- package/dist/AssetsController.d.cts +4 -16
- package/dist/AssetsController.d.cts.map +1 -1
- package/dist/AssetsController.d.mts +4 -16
- package/dist/AssetsController.d.mts.map +1 -1
- package/dist/AssetsController.mjs +27 -118
- package/dist/AssetsController.mjs.map +1 -1
- package/dist/data-sources/AccountsApiDataSource.cjs +0 -1
- package/dist/data-sources/AccountsApiDataSource.cjs.map +1 -1
- package/dist/data-sources/AccountsApiDataSource.d.cts.map +1 -1
- package/dist/data-sources/AccountsApiDataSource.d.mts.map +1 -1
- package/dist/data-sources/AccountsApiDataSource.mjs +0 -1
- package/dist/data-sources/AccountsApiDataSource.mjs.map +1 -1
- package/dist/data-sources/BackendWebsocketDataSource.cjs +1 -1
- package/dist/data-sources/BackendWebsocketDataSource.cjs.map +1 -1
- package/dist/data-sources/BackendWebsocketDataSource.mjs +1 -1
- package/dist/data-sources/BackendWebsocketDataSource.mjs.map +1 -1
- package/dist/data-sources/PriceDataSource.cjs +14 -20
- package/dist/data-sources/PriceDataSource.cjs.map +1 -1
- package/dist/data-sources/PriceDataSource.d.cts +2 -2
- package/dist/data-sources/PriceDataSource.d.cts.map +1 -1
- package/dist/data-sources/PriceDataSource.d.mts +2 -2
- package/dist/data-sources/PriceDataSource.d.mts.map +1 -1
- package/dist/data-sources/PriceDataSource.mjs +14 -20
- package/dist/data-sources/PriceDataSource.mjs.map +1 -1
- package/dist/data-sources/RpcDataSource.cjs +0 -2
- package/dist/data-sources/RpcDataSource.cjs.map +1 -1
- package/dist/data-sources/RpcDataSource.d.cts.map +1 -1
- package/dist/data-sources/RpcDataSource.d.mts.map +1 -1
- package/dist/data-sources/RpcDataSource.mjs +0 -2
- package/dist/data-sources/RpcDataSource.mjs.map +1 -1
- package/dist/data-sources/SnapDataSource.cjs +2 -3
- package/dist/data-sources/SnapDataSource.cjs.map +1 -1
- package/dist/data-sources/SnapDataSource.d.cts.map +1 -1
- package/dist/data-sources/SnapDataSource.d.mts.map +1 -1
- package/dist/data-sources/SnapDataSource.mjs +2 -3
- package/dist/data-sources/SnapDataSource.mjs.map +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/middlewares/index.cjs +1 -5
- package/dist/middlewares/index.cjs.map +1 -1
- package/dist/middlewares/index.d.cts +0 -2
- package/dist/middlewares/index.d.cts.map +1 -1
- package/dist/middlewares/index.d.mts +0 -2
- package/dist/middlewares/index.d.mts.map +1 -1
- package/dist/middlewares/index.mjs +0 -1
- package/dist/middlewares/index.mjs.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +0 -16
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +0 -16
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/package.json +3 -4
- package/dist/middlewares/ParallelMiddleware.cjs +0 -216
- package/dist/middlewares/ParallelMiddleware.cjs.map +0 -1
- package/dist/middlewares/ParallelMiddleware.d.cts +0 -45
- package/dist/middlewares/ParallelMiddleware.d.cts.map +0 -1
- package/dist/middlewares/ParallelMiddleware.d.mts +0 -45
- package/dist/middlewares/ParallelMiddleware.d.mts.map +0 -1
- package/dist/middlewares/ParallelMiddleware.mjs +0 -214
- package/dist/middlewares/ParallelMiddleware.mjs.map +0 -1
package/dist/types.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,uCA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AAC,GAAG,EAAE,IAAI,CAAC,CAAC;IAC/B,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import 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/spl: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 USD */\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 = {\n /** CoinGecko ID */\n id?: string;\n /** Current price in USD */\n price: number;\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 /** 1h price change percentage */\n pricePercentChange1h?: 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 /** Timestamp of last price update (added by client) */\n lastUpdated: number;\n};\n\n/**\n * Price data for NFT collections\n */\nexport type NFTAssetPrice = {\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} & BaseAssetPrice;\n\n/**\n * Union type representing all possible asset price types.\n * All types must be JSON-serializable.\n */\nexport type AssetPrice =\n | FungibleAssetPrice\n | NFTAssetPrice\n | (BaseAssetPrice & { [key: string]: Json });\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 /** Raw balance amount as string (e.g., \"1000000000\" for 1000 USDC) */\n amount: string;\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 /** Specific CAIP-19 asset IDs */\n customAssets?: Caip19AssetId[];\n /** Force fresh fetch, bypass cache */\n forceUpdate?: boolean;\n /** Hint for polling interval (ms) - used by data sources that implement polling */\n updateInterval?: number;\n /** Specific CAIP-19 asset IDs for price update */\n assetsForPriceUpdate?: Caip19AssetId[];\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 */\n errors?: Record<ChainId, string>;\n /** Detected assets (assets that do not have metadata) */\n detectedAssets?: Record<AccountId, Caip19AssetId[]>;\n /**\n * How to apply this response to state. See {@link AssetsUpdateMode}.\n * Defaults to `'merge'` if omitted.\n */\n updateMode?: AssetsUpdateMode;\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 the scope. Assets in state but not in the\n * response are cleared (except custom assets). Use for initial fetch or full refresh.\n * - **merge**: Only assets present in the response are updated; nothing is removed.\n * Use for event-driven or incremental updates.\n */\nexport type AssetsUpdateMode = 'full' | 'merge';\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// UNIFIED MIDDLEWARE TYPES\n// ============================================================================\n\n/**\n * Internal state structure for AssetsController following normalized design.\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 AssetsControllerStateInternal = {\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};\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 /** Get current assets state */\n getAssetsState: () => AssetsControllerStateInternal;\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 * 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\n/**\n * Event emitted when assets without metadata are detected\n */\nexport type AssetsDetectedEvent = {\n accountId: AccountId;\n assetIds: Caip19AssetId[];\n};\n"]}
|
|
1
|
+
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAodA;;;;;;;;;;;;;;;;;;;;;;;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 { 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/spl: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 USD */\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 = {\n /** CoinGecko ID */\n id?: string;\n /** Current price in USD */\n price: number;\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 /** 1h price change percentage */\n pricePercentChange1h?: 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 /** Timestamp of last price update (added by client) */\n lastUpdated: number;\n};\n\n/**\n * Price data for NFT collections\n */\nexport type NFTAssetPrice = {\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} & BaseAssetPrice;\n\n/**\n * Union type representing all possible asset price types.\n * All types must be JSON-serializable.\n */\nexport type AssetPrice =\n | FungibleAssetPrice\n | NFTAssetPrice\n | (BaseAssetPrice & { [key: string]: Json });\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 /** Raw balance amount as string (e.g., \"1000000000\" for 1000 USDC) */\n amount: string;\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 /** Specific CAIP-19 asset IDs */\n customAssets?: Caip19AssetId[];\n /** Force fresh fetch, bypass cache */\n forceUpdate?: 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 */\n errors?: Record<ChainId, string>;\n /** Detected assets (assets that do not have metadata) */\n detectedAssets?: Record<AccountId, Caip19AssetId[]>;\n};\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// UNIFIED MIDDLEWARE TYPES\n// ============================================================================\n\n/**\n * Internal state structure for AssetsController following normalized design.\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 AssetsControllerStateInternal = {\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};\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 /** Get current assets state */\n getAssetsState: () => AssetsControllerStateInternal;\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 * 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\n/**\n * Event emitted when assets without metadata are detected\n */\nexport type AssetsDetectedEvent = {\n accountId: AccountId;\n assetIds: Caip19AssetId[];\n};\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask-previews/assets-controller",
|
|
3
|
-
"version": "2.0.2-preview-
|
|
3
|
+
"version": "2.0.2-preview-3d4d0d0ef",
|
|
4
4
|
"description": "Tracks assets balances/prices and handles token detection across all digital assets",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"MetaMask",
|
|
@@ -41,6 +41,7 @@
|
|
|
41
41
|
"changelog:update": "../../scripts/update-changelog.sh @metamask/assets-controller",
|
|
42
42
|
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/assets-controller",
|
|
43
43
|
"generate-method-action-types": "tsx ../../scripts/generate-method-action-types.ts",
|
|
44
|
+
"publish:preview": "yarn npm publish --tag preview",
|
|
44
45
|
"since-latest-release": "../../scripts/since-latest-release.sh",
|
|
45
46
|
"test": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter",
|
|
46
47
|
"test:clean": "NODE_OPTIONS=--experimental-vm-modules jest --clearCache",
|
|
@@ -54,7 +55,6 @@
|
|
|
54
55
|
"@metamask/account-tree-controller": "^4.1.1",
|
|
55
56
|
"@metamask/assets-controllers": "^100.0.2",
|
|
56
57
|
"@metamask/base-controller": "^9.0.0",
|
|
57
|
-
"@metamask/client-controller": "^1.0.0",
|
|
58
58
|
"@metamask/controller-utils": "^11.19.0",
|
|
59
59
|
"@metamask/core-backend": "^6.0.0",
|
|
60
60
|
"@metamask/keyring-api": "^21.5.0",
|
|
@@ -73,8 +73,7 @@
|
|
|
73
73
|
"@metamask/utils": "^11.9.0",
|
|
74
74
|
"async-mutex": "^0.5.0",
|
|
75
75
|
"bignumber.js": "^9.1.2",
|
|
76
|
-
"lodash": "^4.17.21"
|
|
77
|
-
"p-limit": "^3.1.0"
|
|
76
|
+
"lodash": "^4.17.21"
|
|
78
77
|
},
|
|
79
78
|
"devDependencies": {
|
|
80
79
|
"@metamask/auto-changelog": "^3.4.4",
|
|
@@ -1,216 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.createParallelMiddleware = exports.createParallelBalanceMiddleware = exports.mergeDataResponses = void 0;
|
|
7
|
-
const p_limit_1 = __importDefault(require("p-limit/index.js"));
|
|
8
|
-
// ============================================================================
|
|
9
|
-
// MERGE HELPER
|
|
10
|
-
// ============================================================================
|
|
11
|
-
/**
|
|
12
|
-
* Deep-merge multiple DataResponses into one.
|
|
13
|
-
* Used when running balance data sources in parallel.
|
|
14
|
-
*
|
|
15
|
-
* @param responses - Array of DataResponse from each source.
|
|
16
|
-
* @returns Single merged DataResponse.
|
|
17
|
-
*/
|
|
18
|
-
function mergeDataResponses(responses) {
|
|
19
|
-
const merged = {};
|
|
20
|
-
for (const response of responses) {
|
|
21
|
-
if (response.assetsBalance) {
|
|
22
|
-
merged.assetsBalance ?? (merged.assetsBalance = {});
|
|
23
|
-
for (const [accountId, accountBalances] of Object.entries(response.assetsBalance)) {
|
|
24
|
-
merged.assetsBalance[accountId] = {
|
|
25
|
-
...(merged.assetsBalance[accountId] ?? {}),
|
|
26
|
-
...accountBalances,
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
if (response.assetsInfo) {
|
|
31
|
-
merged.assetsInfo = {
|
|
32
|
-
...(merged.assetsInfo ?? {}),
|
|
33
|
-
...response.assetsInfo,
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
if (response.assetsPrice) {
|
|
37
|
-
merged.assetsPrice = {
|
|
38
|
-
...(merged.assetsPrice ?? {}),
|
|
39
|
-
...response.assetsPrice,
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
if (response.errors) {
|
|
43
|
-
merged.errors = {
|
|
44
|
-
...(merged.errors ?? {}),
|
|
45
|
-
...response.errors,
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
if (response.detectedAssets) {
|
|
49
|
-
merged.detectedAssets = {
|
|
50
|
-
...(merged.detectedAssets ?? {}),
|
|
51
|
-
...response.detectedAssets,
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
if (response.updateMode === 'full') {
|
|
55
|
-
merged.updateMode = 'full';
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
merged.updateMode ?? (merged.updateMode = 'merge');
|
|
59
|
-
return merged;
|
|
60
|
-
}
|
|
61
|
-
exports.mergeDataResponses = mergeDataResponses;
|
|
62
|
-
// ============================================================================
|
|
63
|
-
// PARALLEL BALANCE MIDDLEWARE
|
|
64
|
-
// ============================================================================
|
|
65
|
-
const PARALLEL_BALANCE_MIDDLEWARE_NAME = 'ParallelBalanceMiddleware';
|
|
66
|
-
/** Max concurrent balance source calls (round 1 and fallback). */
|
|
67
|
-
const BALANCE_CONCURRENCY = 3;
|
|
68
|
-
/**
|
|
69
|
-
* Partition request.chainIds so each chain is assigned to exactly one source
|
|
70
|
-
* (by source order: first source that supports the chain gets it). Ensures no
|
|
71
|
-
* chain overlap across data source calls.
|
|
72
|
-
*
|
|
73
|
-
* @param request - The data request with chainIds to partition.
|
|
74
|
-
* @param sources - Balance sources in priority order (e.g. AccountsAPI, Snap, Rpc).
|
|
75
|
-
* @returns Array of requests, one per source, each with only that source's assigned chainIds.
|
|
76
|
-
*/
|
|
77
|
-
function partitionChainsBySource(request, sources) {
|
|
78
|
-
const { chainIds } = request;
|
|
79
|
-
const assigned = new Set();
|
|
80
|
-
return sources.map((source) => {
|
|
81
|
-
const supported = new Set(source.getActiveChainsSync());
|
|
82
|
-
const chainsForSource = chainIds.filter((id) => supported.has(id) && !assigned.has(id));
|
|
83
|
-
chainsForSource.forEach((id) => assigned.add(id));
|
|
84
|
-
return {
|
|
85
|
-
...request,
|
|
86
|
-
chainIds: chainsForSource,
|
|
87
|
-
};
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Collect chain IDs that failed in the first round (present in response.errors).
|
|
92
|
-
* Used to run a fallback round with remaining sources.
|
|
93
|
-
*
|
|
94
|
-
* @param requests - Partitioned requests, one per source (same order as results).
|
|
95
|
-
* @param results - Results from each source; chain IDs in requests[i] that have errors in results[i].response.errors are considered failed.
|
|
96
|
-
* @returns Set of chain IDs that had errors in the first round.
|
|
97
|
-
*/
|
|
98
|
-
function getFailedChainIds(requests, results) {
|
|
99
|
-
const failed = new Set();
|
|
100
|
-
for (let i = 0; i < results.length; i++) {
|
|
101
|
-
const errors = results[i].response.errors ?? {};
|
|
102
|
-
for (const chainId of requests[i].chainIds) {
|
|
103
|
-
if (errors[chainId]) {
|
|
104
|
-
failed.add(chainId);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
return failed;
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Middleware that runs multiple balance data source middlewares in parallel,
|
|
112
|
-
* with no chain overlap. Chains that fail (response.errors) are re-partitioned
|
|
113
|
-
* and fetched again in a fallback round so lower-priority sources can try them.
|
|
114
|
-
*
|
|
115
|
-
* @param sources - Array of balance sources in priority order (each with getName(), getActiveChainsSync(), assetsMiddleware).
|
|
116
|
-
* @returns A single middleware that runs all sources in parallel and merges responses.
|
|
117
|
-
*/
|
|
118
|
-
function createParallelBalanceMiddleware(sources) {
|
|
119
|
-
return {
|
|
120
|
-
getName() {
|
|
121
|
-
return PARALLEL_BALANCE_MIDDLEWARE_NAME;
|
|
122
|
-
},
|
|
123
|
-
assetsMiddleware: async (context, next) => {
|
|
124
|
-
if (sources.length === 0) {
|
|
125
|
-
return next(context);
|
|
126
|
-
}
|
|
127
|
-
const noopNext = async (ctx) => ctx;
|
|
128
|
-
const limit = (0, p_limit_1.default)(BALANCE_CONCURRENCY);
|
|
129
|
-
// Round 1: partition chains (no overlap), run with limited concurrency
|
|
130
|
-
const requests = partitionChainsBySource(context.request, sources);
|
|
131
|
-
const results = await Promise.all(sources.map((source, i) => limit(() => source.assetsMiddleware({
|
|
132
|
-
request: requests[i],
|
|
133
|
-
response: {},
|
|
134
|
-
getAssetsState: context.getAssetsState,
|
|
135
|
-
}, noopNext))));
|
|
136
|
-
let mergedResponse = mergeDataResponses(results.map((result) => result.response));
|
|
137
|
-
// Fallback: chains that failed (in errors) get re-partitioned and tried again
|
|
138
|
-
const failedChainIds = getFailedChainIds(requests, results);
|
|
139
|
-
if (failedChainIds.size > 0) {
|
|
140
|
-
const fallbackRequest = {
|
|
141
|
-
...context.request,
|
|
142
|
-
chainIds: [...failedChainIds],
|
|
143
|
-
};
|
|
144
|
-
const fallbackRequests = partitionChainsBySource(fallbackRequest, sources);
|
|
145
|
-
const fallbackResults = await Promise.all(sources.map((source, i) => limit(() => source.assetsMiddleware({
|
|
146
|
-
request: fallbackRequests[i],
|
|
147
|
-
response: {},
|
|
148
|
-
getAssetsState: context.getAssetsState,
|
|
149
|
-
}, noopNext))));
|
|
150
|
-
const fallbackMerged = mergeDataResponses(fallbackResults.map((result) => result.response));
|
|
151
|
-
mergedResponse = mergeDataResponses([mergedResponse, fallbackMerged]);
|
|
152
|
-
// Remove errors for chains we successfully got balance for in fallback
|
|
153
|
-
if (mergedResponse.errors && mergedResponse.assetsBalance) {
|
|
154
|
-
const chainsWithBalance = new Set();
|
|
155
|
-
for (const accountBalances of Object.values(mergedResponse.assetsBalance)) {
|
|
156
|
-
for (const assetId of Object.keys(accountBalances)) {
|
|
157
|
-
const chainId = assetId.split('/')[0];
|
|
158
|
-
chainsWithBalance.add(chainId);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
for (const chainId of failedChainIds) {
|
|
162
|
-
if (chainsWithBalance.has(chainId)) {
|
|
163
|
-
delete mergedResponse.errors[chainId];
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
return next({
|
|
169
|
-
...context,
|
|
170
|
-
response: mergeDataResponses([context.response, mergedResponse]),
|
|
171
|
-
});
|
|
172
|
-
},
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
exports.createParallelBalanceMiddleware = createParallelBalanceMiddleware;
|
|
176
|
-
// ============================================================================
|
|
177
|
-
// PARALLEL TOKEN/PRICE MIDDLEWARE
|
|
178
|
-
// ============================================================================
|
|
179
|
-
const PARALLEL_MIDDLEWARE_NAME = 'ParallelMiddleware';
|
|
180
|
-
/** Max concurrent token/price source calls. */
|
|
181
|
-
const CONCURRENCY = 2;
|
|
182
|
-
/**
|
|
183
|
-
* Middleware that runs multiple data source middlewares (e.g. TokenDataSource,
|
|
184
|
-
* PriceDataSource) in parallel with the same request. Responses are merged so
|
|
185
|
-
* that assetsInfo (token metadata) and assetsPrice are combined. Use this to
|
|
186
|
-
* fetch token and price data concurrently instead of sequentially.
|
|
187
|
-
*
|
|
188
|
-
* @param sources - Array of sources with getName() and assetsMiddleware.
|
|
189
|
-
* @returns A single middleware that runs all sources in parallel and merges responses.
|
|
190
|
-
*/
|
|
191
|
-
function createParallelMiddleware(sources) {
|
|
192
|
-
return {
|
|
193
|
-
getName() {
|
|
194
|
-
return PARALLEL_MIDDLEWARE_NAME;
|
|
195
|
-
},
|
|
196
|
-
assetsMiddleware: async (context, next) => {
|
|
197
|
-
if (sources.length === 0) {
|
|
198
|
-
return next(context);
|
|
199
|
-
}
|
|
200
|
-
const noopNext = async (ctx) => ctx;
|
|
201
|
-
const limit = (0, p_limit_1.default)(CONCURRENCY);
|
|
202
|
-
const results = await Promise.all(sources.map((source) => limit(() => source.assetsMiddleware({
|
|
203
|
-
request: context.request,
|
|
204
|
-
response: { ...context.response },
|
|
205
|
-
getAssetsState: context.getAssetsState,
|
|
206
|
-
}, noopNext))));
|
|
207
|
-
const mergedResponse = mergeDataResponses(results.map((result) => result.response));
|
|
208
|
-
return next({
|
|
209
|
-
...context,
|
|
210
|
-
response: mergeDataResponses([context.response, mergedResponse]),
|
|
211
|
-
});
|
|
212
|
-
},
|
|
213
|
-
};
|
|
214
|
-
}
|
|
215
|
-
exports.createParallelMiddleware = createParallelMiddleware;
|
|
216
|
-
//# sourceMappingURL=ParallelMiddleware.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ParallelMiddleware.cjs","sourceRoot":"","sources":["../../src/middlewares/ParallelMiddleware.ts"],"names":[],"mappings":";;;;;;AAAA,+DAA6B;AAU7B,+EAA+E;AAC/E,eAAe;AACf,+EAA+E;AAE/E;;;;;;GAMG;AACH,SAAgB,kBAAkB,CAAC,SAAyB;IAC1D,MAAM,MAAM,GAAiB,EAAE,CAAC;IAEhC,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;QACjC,IAAI,QAAQ,CAAC,aAAa,EAAE,CAAC;YAC3B,MAAM,CAAC,aAAa,KAApB,MAAM,CAAC,aAAa,GAAK,EAAE,EAAC;YAC5B,KAAK,MAAM,CAAC,SAAS,EAAE,eAAe,CAAC,IAAI,MAAM,CAAC,OAAO,CACvD,QAAQ,CAAC,aAAa,CACvB,EAAE,CAAC;gBACF,MAAM,CAAC,aAAa,CAAC,SAAS,CAAC,GAAG;oBAChC,GAAG,CAAC,MAAM,CAAC,aAAa,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC;oBAC1C,GAAG,eAAe;iBACnB,CAAC;YACJ,CAAC;QACH,CAAC;QACD,IAAI,QAAQ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EAAE,kBAAkB,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC;aACjE,CAAC,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC;AA3CD,4DA2CC","sourcesContent":["import pLimit from 'p-limit';\n\nimport type {\n ChainId,\n Context,\n DataRequest,\n DataResponse,\n Middleware,\n} from '../types';\n\n// ============================================================================\n// MERGE HELPER\n// ============================================================================\n\n/**\n * Deep-merge multiple DataResponses into one.\n * Used when running balance data sources in parallel.\n *\n * @param responses - Array of DataResponse from each source.\n * @returns Single merged DataResponse.\n */\nexport function mergeDataResponses(responses: DataResponse[]): DataResponse {\n const merged: DataResponse = {};\n\n for (const response of responses) {\n if (response.assetsBalance) {\n merged.assetsBalance ??= {};\n for (const [accountId, accountBalances] of Object.entries(\n response.assetsBalance,\n )) {\n merged.assetsBalance[accountId] = {\n ...(merged.assetsBalance[accountId] ?? {}),\n ...accountBalances,\n };\n }\n }\n if (response.assetsInfo) {\n merged.assetsInfo = {\n ...(merged.assetsInfo ?? {}),\n ...response.assetsInfo,\n };\n }\n if (response.assetsPrice) {\n merged.assetsPrice = {\n ...(merged.assetsPrice ?? {}),\n ...response.assetsPrice,\n };\n }\n if (response.errors) {\n merged.errors = {\n ...(merged.errors ?? {}),\n ...response.errors,\n };\n }\n if (response.detectedAssets) {\n merged.detectedAssets = {\n ...(merged.detectedAssets ?? {}),\n ...response.detectedAssets,\n };\n }\n if (response.updateMode === 'full') {\n merged.updateMode = 'full';\n }\n }\n merged.updateMode ??= 'merge';\n\n return merged;\n}\n\n// ============================================================================\n// PARALLEL BALANCE MIDDLEWARE\n// ============================================================================\n\nconst PARALLEL_BALANCE_MIDDLEWARE_NAME = 'ParallelBalanceMiddleware';\n\n/** Max concurrent balance source calls (round 1 and fallback). */\nconst BALANCE_CONCURRENCY = 3;\n\nexport type BalanceSource = {\n getName(): string;\n /** Chains this source can fetch (e.g. from getActiveChainsSync()). Used to partition chains with no overlap. */\n getActiveChainsSync(): ChainId[];\n assetsMiddleware: Middleware;\n};\n\n/**\n * Partition request.chainIds so each chain is assigned to exactly one source\n * (by source order: first source that supports the chain gets it). Ensures no\n * chain overlap across data source calls.\n *\n * @param request - The data request with chainIds to partition.\n * @param sources - Balance sources in priority order (e.g. AccountsAPI, Snap, Rpc).\n * @returns Array of requests, one per source, each with only that source's assigned chainIds.\n */\nfunction partitionChainsBySource(\n request: DataRequest,\n sources: BalanceSource[],\n): DataRequest[] {\n const { chainIds } = request;\n const assigned = new Set<ChainId>();\n\n return sources.map((source) => {\n const supported = new Set(source.getActiveChainsSync());\n const chainsForSource = chainIds.filter(\n (id) => supported.has(id) && !assigned.has(id),\n );\n chainsForSource.forEach((id) => assigned.add(id));\n\n return {\n ...request,\n chainIds: chainsForSource,\n };\n });\n}\n\n/**\n * Collect chain IDs that failed in the first round (present in response.errors).\n * Used to run a fallback round with remaining sources.\n *\n * @param requests - Partitioned requests, one per source (same order as results).\n * @param results - Results from each source; chain IDs in requests[i] that have errors in results[i].response.errors are considered failed.\n * @returns Set of chain IDs that had errors in the first round.\n */\nfunction getFailedChainIds(\n requests: DataRequest[],\n results: { response: DataResponse }[],\n): Set<ChainId> {\n const failed = new Set<ChainId>();\n for (let i = 0; i < results.length; i++) {\n const errors = results[i].response.errors ?? {};\n for (const chainId of requests[i].chainIds) {\n if (errors[chainId]) {\n failed.add(chainId);\n }\n }\n }\n return failed;\n}\n\n/**\n * Middleware that runs multiple balance data source middlewares in parallel,\n * with no chain overlap. Chains that fail (response.errors) are re-partitioned\n * and fetched again in a fallback round so lower-priority sources can try them.\n *\n * @param sources - Array of balance sources in priority order (each with getName(), getActiveChainsSync(), assetsMiddleware).\n * @returns A single middleware that runs all sources in parallel and merges responses.\n */\nexport function createParallelBalanceMiddleware(sources: BalanceSource[]): {\n getName(): string;\n assetsMiddleware: Middleware;\n} {\n return {\n getName(): string {\n return PARALLEL_BALANCE_MIDDLEWARE_NAME;\n },\n\n assetsMiddleware: async (context, next): Promise<Context> => {\n if (sources.length === 0) {\n return next(context);\n }\n\n const noopNext = async (ctx: typeof context): Promise<typeof context> =>\n ctx;\n const limit = pLimit(BALANCE_CONCURRENCY);\n\n // Round 1: partition chains (no overlap), run with limited concurrency\n const requests = partitionChainsBySource(context.request, sources);\n const results = await Promise.all(\n sources.map((source, i) =>\n limit(() =>\n source.assetsMiddleware(\n {\n request: requests[i],\n response: {},\n getAssetsState: context.getAssetsState,\n },\n noopNext,\n ),\n ),\n ),\n );\n\n let mergedResponse = mergeDataResponses(\n results.map((result) => result.response),\n );\n\n // Fallback: chains that failed (in errors) get re-partitioned and tried again\n const failedChainIds = getFailedChainIds(requests, results);\n if (failedChainIds.size > 0) {\n const fallbackRequest: DataRequest = {\n ...context.request,\n chainIds: [...failedChainIds],\n };\n const fallbackRequests = partitionChainsBySource(\n fallbackRequest,\n sources,\n );\n const fallbackResults = await Promise.all(\n sources.map((source, i) =>\n limit(() =>\n source.assetsMiddleware(\n {\n request: fallbackRequests[i],\n response: {},\n getAssetsState: context.getAssetsState,\n },\n noopNext,\n ),\n ),\n ),\n );\n const fallbackMerged = mergeDataResponses(\n fallbackResults.map((result) => result.response),\n );\n mergedResponse = mergeDataResponses([mergedResponse, fallbackMerged]);\n // Remove errors for chains we successfully got balance for in fallback\n if (mergedResponse.errors && mergedResponse.assetsBalance) {\n const chainsWithBalance = new Set<ChainId>();\n for (const accountBalances of Object.values(\n mergedResponse.assetsBalance,\n )) {\n for (const assetId of Object.keys(accountBalances)) {\n const chainId = assetId.split('/')[0] as ChainId;\n chainsWithBalance.add(chainId);\n }\n }\n for (const chainId of failedChainIds) {\n if (chainsWithBalance.has(chainId)) {\n delete mergedResponse.errors[chainId];\n }\n }\n }\n }\n\n return next({\n ...context,\n response: mergeDataResponses([context.response, mergedResponse]),\n });\n },\n };\n}\n\n// ============================================================================\n// PARALLEL TOKEN/PRICE MIDDLEWARE\n// ============================================================================\n\nconst PARALLEL_MIDDLEWARE_NAME = 'ParallelMiddleware';\n\n/** Max concurrent token/price source calls. */\nconst CONCURRENCY = 2;\n\nexport type TokenPriceSource = {\n getName(): string;\n assetsMiddleware: Middleware;\n};\n\n/**\n * Middleware that runs multiple data source middlewares (e.g. TokenDataSource,\n * PriceDataSource) in parallel with the same request. Responses are merged so\n * that assetsInfo (token metadata) and assetsPrice are combined. Use this to\n * fetch token and price data concurrently instead of sequentially.\n *\n * @param sources - Array of sources with getName() and assetsMiddleware.\n * @returns A single middleware that runs all sources in parallel and merges responses.\n */\nexport function createParallelMiddleware(sources: TokenPriceSource[]): {\n getName(): string;\n assetsMiddleware: Middleware;\n} {\n return {\n getName(): string {\n return PARALLEL_MIDDLEWARE_NAME;\n },\n\n assetsMiddleware: async (context, next): Promise<Context> => {\n if (sources.length === 0) {\n return next(context);\n }\n\n const noopNext = async (ctx: typeof context): Promise<typeof context> =>\n ctx;\n const limit = pLimit(CONCURRENCY);\n\n const results = await Promise.all(\n sources.map((source) =>\n limit(() =>\n source.assetsMiddleware(\n {\n request: context.request,\n response: { ...context.response },\n getAssetsState: context.getAssetsState,\n },\n noopNext,\n ),\n ),\n ),\n );\n\n const mergedResponse = mergeDataResponses(\n results.map((result) => result.response),\n );\n\n return next({\n ...context,\n response: mergeDataResponses([context.response, mergedResponse]),\n });\n },\n };\n}\n"]}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import type { ChainId, DataResponse, Middleware } from "../types.cjs";
|
|
2
|
-
/**
|
|
3
|
-
* Deep-merge multiple DataResponses into one.
|
|
4
|
-
* Used when running balance data sources in parallel.
|
|
5
|
-
*
|
|
6
|
-
* @param responses - Array of DataResponse from each source.
|
|
7
|
-
* @returns Single merged DataResponse.
|
|
8
|
-
*/
|
|
9
|
-
export declare function mergeDataResponses(responses: DataResponse[]): DataResponse;
|
|
10
|
-
export type BalanceSource = {
|
|
11
|
-
getName(): string;
|
|
12
|
-
/** Chains this source can fetch (e.g. from getActiveChainsSync()). Used to partition chains with no overlap. */
|
|
13
|
-
getActiveChainsSync(): ChainId[];
|
|
14
|
-
assetsMiddleware: Middleware;
|
|
15
|
-
};
|
|
16
|
-
/**
|
|
17
|
-
* Middleware that runs multiple balance data source middlewares in parallel,
|
|
18
|
-
* with no chain overlap. Chains that fail (response.errors) are re-partitioned
|
|
19
|
-
* and fetched again in a fallback round so lower-priority sources can try them.
|
|
20
|
-
*
|
|
21
|
-
* @param sources - Array of balance sources in priority order (each with getName(), getActiveChainsSync(), assetsMiddleware).
|
|
22
|
-
* @returns A single middleware that runs all sources in parallel and merges responses.
|
|
23
|
-
*/
|
|
24
|
-
export declare function createParallelBalanceMiddleware(sources: BalanceSource[]): {
|
|
25
|
-
getName(): string;
|
|
26
|
-
assetsMiddleware: Middleware;
|
|
27
|
-
};
|
|
28
|
-
export type TokenPriceSource = {
|
|
29
|
-
getName(): string;
|
|
30
|
-
assetsMiddleware: Middleware;
|
|
31
|
-
};
|
|
32
|
-
/**
|
|
33
|
-
* Middleware that runs multiple data source middlewares (e.g. TokenDataSource,
|
|
34
|
-
* PriceDataSource) in parallel with the same request. Responses are merged so
|
|
35
|
-
* that assetsInfo (token metadata) and assetsPrice are combined. Use this to
|
|
36
|
-
* fetch token and price data concurrently instead of sequentially.
|
|
37
|
-
*
|
|
38
|
-
* @param sources - Array of sources with getName() and assetsMiddleware.
|
|
39
|
-
* @returns A single middleware that runs all sources in parallel and merges responses.
|
|
40
|
-
*/
|
|
41
|
-
export declare function createParallelMiddleware(sources: TokenPriceSource[]): {
|
|
42
|
-
getName(): string;
|
|
43
|
-
assetsMiddleware: Middleware;
|
|
44
|
-
};
|
|
45
|
-
//# sourceMappingURL=ParallelMiddleware.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ParallelMiddleware.d.cts","sourceRoot":"","sources":["../../src/middlewares/ParallelMiddleware.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,OAAO,EAGP,YAAY,EACZ,UAAU,EACX,qBAAiB;AAMlB;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,YAAY,EAAE,GAAG,YAAY,CA8C1E;AAWD,MAAM,MAAM,aAAa,GAAG;IAC1B,OAAO,IAAI,MAAM,CAAC;IAClB,gHAAgH;IAChH,mBAAmB,IAAI,OAAO,EAAE,CAAC;IACjC,gBAAgB,EAAE,UAAU,CAAC;CAC9B,CAAC;AAwDF;;;;;;;GAOG;AACH,wBAAgB,+BAA+B,CAAC,OAAO,EAAE,aAAa,EAAE,GAAG;IACzE,OAAO,IAAI,MAAM,CAAC;IAClB,gBAAgB,EAAE,UAAU,CAAC;CAC9B,CA0FA;AAWD,MAAM,MAAM,gBAAgB,GAAG;IAC7B,OAAO,IAAI,MAAM,CAAC;IAClB,gBAAgB,EAAE,UAAU,CAAC;CAC9B,CAAC;AAEF;;;;;;;;GAQG;AACH,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,gBAAgB,EAAE,GAAG;IACrE,OAAO,IAAI,MAAM,CAAC;IAClB,gBAAgB,EAAE,UAAU,CAAC;CAC9B,CAwCA"}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import type { ChainId, DataResponse, Middleware } from "../types.mjs";
|
|
2
|
-
/**
|
|
3
|
-
* Deep-merge multiple DataResponses into one.
|
|
4
|
-
* Used when running balance data sources in parallel.
|
|
5
|
-
*
|
|
6
|
-
* @param responses - Array of DataResponse from each source.
|
|
7
|
-
* @returns Single merged DataResponse.
|
|
8
|
-
*/
|
|
9
|
-
export declare function mergeDataResponses(responses: DataResponse[]): DataResponse;
|
|
10
|
-
export type BalanceSource = {
|
|
11
|
-
getName(): string;
|
|
12
|
-
/** Chains this source can fetch (e.g. from getActiveChainsSync()). Used to partition chains with no overlap. */
|
|
13
|
-
getActiveChainsSync(): ChainId[];
|
|
14
|
-
assetsMiddleware: Middleware;
|
|
15
|
-
};
|
|
16
|
-
/**
|
|
17
|
-
* Middleware that runs multiple balance data source middlewares in parallel,
|
|
18
|
-
* with no chain overlap. Chains that fail (response.errors) are re-partitioned
|
|
19
|
-
* and fetched again in a fallback round so lower-priority sources can try them.
|
|
20
|
-
*
|
|
21
|
-
* @param sources - Array of balance sources in priority order (each with getName(), getActiveChainsSync(), assetsMiddleware).
|
|
22
|
-
* @returns A single middleware that runs all sources in parallel and merges responses.
|
|
23
|
-
*/
|
|
24
|
-
export declare function createParallelBalanceMiddleware(sources: BalanceSource[]): {
|
|
25
|
-
getName(): string;
|
|
26
|
-
assetsMiddleware: Middleware;
|
|
27
|
-
};
|
|
28
|
-
export type TokenPriceSource = {
|
|
29
|
-
getName(): string;
|
|
30
|
-
assetsMiddleware: Middleware;
|
|
31
|
-
};
|
|
32
|
-
/**
|
|
33
|
-
* Middleware that runs multiple data source middlewares (e.g. TokenDataSource,
|
|
34
|
-
* PriceDataSource) in parallel with the same request. Responses are merged so
|
|
35
|
-
* that assetsInfo (token metadata) and assetsPrice are combined. Use this to
|
|
36
|
-
* fetch token and price data concurrently instead of sequentially.
|
|
37
|
-
*
|
|
38
|
-
* @param sources - Array of sources with getName() and assetsMiddleware.
|
|
39
|
-
* @returns A single middleware that runs all sources in parallel and merges responses.
|
|
40
|
-
*/
|
|
41
|
-
export declare function createParallelMiddleware(sources: TokenPriceSource[]): {
|
|
42
|
-
getName(): string;
|
|
43
|
-
assetsMiddleware: Middleware;
|
|
44
|
-
};
|
|
45
|
-
//# sourceMappingURL=ParallelMiddleware.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ParallelMiddleware.d.mts","sourceRoot":"","sources":["../../src/middlewares/ParallelMiddleware.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,OAAO,EAGP,YAAY,EACZ,UAAU,EACX,qBAAiB;AAMlB;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,YAAY,EAAE,GAAG,YAAY,CA8C1E;AAWD,MAAM,MAAM,aAAa,GAAG;IAC1B,OAAO,IAAI,MAAM,CAAC;IAClB,gHAAgH;IAChH,mBAAmB,IAAI,OAAO,EAAE,CAAC;IACjC,gBAAgB,EAAE,UAAU,CAAC;CAC9B,CAAC;AAwDF;;;;;;;GAOG;AACH,wBAAgB,+BAA+B,CAAC,OAAO,EAAE,aAAa,EAAE,GAAG;IACzE,OAAO,IAAI,MAAM,CAAC;IAClB,gBAAgB,EAAE,UAAU,CAAC;CAC9B,CA0FA;AAWD,MAAM,MAAM,gBAAgB,GAAG;IAC7B,OAAO,IAAI,MAAM,CAAC;IAClB,gBAAgB,EAAE,UAAU,CAAC;CAC9B,CAAC;AAEF;;;;;;;;GAQG;AACH,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,gBAAgB,EAAE,GAAG;IACrE,OAAO,IAAI,MAAM,CAAC;IAClB,gBAAgB,EAAE,UAAU,CAAC;CAC9B,CAwCA"}
|