@metamask-previews/assets-controller 13.1.2-preview-9ab272863 → 13.1.2-preview-823dcff
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 +11 -0
- package/dist/AssetsController.cjs +44 -4
- package/dist/AssetsController.cjs.map +1 -1
- package/dist/AssetsController.d.cts +2 -2
- package/dist/AssetsController.d.cts.map +1 -1
- package/dist/AssetsController.d.mts +2 -2
- package/dist/AssetsController.d.mts.map +1 -1
- package/dist/AssetsController.mjs +44 -4
- package/dist/AssetsController.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/DetectionMiddleware.cjs +88 -25
- package/dist/middlewares/DetectionMiddleware.cjs.map +1 -1
- package/dist/middlewares/DetectionMiddleware.d.cts +16 -0
- package/dist/middlewares/DetectionMiddleware.d.cts.map +1 -1
- package/dist/middlewares/DetectionMiddleware.d.mts +16 -0
- package/dist/middlewares/DetectionMiddleware.d.mts.map +1 -1
- package/dist/middlewares/DetectionMiddleware.mjs +86 -23
- package/dist/middlewares/DetectionMiddleware.mjs.map +1 -1
- package/dist/middlewares/index.cjs.map +1 -1
- package/dist/middlewares/index.d.cts +1 -0
- package/dist/middlewares/index.d.cts.map +1 -1
- package/dist/middlewares/index.d.mts +1 -0
- package/dist/middlewares/index.d.mts.map +1 -1
- package/dist/middlewares/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,yBAAyB;AACzB,8DAG+B;AAF7B,uHAAA,gBAAgB,OAAA;AAChB,sIAAA,+BAA+B,OAAA;AAEjC,0CAAoD;AAA3C,kHAA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,qCAAqC,OAAA;AACrC,4HAAA,8BAA8B,OAAA;AAC9B,kHAAA,oBAAoB,OAAA;AACpB,yHAAA,2BAA2B,OAAA","sourcesContent":["// Main controller export\nexport {\n AssetsController,\n getDefaultAssetsControllerState,\n} from './AssetsController.js';\nexport { AssetsDataSourceError } from './errors.js';\nexport {\n DEFAULT_TRACKED_ASSETS_BY_CHAIN,\n CHAINS_WITH_DEFAULT_TRACKED_ASSETS,\n DEFAULT_ASSET_METADATA,\n buildDefaultAssetsInfo,\n getDefaultTrackedAssetsForChain,\n getDefaultAssetMetadata,\n} from './defaults.js';\nexport type { PendingTokenMetadata } from './AssetsController.js';\n\n// Snaps → AssetsController assets migration\nexport {\n SNAPS_ASSETS_MIGRATION_FLAG_KEYS,\n SNAPS_ASSETS_MIGRATION_NAMESPACES,\n SnapsAssetsMigrationStage,\n getSnapsAssetsMigrationNamespace,\n isMigrationStageActive,\n isSnapsAssetsMigrationNamespace,\n parseSnapsAssetsMigrationStage,\n} from './utils/snaps-assets-migration.js';\nexport type { SnapsAssetsMigrationNamespace } from './utils/snaps-assets-migration.js';\n\n// State and messenger types\nexport type {\n AssetsControllerState,\n AssetsControllerMessenger,\n AssetsControllerOptions,\n AssetsControllerGetStateAction,\n AssetsControllerActions,\n AssetsControllerStateChangeEvent,\n AssetsControllerBalanceChangedEvent,\n AssetsControllerPriceChangedEvent,\n AssetsControllerAssetsDetectedEvent,\n AssetsControllerEvents,\n} from './AssetsController.js';\nexport type {\n AssetsControllerGetAssetsAction,\n AssetsControllerGetAssetsBalanceAction,\n AssetsControllerGetAssetMetadataAction,\n AssetsControllerGetAccountAssetByIDAction,\n AssetsControllerGetAccountAssetsByIDsAction,\n AssetsControllerGetAccountAssetsByScopeAction,\n AssetsControllerGetAssetsPriceAction,\n AssetsControllerAddCustomAssetAction,\n AssetsControllerRemoveCustomAssetAction,\n AssetsControllerGetCustomAssetsAction,\n AssetsControllerHideAssetAction,\n AssetsControllerUnhideAssetAction,\n AssetsControllerGetExchangeRatesForBridgeAction,\n AssetsControllerGetStateForTransactionPayAction,\n AssetsControllerSetSelectedCurrencyAction,\n} from './AssetsController-method-action-types.js';\n\n// Core types\nexport type {\n // CAIP types\n Caip19AssetId,\n AccountId,\n ChainId,\n // Asset types\n AssetType,\n TokenStandard,\n // Contract data types\n TokenFees,\n HoneypotStatus,\n StorageSlots,\n LocalizedDescription,\n // Metadata types\n BaseAssetMetadata,\n FungibleAssetMetadata,\n ERC721AssetMetadata,\n ERC1155AssetMetadata,\n AssetMetadata,\n // Price types\n BaseAssetPrice,\n FungibleAssetPrice,\n NFTAssetPrice,\n AssetPrice,\n // Balance types\n FungibleAssetBalance,\n ERC721AssetBalance,\n ERC1155AssetBalance,\n AssetBalance,\n // Data source types\n AccountWithSupportedChains,\n DataType,\n DataRequest,\n DataResponse,\n AssetsUpdateMode,\n // Middleware types\n Context,\n NextFunction,\n Middleware,\n AssetsDataSource,\n FetchContext,\n FetchNextFunction,\n FetchMiddleware,\n SubscriptionResponse,\n // Combined asset type\n Asset,\n // Event types\n BalanceChangeEvent,\n PriceChangeEvent,\n MetadataChangeEvent,\n AssetsDetectedEvent,\n} from './types.js';\n\n// Data sources - base class and types\nexport { AbstractDataSource } from './data-sources/index.js';\n\nexport type {\n DataSourceState,\n SubscriptionRequest,\n} from './data-sources/index.js';\n\n// Data sources - AccountsApi\nexport { AccountsApiDataSource } from './data-sources/index.js';\n\nexport type {\n AccountsApiDataSourceConfig,\n AccountsApiDataSourceOptions,\n AccountsApiDataSourceState,\n} from './data-sources/index.js';\n\n// Data sources - RPC\nexport { RpcDataSource, createRpcDataSource } from './data-sources/index.js';\n\nexport type {\n RpcDataSourceConfig,\n RpcDataSourceOptions,\n RpcDataSourceState,\n ChainStatus,\n} from './data-sources/index.js';\n\n// Data sources - Unified Snap Data Source (dynamically discovers keyring snaps)\nexport {\n SnapDataSource,\n createSnapDataSource,\n SNAP_DATA_SOURCE_NAME,\n // Constants\n KEYRING_PERMISSION,\n // Utility functions\n getChainIdsCaveat,\n extractChainFromAssetId,\n} from './data-sources/index.js';\n\nexport type {\n SnapDataSourceState,\n SnapDataSourceOptions,\n} from './data-sources/index.js';\n\n// Enrichment data sources\nexport { TokenDataSource, PriceDataSource } from './data-sources/index.js';\n\nexport type {\n TokenDataSourceOptions,\n PriceDataSourceConfig,\n PriceDataSourceOptions,\n} from './data-sources/index.js';\n\n// Middlewares\nexport {\n CustomAssetGraduationMiddleware,\n DetectionMiddleware,\n RpcFallbackMiddleware,\n} from './middlewares/index.js';\nexport type {\n CustomAssetGraduationMiddlewareOptions,\n DetectionMiddlewareOptions,\n RpcFallbackMiddlewareOptions,\n} from './middlewares/index.js';\n\n// Utilities\nexport {\n normalizeAssetId,\n formatExchangeRatesForBridge,\n formatStateForTransactionPay,\n} from './utils/index.js';\nexport type {\n AccountForLegacyFormat,\n BridgeExchangeRatesFormat,\n FormatExchangeRatesForBridgeParams,\n FormatStateForTransactionPayParams,\n LegacyToken,\n TransactionPayLegacyFormat,\n} from './utils/index.js';\n\n// Selectors\nexport {\n calculateBalanceForAllWallets,\n calculateBalanceChangeForAccountGroup,\n getAggregatedBalanceForAccount,\n getGroupIdForAccount,\n getInternalAccountsForGroup,\n} from './selectors/balance.js';\n\nexport type {\n AccountGroupBalance,\n AccountsById,\n AggregatedBalanceEntry,\n AggregatedBalanceForAccount,\n AllWalletsBalance,\n BalanceChangePeriod,\n BalanceChangeResult,\n EnabledNetworkMap,\n WalletBalance,\n} from './selectors/balance.js';\n"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -18,7 +18,7 @@ export type { SnapDataSourceState, SnapDataSourceOptions, } from "./data-sources
|
|
|
18
18
|
export { TokenDataSource, PriceDataSource } from "./data-sources/index.cjs";
|
|
19
19
|
export type { TokenDataSourceOptions, PriceDataSourceConfig, PriceDataSourceOptions, } from "./data-sources/index.cjs";
|
|
20
20
|
export { CustomAssetGraduationMiddleware, DetectionMiddleware, RpcFallbackMiddleware, } from "./middlewares/index.cjs";
|
|
21
|
-
export type { CustomAssetGraduationMiddlewareOptions, RpcFallbackMiddlewareOptions, } from "./middlewares/index.cjs";
|
|
21
|
+
export type { CustomAssetGraduationMiddlewareOptions, DetectionMiddlewareOptions, RpcFallbackMiddlewareOptions, } from "./middlewares/index.cjs";
|
|
22
22
|
export { normalizeAssetId, formatExchangeRatesForBridge, formatStateForTransactionPay, } from "./utils/index.cjs";
|
|
23
23
|
export type { AccountForLegacyFormat, BridgeExchangeRatesFormat, FormatExchangeRatesForBridgeParams, FormatStateForTransactionPayParams, LegacyToken, TransactionPayLegacyFormat, } from "./utils/index.cjs";
|
|
24
24
|
export { calculateBalanceForAllWallets, calculateBalanceChangeForAccountGroup, getAggregatedBalanceForAccount, getGroupIdForAccount, getInternalAccountsForGroup, } from "./selectors/balance.cjs";
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,gBAAgB,EAChB,+BAA+B,GAChC,+BAA8B;AAC/B,OAAO,EAAE,qBAAqB,EAAE,qBAAoB;AACpD,OAAO,EACL,+BAA+B,EAC/B,kCAAkC,EAClC,sBAAsB,EACtB,sBAAsB,EACtB,+BAA+B,EAC/B,uBAAuB,GACxB,uBAAsB;AACvB,YAAY,EAAE,oBAAoB,EAAE,+BAA8B;AAGlE,OAAO,EACL,gCAAgC,EAChC,iCAAiC,EACjC,yBAAyB,EACzB,gCAAgC,EAChC,sBAAsB,EACtB,+BAA+B,EAC/B,8BAA8B,GAC/B,2CAA0C;AAC3C,YAAY,EAAE,6BAA6B,EAAE,2CAA0C;AAGvF,YAAY,EACV,qBAAqB,EACrB,yBAAyB,EACzB,uBAAuB,EACvB,8BAA8B,EAC9B,uBAAuB,EACvB,gCAAgC,EAChC,mCAAmC,EACnC,iCAAiC,EACjC,mCAAmC,EACnC,sBAAsB,GACvB,+BAA8B;AAC/B,YAAY,EACV,+BAA+B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AE7E,YAAY,EACV,mBAAmB,EACnB,oBAAoB,EACpB,kBAAkB,EAClB,WAAW,GACZ,iCAAgC;AAGjC,OAAO,EACL,cAAc,EACd,oBAAoB,EACpB,qBAAqB,EAErB,kBAAkB,EAElB,iBAAiB,EACjB,uBAAuB,GACxB,iCAAgC;AAEjC,YAAY,EACV,mBAAmB,EACnB,qBAAqB,GACtB,iCAAgC;AAGjC,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,iCAAgC;AAE3E,YAAY,EACV,sBAAsB,EACtB,qBAAqB,EACrB,sBAAsB,GACvB,iCAAgC;AAGjC,OAAO,EACL,+BAA+B,EAC/B,mBAAmB,EACnB,qBAAqB,GACtB,gCAA+B;AAChC,YAAY,EACV,sCAAsC,EACtC,0BAA0B,EAC1B,4BAA4B,GAC7B,gCAA+B;AAGhC,OAAO,EACL,gBAAgB,EAChB,4BAA4B,EAC5B,4BAA4B,GAC7B,0BAAyB;AAC1B,YAAY,EACV,sBAAsB,EACtB,yBAAyB,EACzB,kCAAkC,EAClC,kCAAkC,EAClC,WAAW,EACX,0BAA0B,GAC3B,0BAAyB;AAG1B,OAAO,EACL,6BAA6B,EAC7B,qCAAqC,EACrC,8BAA8B,EAC9B,oBAAoB,EACpB,2BAA2B,GAC5B,gCAA+B;AAEhC,YAAY,EACV,mBAAmB,EACnB,YAAY,EACZ,sBAAsB,EACtB,2BAA2B,EAC3B,iBAAiB,EACjB,mBAAmB,EACnB,mBAAmB,EACnB,iBAAiB,EACjB,aAAa,GACd,gCAA+B"}
|
package/dist/index.d.mts
CHANGED
|
@@ -18,7 +18,7 @@ export type { SnapDataSourceState, SnapDataSourceOptions, } from "./data-sources
|
|
|
18
18
|
export { TokenDataSource, PriceDataSource } from "./data-sources/index.mjs";
|
|
19
19
|
export type { TokenDataSourceOptions, PriceDataSourceConfig, PriceDataSourceOptions, } from "./data-sources/index.mjs";
|
|
20
20
|
export { CustomAssetGraduationMiddleware, DetectionMiddleware, RpcFallbackMiddleware, } from "./middlewares/index.mjs";
|
|
21
|
-
export type { CustomAssetGraduationMiddlewareOptions, RpcFallbackMiddlewareOptions, } from "./middlewares/index.mjs";
|
|
21
|
+
export type { CustomAssetGraduationMiddlewareOptions, DetectionMiddlewareOptions, RpcFallbackMiddlewareOptions, } from "./middlewares/index.mjs";
|
|
22
22
|
export { normalizeAssetId, formatExchangeRatesForBridge, formatStateForTransactionPay, } from "./utils/index.mjs";
|
|
23
23
|
export type { AccountForLegacyFormat, BridgeExchangeRatesFormat, FormatExchangeRatesForBridgeParams, FormatStateForTransactionPayParams, LegacyToken, TransactionPayLegacyFormat, } from "./utils/index.mjs";
|
|
24
24
|
export { calculateBalanceForAllWallets, calculateBalanceChangeForAccountGroup, getAggregatedBalanceForAccount, getGroupIdForAccount, getInternalAccountsForGroup, } from "./selectors/balance.mjs";
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,gBAAgB,EAChB,+BAA+B,GAChC,+BAA8B;AAC/B,OAAO,EAAE,qBAAqB,EAAE,qBAAoB;AACpD,OAAO,EACL,+BAA+B,EAC/B,kCAAkC,EAClC,sBAAsB,EACtB,sBAAsB,EACtB,+BAA+B,EAC/B,uBAAuB,GACxB,uBAAsB;AACvB,YAAY,EAAE,oBAAoB,EAAE,+BAA8B;AAGlE,OAAO,EACL,gCAAgC,EAChC,iCAAiC,EACjC,yBAAyB,EACzB,gCAAgC,EAChC,sBAAsB,EACtB,+BAA+B,EAC/B,8BAA8B,GAC/B,2CAA0C;AAC3C,YAAY,EAAE,6BAA6B,EAAE,2CAA0C;AAGvF,YAAY,EACV,qBAAqB,EACrB,yBAAyB,EACzB,uBAAuB,EACvB,8BAA8B,EAC9B,uBAAuB,EACvB,gCAAgC,EAChC,mCAAmC,EACnC,iCAAiC,EACjC,mCAAmC,EACnC,sBAAsB,GACvB,+BAA8B;AAC/B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ACxB,iCAAgC;AAEjC,YAAY,EACV,mBAAmB,EACnB,qBAAqB,GACtB,iCAAgC;AAGjC,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,iCAAgC;AAE3E,YAAY,EACV,sBAAsB,EACtB,qBAAqB,EACrB,sBAAsB,GACvB,iCAAgC;AAGjC,OAAO,EACL,+BAA+B,EAC/B,mBAAmB,EACnB,qBAAqB,GACtB,gCAA+B;AAChC,YAAY,EACV,sCAAsC,EACtC,4BAA4B,GAC7B,gCAA+B;AAGhC,OAAO,EACL,gBAAgB,EAChB,4BAA4B,EAC5B,4BAA4B,GAC7B,0BAAyB;AAC1B,YAAY,EACV,sBAAsB,EACtB,yBAAyB,EACzB,kCAAkC,EAClC,kCAAkC,EAClC,WAAW,EACX,0BAA0B,GAC3B,0BAAyB;AAG1B,OAAO,EACL,6BAA6B,EAC7B,qCAAqC,EACrC,8BAA8B,EAC9B,oBAAoB,EACpB,2BAA2B,GAC5B,gCAA+B;AAEhC,YAAY,EACV,mBAAmB,EACnB,YAAY,EACZ,sBAAsB,EACtB,2BAA2B,EAC3B,iBAAiB,EACjB,mBAAmB,EACnB,mBAAmB,EACnB,iBAAiB,EACjB,aAAa,GACd,gCAA+B"}
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,gBAAgB,EAChB,+BAA+B,GAChC,+BAA8B;AAC/B,OAAO,EAAE,qBAAqB,EAAE,qBAAoB;AACpD,OAAO,EACL,+BAA+B,EAC/B,kCAAkC,EAClC,sBAAsB,EACtB,sBAAsB,EACtB,+BAA+B,EAC/B,uBAAuB,GACxB,uBAAsB;AACvB,YAAY,EAAE,oBAAoB,EAAE,+BAA8B;AAGlE,OAAO,EACL,gCAAgC,EAChC,iCAAiC,EACjC,yBAAyB,EACzB,gCAAgC,EAChC,sBAAsB,EACtB,+BAA+B,EAC/B,8BAA8B,GAC/B,2CAA0C;AAC3C,YAAY,EAAE,6BAA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mB,EAAE,iCAAgC;AAE7E,YAAY,EACV,mBAAmB,EACnB,oBAAoB,EACpB,kBAAkB,EAClB,WAAW,GACZ,iCAAgC;AAGjC,OAAO,EACL,cAAc,EACd,oBAAoB,EACpB,qBAAqB,EAErB,kBAAkB,EAElB,iBAAiB,EACjB,uBAAuB,GACxB,iCAAgC;AAEjC,YAAY,EACV,mBAAmB,EACnB,qBAAqB,GACtB,iCAAgC;AAGjC,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,iCAAgC;AAE3E,YAAY,EACV,sBAAsB,EACtB,qBAAqB,EACrB,sBAAsB,GACvB,iCAAgC;AAGjC,OAAO,EACL,+BAA+B,EAC/B,mBAAmB,EACnB,qBAAqB,GACtB,gCAA+B;AAChC,YAAY,EACV,sCAAsC,EACtC,0BAA0B,EAC1B,4BAA4B,GAC7B,gCAA+B;AAGhC,OAAO,EACL,gBAAgB,EAChB,4BAA4B,EAC5B,4BAA4B,GAC7B,0BAAyB;AAC1B,YAAY,EACV,sBAAsB,EACtB,yBAAyB,EACzB,kCAAkC,EAClC,kCAAkC,EAClC,WAAW,EACX,0BAA0B,GAC3B,0BAAyB;AAG1B,OAAO,EACL,6BAA6B,EAC7B,qCAAqC,EACrC,8BAA8B,EAC9B,oBAAoB,EACpB,2BAA2B,GAC5B,gCAA+B;AAEhC,YAAY,EACV,mBAAmB,EACnB,YAAY,EACZ,sBAAsB,EACtB,2BAA2B,EAC3B,iBAAiB,EACjB,mBAAmB,EACnB,mBAAmB,EACnB,iBAAiB,EACjB,aAAa,GACd,gCAA+B"}
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,yBAAyB;AACzB,OAAO,EACL,gBAAgB,EAChB,+BAA+B,EAChC,+BAA8B;AAC/B,OAAO,EAAE,qBAAqB,EAAE,qBAAoB;AACpD,OAAO,EACL,+BAA+B,EAC/B,kCAAk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AO,EAAE,qBAAqB,EAAE,iCAAgC;AAQhE,qBAAqB;AACrB,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,iCAAgC;AAS7E,gFAAgF;AAChF,OAAO,EACL,cAAc,EACd,oBAAoB,EACpB,qBAAqB;AACrB,YAAY;AACZ,kBAAkB;AAClB,oBAAoB;AACpB,iBAAiB,EACjB,uBAAuB,EACxB,iCAAgC;AAOjC,0BAA0B;AAC1B,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,iCAAgC;AAQ3E,cAAc;AACd,OAAO,EACL,+BAA+B,EAC/B,mBAAmB,EACnB,qBAAqB,EACtB,gCAA+B;AAOhC,YAAY;AACZ,OAAO,EACL,gBAAgB,EAChB,4BAA4B,EAC5B,4BAA4B,EAC7B,0BAAyB;AAU1B,YAAY;AACZ,OAAO,EACL,6BAA6B,EAC7B,qCAAqC,EACrC,8BAA8B,EAC9B,oBAAoB,EACpB,2BAA2B,EAC5B,gCAA+B","sourcesContent":["// Main controller export\nexport {\n AssetsController,\n getDefaultAssetsControllerState,\n} from './AssetsController.js';\nexport { AssetsDataSourceError } from './errors.js';\nexport {\n DEFAULT_TRACKED_ASSETS_BY_CHAIN,\n CHAINS_WITH_DEFAULT_TRACKED_ASSETS,\n DEFAULT_ASSET_METADATA,\n buildDefaultAssetsInfo,\n getDefaultTrackedAssetsForChain,\n getDefaultAssetMetadata,\n} from './defaults.js';\nexport type { PendingTokenMetadata } from './AssetsController.js';\n\n// Snaps → AssetsController assets migration\nexport {\n SNAPS_ASSETS_MIGRATION_FLAG_KEYS,\n SNAPS_ASSETS_MIGRATION_NAMESPACES,\n SnapsAssetsMigrationStage,\n getSnapsAssetsMigrationNamespace,\n isMigrationStageActive,\n isSnapsAssetsMigrationNamespace,\n parseSnapsAssetsMigrationStage,\n} from './utils/snaps-assets-migration.js';\nexport type { SnapsAssetsMigrationNamespace } from './utils/snaps-assets-migration.js';\n\n// State and messenger types\nexport type {\n AssetsControllerState,\n AssetsControllerMessenger,\n AssetsControllerOptions,\n AssetsControllerGetStateAction,\n AssetsControllerActions,\n AssetsControllerStateChangeEvent,\n AssetsControllerBalanceChangedEvent,\n AssetsControllerPriceChangedEvent,\n AssetsControllerAssetsDetectedEvent,\n AssetsControllerEvents,\n} from './AssetsController.js';\nexport type {\n AssetsControllerGetAssetsAction,\n AssetsControllerGetAssetsBalanceAction,\n AssetsControllerGetAssetMetadataAction,\n AssetsControllerGetAccountAssetByIDAction,\n AssetsControllerGetAccountAssetsByIDsAction,\n AssetsControllerGetAccountAssetsByScopeAction,\n AssetsControllerGetAssetsPriceAction,\n AssetsControllerAddCustomAssetAction,\n AssetsControllerRemoveCustomAssetAction,\n AssetsControllerGetCustomAssetsAction,\n AssetsControllerHideAssetAction,\n AssetsControllerUnhideAssetAction,\n AssetsControllerGetExchangeRatesForBridgeAction,\n AssetsControllerGetStateForTransactionPayAction,\n AssetsControllerSetSelectedCurrencyAction,\n} from './AssetsController-method-action-types.js';\n\n// Core types\nexport type {\n // CAIP types\n Caip19AssetId,\n AccountId,\n ChainId,\n // Asset types\n AssetType,\n TokenStandard,\n // Contract data types\n TokenFees,\n HoneypotStatus,\n StorageSlots,\n LocalizedDescription,\n // Metadata types\n BaseAssetMetadata,\n FungibleAssetMetadata,\n ERC721AssetMetadata,\n ERC1155AssetMetadata,\n AssetMetadata,\n // Price types\n BaseAssetPrice,\n FungibleAssetPrice,\n NFTAssetPrice,\n AssetPrice,\n // Balance types\n FungibleAssetBalance,\n ERC721AssetBalance,\n ERC1155AssetBalance,\n AssetBalance,\n // Data source types\n AccountWithSupportedChains,\n DataType,\n DataRequest,\n DataResponse,\n AssetsUpdateMode,\n // Middleware types\n Context,\n NextFunction,\n Middleware,\n AssetsDataSource,\n FetchContext,\n FetchNextFunction,\n FetchMiddleware,\n SubscriptionResponse,\n // Combined asset type\n Asset,\n // Event types\n BalanceChangeEvent,\n PriceChangeEvent,\n MetadataChangeEvent,\n AssetsDetectedEvent,\n} from './types.js';\n\n// Data sources - base class and types\nexport { AbstractDataSource } from './data-sources/index.js';\n\nexport type {\n DataSourceState,\n SubscriptionRequest,\n} from './data-sources/index.js';\n\n// Data sources - AccountsApi\nexport { AccountsApiDataSource } from './data-sources/index.js';\n\nexport type {\n AccountsApiDataSourceConfig,\n AccountsApiDataSourceOptions,\n AccountsApiDataSourceState,\n} from './data-sources/index.js';\n\n// Data sources - RPC\nexport { RpcDataSource, createRpcDataSource } from './data-sources/index.js';\n\nexport type {\n RpcDataSourceConfig,\n RpcDataSourceOptions,\n RpcDataSourceState,\n ChainStatus,\n} from './data-sources/index.js';\n\n// Data sources - Unified Snap Data Source (dynamically discovers keyring snaps)\nexport {\n SnapDataSource,\n createSnapDataSource,\n SNAP_DATA_SOURCE_NAME,\n // Constants\n KEYRING_PERMISSION,\n // Utility functions\n getChainIdsCaveat,\n extractChainFromAssetId,\n} from './data-sources/index.js';\n\nexport type {\n SnapDataSourceState,\n SnapDataSourceOptions,\n} from './data-sources/index.js';\n\n// Enrichment data sources\nexport { TokenDataSource, PriceDataSource } from './data-sources/index.js';\n\nexport type {\n TokenDataSourceOptions,\n PriceDataSourceConfig,\n PriceDataSourceOptions,\n} from './data-sources/index.js';\n\n// Middlewares\nexport {\n CustomAssetGraduationMiddleware,\n DetectionMiddleware,\n RpcFallbackMiddleware,\n} from './middlewares/index.js';\nexport type {\n CustomAssetGraduationMiddlewareOptions,\n DetectionMiddlewareOptions,\n RpcFallbackMiddlewareOptions,\n} from './middlewares/index.js';\n\n// Utilities\nexport {\n normalizeAssetId,\n formatExchangeRatesForBridge,\n formatStateForTransactionPay,\n} from './utils/index.js';\nexport type {\n AccountForLegacyFormat,\n BridgeExchangeRatesFormat,\n FormatExchangeRatesForBridgeParams,\n FormatStateForTransactionPayParams,\n LegacyToken,\n TransactionPayLegacyFormat,\n} from './utils/index.js';\n\n// Selectors\nexport {\n calculateBalanceForAllWallets,\n calculateBalanceChangeForAccountGroup,\n getAggregatedBalanceForAccount,\n getGroupIdForAccount,\n getInternalAccountsForGroup,\n} from './selectors/balance.js';\n\nexport type {\n AccountGroupBalance,\n AccountsById,\n AggregatedBalanceEntry,\n AggregatedBalanceForAccount,\n AllWalletsBalance,\n BalanceChangePeriod,\n BalanceChangeResult,\n EnabledNetworkMap,\n WalletBalance,\n} from './selectors/balance.js';\n"]}
|
|
@@ -1,40 +1,53 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
+
};
|
|
8
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
+
};
|
|
13
|
+
var _DetectionMiddleware_isTokenDetectionEnabled;
|
|
2
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
15
|
exports.DetectionMiddleware = void 0;
|
|
16
|
+
const utils_1 = require("@metamask/utils");
|
|
17
|
+
const index_js_1 = require("../data-sources/evm-rpc-services/index.cjs");
|
|
18
|
+
const TokenDataSource_js_1 = require("../data-sources/TokenDataSource.cjs");
|
|
4
19
|
const logger_js_1 = require("../logger.cjs");
|
|
5
20
|
const types_js_1 = require("../types.cjs");
|
|
6
|
-
const
|
|
21
|
+
const index_js_2 = require("../utils/index.cjs");
|
|
7
22
|
// ============================================================================
|
|
8
23
|
// CONSTANTS
|
|
9
24
|
// ============================================================================
|
|
10
25
|
const CONTROLLER_NAME = 'DetectionMiddleware';
|
|
11
|
-
|
|
12
|
-
(0, logger_js_1.createModuleLogger)(logger_js_1.projectLogger, CONTROLLER_NAME);
|
|
13
|
-
// ============================================================================
|
|
14
|
-
// DETECTION MIDDLEWARE
|
|
15
|
-
// ============================================================================
|
|
26
|
+
const log = (0, logger_js_1.createModuleLogger)(logger_js_1.projectLogger, CONTROLLER_NAME);
|
|
16
27
|
/**
|
|
17
|
-
*
|
|
18
|
-
*
|
|
28
|
+
* Whether an asset is subject to the token-detection toggle: fungible tokens
|
|
29
|
+
* (EVM `erc20`, non-EVM `token` — SPL, TRC, etc.). Natives (`slip44`),
|
|
30
|
+
* staking-contract assets, and anything unparseable are never gated.
|
|
19
31
|
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* from BOTH `state.assetsBalance` (never tracked before) AND `state.assetsInfo`
|
|
23
|
-
* (no metadata yet). Assets already present in either collection are considered
|
|
24
|
-
* known and are intentionally excluded — PriceDataSource's own subscription
|
|
25
|
-
* handles periodic refreshes for those.
|
|
26
|
-
* - Each account's custom assets from state are always included because they
|
|
27
|
-
* may have no balance yet and are explicitly managed by the user.
|
|
28
|
-
*
|
|
29
|
-
* Usage:
|
|
30
|
-
* ```typescript
|
|
31
|
-
* const detectionMiddleware = new DetectionMiddleware();
|
|
32
|
-
* const middleware = detectionMiddleware.assetsMiddleware;
|
|
33
|
-
* ```
|
|
32
|
+
* @param assetId - The CAIP-19 asset ID to classify.
|
|
33
|
+
* @returns `true` when the asset should be blocked while detection is off.
|
|
34
34
|
*/
|
|
35
|
+
function isDetectionGatedAsset(assetId) {
|
|
36
|
+
try {
|
|
37
|
+
const { assetNamespace } = (0, utils_1.parseCaipAssetType)(assetId);
|
|
38
|
+
return ((assetNamespace === TokenDataSource_js_1.CaipAssetNamespace.Erc20 ||
|
|
39
|
+
assetNamespace === TokenDataSource_js_1.CaipAssetNamespace.Token) &&
|
|
40
|
+
!(0, index_js_1.isStakingContractAssetId)(assetId));
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
35
46
|
class DetectionMiddleware {
|
|
36
|
-
constructor() {
|
|
47
|
+
constructor(options = {}) {
|
|
37
48
|
this.name = CONTROLLER_NAME;
|
|
49
|
+
_DetectionMiddleware_isTokenDetectionEnabled.set(this, void 0);
|
|
50
|
+
__classPrivateFieldSet(this, _DetectionMiddleware_isTokenDetectionEnabled, options.isTokenDetectionEnabled ?? (() => true), "f");
|
|
38
51
|
}
|
|
39
52
|
getName() {
|
|
40
53
|
return this.name;
|
|
@@ -60,12 +73,31 @@ class DetectionMiddleware {
|
|
|
60
73
|
const state = ctx.getAssetsState();
|
|
61
74
|
const { customAssets: stateCustomAssets, assetsBalance: stateAssetsBalance, assetsInfo: stateAssetsInfo, assetsPrice: stateAssetsPrice, } = state;
|
|
62
75
|
const detectedAssets = {};
|
|
76
|
+
const detectionEnabled = __classPrivateFieldGet(this, _DetectionMiddleware_isTokenDetectionEnabled, "f").call(this);
|
|
77
|
+
// Lower-cased asset IDs stripped from the response because token
|
|
78
|
+
// detection is off; used to purge their stub metadata afterwards.
|
|
79
|
+
const strippedAssetIds = new Set();
|
|
80
|
+
// Lower-cased state metadata keys, built lazily (only when detection is
|
|
81
|
+
// off) so the destructive strip below cannot misfire on a known holding
|
|
82
|
+
// reported by a source in a different address case.
|
|
83
|
+
let knownMetadataLower = null;
|
|
84
|
+
const getKnownMetadataLower = () => {
|
|
85
|
+
knownMetadataLower ?? (knownMetadataLower = new Set(Object.keys(stateAssetsInfo).map((id) => id.toLowerCase())));
|
|
86
|
+
return knownMetadataLower;
|
|
87
|
+
};
|
|
63
88
|
// 1. From balance response: only include assets that are genuinely new —
|
|
64
89
|
// not already present in state.assetsBalance or state.assetsInfo.
|
|
65
90
|
if (response.assetsBalance) {
|
|
66
91
|
for (const [accountId, accountBalances] of Object.entries(response.assetsBalance)) {
|
|
67
92
|
const detected = [];
|
|
68
93
|
const stateAccountBalances = stateAssetsBalance[accountId] ?? {};
|
|
94
|
+
const customForAccount = stateCustomAssets?.[accountId] ?? [];
|
|
95
|
+
const customLowerIds = detectionEnabled
|
|
96
|
+
? null
|
|
97
|
+
: new Set(customForAccount.map((id) => id.toLowerCase()));
|
|
98
|
+
const knownBalanceLower = detectionEnabled
|
|
99
|
+
? null
|
|
100
|
+
: new Set(Object.keys(stateAccountBalances).map((id) => id.toLowerCase()));
|
|
69
101
|
for (const assetId of Object.keys(accountBalances)) {
|
|
70
102
|
const caipAssetId = assetId;
|
|
71
103
|
// Skip if already tracked in state balances or already has metadata
|
|
@@ -73,11 +105,25 @@ class DetectionMiddleware {
|
|
|
73
105
|
stateAssetsInfo[caipAssetId] !== undefined) {
|
|
74
106
|
continue;
|
|
75
107
|
}
|
|
108
|
+
// Token detection off: new-to-state fungible tokens (erc20 / SPL
|
|
109
|
+
// and similar `token` namespaces) are neither detected nor
|
|
110
|
+
// persisted. Natives, staking contracts, custom assets, and
|
|
111
|
+
// holdings already known to state (any address case) still flow.
|
|
112
|
+
if (!detectionEnabled &&
|
|
113
|
+
isDetectionGatedAsset(assetId) &&
|
|
114
|
+
!customLowerIds?.has(assetId.toLowerCase())) {
|
|
115
|
+
const lowerId = assetId.toLowerCase();
|
|
116
|
+
if (!knownBalanceLower?.has(lowerId) &&
|
|
117
|
+
!getKnownMetadataLower().has(lowerId)) {
|
|
118
|
+
delete accountBalances[assetId];
|
|
119
|
+
strippedAssetIds.add(lowerId);
|
|
120
|
+
}
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
76
123
|
detected.push(caipAssetId);
|
|
77
124
|
}
|
|
78
125
|
// Merge custom assets for this account, applying the same filter:
|
|
79
126
|
// skip if already in state balance or already has metadata.
|
|
80
|
-
const customForAccount = stateCustomAssets?.[accountId] ?? [];
|
|
81
127
|
for (const assetId of customForAccount) {
|
|
82
128
|
if (detected.includes(assetId)) {
|
|
83
129
|
continue;
|
|
@@ -93,6 +139,22 @@ class DetectionMiddleware {
|
|
|
93
139
|
}
|
|
94
140
|
}
|
|
95
141
|
}
|
|
142
|
+
// Drop stub metadata (e.g. websocket-seeded name/symbol) of stripped
|
|
143
|
+
// tokens so it never persists to state — a persisted stub would make
|
|
144
|
+
// the token look "known" on the next update and let it bypass the
|
|
145
|
+
// detection gate.
|
|
146
|
+
if (strippedAssetIds.size > 0) {
|
|
147
|
+
if (response.assetsInfo) {
|
|
148
|
+
for (const assetId of Object.keys(response.assetsInfo)) {
|
|
149
|
+
if (strippedAssetIds.has(assetId.toLowerCase())) {
|
|
150
|
+
delete response.assetsInfo[assetId];
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
log('Token detection disabled - stripped new tokens from response', {
|
|
155
|
+
assetIds: [...strippedAssetIds],
|
|
156
|
+
});
|
|
157
|
+
}
|
|
96
158
|
// 2. Accounts in request that weren't in balance response: include their
|
|
97
159
|
// custom assets that are not yet in state.
|
|
98
160
|
for (const { account } of request.accountsWithSupportedChains) {
|
|
@@ -122,7 +184,7 @@ class DetectionMiddleware {
|
|
|
122
184
|
const prices = stateAssetsPrice;
|
|
123
185
|
const missingPriceAssets = new Set();
|
|
124
186
|
const maybeQueue = (assetId) => {
|
|
125
|
-
const normalizedAssetId = (0,
|
|
187
|
+
const normalizedAssetId = (0, index_js_2.normalizeAssetId)(assetId);
|
|
126
188
|
if (prices[normalizedAssetId] === undefined &&
|
|
127
189
|
prices[assetId] === undefined) {
|
|
128
190
|
missingPriceAssets.add(normalizedAssetId);
|
|
@@ -151,4 +213,5 @@ class DetectionMiddleware {
|
|
|
151
213
|
}
|
|
152
214
|
}
|
|
153
215
|
exports.DetectionMiddleware = DetectionMiddleware;
|
|
216
|
+
_DetectionMiddleware_isTokenDetectionEnabled = new WeakMap();
|
|
154
217
|
//# sourceMappingURL=DetectionMiddleware.c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,EAAE,CAAC;gBAC5D,KAAK,MAAM,OAAO,IAAI,eAAe,EAAE,CAAC;oBACtC,UAAU,CAAC,OAAO,CAAC,CAAC;gBACtB,CAAC;YACH,CAAC;YAED,IAAI,QAAQ,CAAC,aAAa,EAAE,CAAC;gBAC3B,KAAK,MAAM,eAAe,IAAI,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAC,EAAE,CAAC;oBACpE,KAAK,MAAM,OAAO,IAAI,MAAM,CAAC,IAAI,CAC/B,eAA0C,CAC3C,EAAE,CAAC;wBACF,UAAU,CAAC,OAAwB,CAAC,CAAC;oBACvC,CAAC;gBACH,CAAC;YACH,CAAC;YAED,IAAI,kBAAkB,CAAC,IAAI,GAAG,CAAC,EAAE,CAAC;gBAChC,OAAO,CAAC,oBAAoB,GAAG;oBAC7B,GAAG,CAAC,OAAO,CAAC,oBAAoB,IAAI,EAAE,CAAC;oBACvC,GAAG,kBAAkB;iBACtB,CAAC;YACJ,CAAC;YAED,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;QACnB,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AArJD,kDAqJC","sourcesContent":["import { projectLogger, createModuleLogger } from '../logger.js';\nimport { forDataTypes } from '../types.js';\nimport type { AccountId, Caip19AssetId, Middleware } from '../types.js';\nimport { normalizeAssetId } from '../utils/index.js';\n\n// ============================================================================\n// CONSTANTS\n// ============================================================================\n\nconst CONTROLLER_NAME = 'DetectionMiddleware';\n\n// Logger for debugging\ncreateModuleLogger(projectLogger, CONTROLLER_NAME);\n\n// ============================================================================\n// DETECTION MIDDLEWARE\n// ============================================================================\n\n/**\n * DetectionMiddleware builds the set of assets that downstream sources use for\n * metadata and price fetching.\n *\n * An asset is included in `detectedAssets` only when it is genuinely new:\n * - Assets from `response.assetsBalance` are included only if they are absent\n * from BOTH `state.assetsBalance` (never tracked before) AND `state.assetsInfo`\n * (no metadata yet). Assets already present in either collection are considered\n * known and are intentionally excluded — PriceDataSource's own subscription\n * handles periodic refreshes for those.\n * - Each account's custom assets from state are always included because they\n * may have no balance yet and are explicitly managed by the user.\n *\n * Usage:\n * ```typescript\n * const detectionMiddleware = new DetectionMiddleware();\n * const middleware = detectionMiddleware.assetsMiddleware;\n * ```\n */\nexport class DetectionMiddleware {\n readonly name = CONTROLLER_NAME;\n\n getName(): string {\n return this.name;\n }\n\n /**\n * Get the middleware that builds detectedAssets for metadata and price fetching.\n *\n * This middleware:\n * 1. Includes assets from response.assetsBalance that are absent from both\n * state.assetsBalance and state.assetsInfo (brand-new assets only)\n * 2. Always includes each account's custom assets from state\n * 3. Fills response.detectedAssets with the resulting asset IDs per account\n * 4. Queues detected assets that lack a price in state on\n * request.assetsForPriceUpdate so PriceDataSource fetches them in the same\n * pipeline pass (including the background RPC detection path)\n *\n * @returns The middleware function for the assets pipeline.\n */\n get assetsMiddleware(): Middleware {\n return forDataTypes(['balance'], async (ctx, next) => {\n const { request, response } = ctx;\n\n // Get state for custom assets, existing balances, and existing metadata\n const state = ctx.getAssetsState();\n const {\n customAssets: stateCustomAssets,\n assetsBalance: stateAssetsBalance,\n assetsInfo: stateAssetsInfo,\n assetsPrice: stateAssetsPrice,\n } = state;\n\n const detectedAssets: Record<AccountId, Caip19AssetId[]> = {};\n\n // 1. From balance response: only include assets that are genuinely new —\n // not already present in state.assetsBalance or state.assetsInfo.\n if (response.assetsBalance) {\n for (const [accountId, accountBalances] of Object.entries(\n response.assetsBalance,\n )) {\n const detected: Caip19AssetId[] = [];\n\n const stateAccountBalances = stateAssetsBalance[accountId] ?? {};\n\n for (const assetId of Object.keys(\n accountBalances as Record<string, unknown>,\n )) {\n const caipAssetId = assetId as Caip19AssetId;\n // Skip if already tracked in state balances or already has metadata\n if (\n stateAccountBalances[caipAssetId] !== undefined ||\n stateAssetsInfo[caipAssetId] !== undefined\n ) {\n continue;\n }\n detected.push(caipAssetId);\n }\n\n // Merge custom assets for this account, applying the same filter:\n // skip if already in state balance or already has metadata.\n const customForAccount = stateCustomAssets?.[accountId] ?? [];\n for (const assetId of customForAccount) {\n if (detected.includes(assetId)) {\n continue;\n }\n if (\n stateAccountBalances[assetId] !== undefined ||\n stateAssetsInfo[assetId] !== undefined\n ) {\n continue;\n }\n detected.push(assetId);\n }\n\n if (detected.length > 0) {\n detectedAssets[accountId] = detected;\n }\n }\n }\n\n // 2. Accounts in request that weren't in balance response: include their\n // custom assets that are not yet in state.\n for (const { account } of request.accountsWithSupportedChains) {\n const accountId = account.id;\n if (detectedAssets[accountId]) {\n continue;\n }\n const stateAccountBalances = stateAssetsBalance[accountId] ?? {};\n const customForAccount = stateCustomAssets?.[accountId] ?? [];\n const newCustomAssets = customForAccount.filter((assetId) => {\n const inBalance = stateAccountBalances[assetId] !== undefined;\n const inInfo = stateAssetsInfo[assetId] !== undefined;\n return !inBalance && !inInfo;\n });\n if (newCustomAssets.length > 0) {\n detectedAssets[accountId] = newCustomAssets;\n }\n }\n\n if (Object.keys(detectedAssets).length > 0) {\n response.detectedAssets = detectedAssets;\n }\n\n // Queue prices for:\n // 1) newly detected assets missing a price, and\n // 2) assets in this balance response that already exist in state but still\n // lack a price (e.g. natives seeded before the first price poll).\n // PriceDataSource filters non-priceable IDs before calling the API.\n const prices = stateAssetsPrice as Record<string, unknown>;\n const missingPriceAssets = new Set<Caip19AssetId>();\n\n const maybeQueue = (assetId: Caip19AssetId): void => {\n const normalizedAssetId = normalizeAssetId(assetId);\n if (\n prices[normalizedAssetId] === undefined &&\n prices[assetId] === undefined\n ) {\n missingPriceAssets.add(normalizedAssetId);\n }\n };\n\n for (const accountAssetIds of Object.values(detectedAssets)) {\n for (const assetId of accountAssetIds) {\n maybeQueue(assetId);\n }\n }\n\n if (response.assetsBalance) {\n for (const accountBalances of Object.values(response.assetsBalance)) {\n for (const assetId of Object.keys(\n accountBalances as Record<string, unknown>,\n )) {\n maybeQueue(assetId as Caip19AssetId);\n }\n }\n }\n\n if (missingPriceAssets.size > 0) {\n request.assetsForPriceUpdate = [\n ...(request.assetsForPriceUpdate ?? []),\n ...missingPriceAssets,\n ];\n }\n\n return next(ctx);\n });\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"DetectionMiddleware.cjs","sourceRoot":"","sources":["../../src/middlewares/DetectionMiddleware.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAqD;AAErD,yEAAqF;AACrF,4EAAwE;AACxE,6CAAiE;AACjE,2CAA2C;AAE3C,iDAAqD;AAErD,+EAA+E;AAC/E,YAAY;AACZ,+EAA+E;AAE/E,MAAM,eAAe,GAAG,qBAAqB,CAAC;AAE9C,MAAM,GAAG,GAAG,IAAA,8BAAkB,EAAC,yBAAa,EAAE,eAAe,CAAC,CAAC;AAE/D;;;;;;;GAOG;AACH,SAAS,qBAAqB,CAAC,OAAe;IAC5C,IAAI,CAAC;QACH,MAAM,EAAE,cAAc,EAAE,GAAG,IAAA,0BAAkB,EAAC,OAAwB,CAAC,CAAC;QACxE,OAAO,CACL,CAAC,cAAc,KAAM,uCAAkB,CAAC,KAAgB;YACtD,cAAc,KAAM,uCAAkB,CAAC,KAAgB,CAAC;YAC1D,CAAC,IAAA,mCAAwB,EAAC,OAAO,CAAC,CACnC,CAAC;IACJ,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAyCD,MAAa,mBAAmB;IAK9B,YAAY,UAAsC,EAAE;QAJ3C,SAAI,GAAG,eAAe,CAAC;QAEvB,+DAAwC;QAG/C,uBAAA,IAAI,gDACF,OAAO,CAAC,uBAAuB,IAAI,CAAC,GAAY,EAAE,CAAC,IAAI,CAAC,MAAA,CAAC;IAC7D,CAAC;IAED,OAAO;QACL,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IAED;;;;;;;;;;;;;OAaG;IACH,IAAI,gBAAgB;QAClB,OAAO,IAAA,uBAAY,EAAC,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;YACnD,MAAM,EA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,KAAK,MAAM,eAAe,IAAI,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,EAAE,CAAC;gBAC5D,KAAK,MAAM,OAAO,IAAI,eAAe,EAAE,CAAC;oBACtC,UAAU,CAAC,OAAO,CAAC,CAAC;gBACtB,CAAC;YACH,CAAC;YAED,IAAI,QAAQ,CAAC,aAAa,EAAE,CAAC;gBAC3B,KAAK,MAAM,eAAe,IAAI,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAC,EAAE,CAAC;oBACpE,KAAK,MAAM,OAAO,IAAI,MAAM,CAAC,IAAI,CAC/B,eAA0C,CAC3C,EAAE,CAAC;wBACF,UAAU,CAAC,OAAwB,CAAC,CAAC;oBACvC,CAAC;gBACH,CAAC;YACH,CAAC;YAED,IAAI,kBAAkB,CAAC,IAAI,GAAG,CAAC,EAAE,CAAC;gBAChC,OAAO,CAAC,oBAAoB,GAAG;oBAC7B,GAAG,CAAC,OAAO,CAAC,oBAAoB,IAAI,EAAE,CAAC;oBACvC,GAAG,kBAAkB;iBACtB,CAAC;YACJ,CAAC;YAED,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;QACnB,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAzND,kDAyNC","sourcesContent":["import { parseCaipAssetType } from '@metamask/utils';\n\nimport { isStakingContractAssetId } from '../data-sources/evm-rpc-services/index.js';\nimport { CaipAssetNamespace } from '../data-sources/TokenDataSource.js';\nimport { projectLogger, createModuleLogger } from '../logger.js';\nimport { forDataTypes } from '../types.js';\nimport type { AccountId, Caip19AssetId, Middleware } from '../types.js';\nimport { normalizeAssetId } from '../utils/index.js';\n\n// ============================================================================\n// CONSTANTS\n// ============================================================================\n\nconst CONTROLLER_NAME = 'DetectionMiddleware';\n\nconst log = createModuleLogger(projectLogger, CONTROLLER_NAME);\n\n/**\n * Whether an asset is subject to the token-detection toggle: fungible tokens\n * (EVM `erc20`, non-EVM `token` — SPL, TRC, etc.). Natives (`slip44`),\n * staking-contract assets, and anything unparseable are never gated.\n *\n * @param assetId - The CAIP-19 asset ID to classify.\n * @returns `true` when the asset should be blocked while detection is off.\n */\nfunction isDetectionGatedAsset(assetId: string): boolean {\n try {\n const { assetNamespace } = parseCaipAssetType(assetId as Caip19AssetId);\n return (\n (assetNamespace === (CaipAssetNamespace.Erc20 as string) ||\n assetNamespace === (CaipAssetNamespace.Token as string)) &&\n !isStakingContractAssetId(assetId)\n );\n } catch {\n return false;\n }\n}\n\n// ============================================================================\n// DETECTION MIDDLEWARE\n// ============================================================================\n\n/**\n * DetectionMiddleware builds the set of assets that downstream sources use for\n * metadata and price fetching.\n *\n * An asset is included in `detectedAssets` only when it is genuinely new:\n * - Assets from `response.assetsBalance` are included only if they are absent\n * from BOTH `state.assetsBalance` (never tracked before) AND `state.assetsInfo`\n * (no metadata yet). Assets already present in either collection are considered\n * known and are intentionally excluded — PriceDataSource's own subscription\n * handles periodic refreshes for those.\n * - Each account's custom assets from state are always included because they\n * may have no balance yet and are explicitly managed by the user.\n *\n * When token detection is disabled (`isTokenDetectionEnabled` returns false),\n * new-to-state fungible tokens (`erc20` / `token` namespaces) are neither\n * detected nor persisted: their balances and stub metadata are stripped from\n * the response. Natives, staking-contract assets, custom (user-imported)\n * assets, and assets already tracked in state are unaffected.\n *\n * Usage:\n * ```typescript\n * const detectionMiddleware = new DetectionMiddleware();\n * const middleware = detectionMiddleware.assetsMiddleware;\n * ```\n */\n\n/** Constructor options for {@link DetectionMiddleware}. */\nexport type DetectionMiddlewareOptions = {\n /**\n * Whether automatic token detection is enabled (e.g. the user's\n * \"Autodetect tokens\" preference). Defaults to `() => true`.\n */\n isTokenDetectionEnabled?: () => boolean;\n};\n\nexport class DetectionMiddleware {\n readonly name = CONTROLLER_NAME;\n\n readonly #isTokenDetectionEnabled: () => boolean;\n\n constructor(options: DetectionMiddlewareOptions = {}) {\n this.#isTokenDetectionEnabled =\n options.isTokenDetectionEnabled ?? ((): boolean => true);\n }\n\n getName(): string {\n return this.name;\n }\n\n /**\n * Get the middleware that builds detectedAssets for metadata and price fetching.\n *\n * This middleware:\n * 1. Includes assets from response.assetsBalance that are absent from both\n * state.assetsBalance and state.assetsInfo (brand-new assets only)\n * 2. Always includes each account's custom assets from state\n * 3. Fills response.detectedAssets with the resulting asset IDs per account\n * 4. Queues detected assets that lack a price in state on\n * request.assetsForPriceUpdate so PriceDataSource fetches them in the same\n * pipeline pass (including the background RPC detection path)\n *\n * @returns The middleware function for the assets pipeline.\n */\n get assetsMiddleware(): Middleware {\n return forDataTypes(['balance'], async (ctx, next) => {\n const { request, response } = ctx;\n\n // Get state for custom assets, existing balances, and existing metadata\n const state = ctx.getAssetsState();\n const {\n customAssets: stateCustomAssets,\n assetsBalance: stateAssetsBalance,\n assetsInfo: stateAssetsInfo,\n assetsPrice: stateAssetsPrice,\n } = state;\n\n const detectedAssets: Record<AccountId, Caip19AssetId[]> = {};\n\n const detectionEnabled = this.#isTokenDetectionEnabled();\n // Lower-cased asset IDs stripped from the response because token\n // detection is off; used to purge their stub metadata afterwards.\n const strippedAssetIds = new Set<string>();\n // Lower-cased state metadata keys, built lazily (only when detection is\n // off) so the destructive strip below cannot misfire on a known holding\n // reported by a source in a different address case.\n let knownMetadataLower: Set<string> | null = null;\n const getKnownMetadataLower = (): Set<string> => {\n knownMetadataLower ??= new Set(\n Object.keys(stateAssetsInfo).map((id) => id.toLowerCase()),\n );\n return knownMetadataLower;\n };\n\n // 1. From balance response: only include assets that are genuinely new —\n // not already present in state.assetsBalance or state.assetsInfo.\n if (response.assetsBalance) {\n for (const [accountId, accountBalances] of Object.entries(\n response.assetsBalance,\n )) {\n const detected: Caip19AssetId[] = [];\n\n const stateAccountBalances = stateAssetsBalance[accountId] ?? {};\n const customForAccount = stateCustomAssets?.[accountId] ?? [];\n const customLowerIds = detectionEnabled\n ? null\n : new Set(customForAccount.map((id) => id.toLowerCase()));\n const knownBalanceLower = detectionEnabled\n ? null\n : new Set(\n Object.keys(stateAccountBalances).map((id) => id.toLowerCase()),\n );\n\n for (const assetId of Object.keys(\n accountBalances as Record<string, unknown>,\n )) {\n const caipAssetId = assetId as Caip19AssetId;\n // Skip if already tracked in state balances or already has metadata\n if (\n stateAccountBalances[caipAssetId] !== undefined ||\n stateAssetsInfo[caipAssetId] !== undefined\n ) {\n continue;\n }\n\n // Token detection off: new-to-state fungible tokens (erc20 / SPL\n // and similar `token` namespaces) are neither detected nor\n // persisted. Natives, staking contracts, custom assets, and\n // holdings already known to state (any address case) still flow.\n if (\n !detectionEnabled &&\n isDetectionGatedAsset(assetId) &&\n !customLowerIds?.has(assetId.toLowerCase())\n ) {\n const lowerId = assetId.toLowerCase();\n if (\n !knownBalanceLower?.has(lowerId) &&\n !getKnownMetadataLower().has(lowerId)\n ) {\n delete (accountBalances as Record<string, unknown>)[assetId];\n strippedAssetIds.add(lowerId);\n }\n continue;\n }\n\n detected.push(caipAssetId);\n }\n\n // Merge custom assets for this account, applying the same filter:\n // skip if already in state balance or already has metadata.\n for (const assetId of customForAccount) {\n if (detected.includes(assetId)) {\n continue;\n }\n if (\n stateAccountBalances[assetId] !== undefined ||\n stateAssetsInfo[assetId] !== undefined\n ) {\n continue;\n }\n detected.push(assetId);\n }\n\n if (detected.length > 0) {\n detectedAssets[accountId] = detected;\n }\n }\n }\n\n // Drop stub metadata (e.g. websocket-seeded name/symbol) of stripped\n // tokens so it never persists to state — a persisted stub would make\n // the token look \"known\" on the next update and let it bypass the\n // detection gate.\n if (strippedAssetIds.size > 0) {\n if (response.assetsInfo) {\n for (const assetId of Object.keys(response.assetsInfo)) {\n if (strippedAssetIds.has(assetId.toLowerCase())) {\n delete response.assetsInfo[assetId as Caip19AssetId];\n }\n }\n }\n log('Token detection disabled - stripped new tokens from response', {\n assetIds: [...strippedAssetIds],\n });\n }\n\n // 2. Accounts in request that weren't in balance response: include their\n // custom assets that are not yet in state.\n for (const { account } of request.accountsWithSupportedChains) {\n const accountId = account.id;\n if (detectedAssets[accountId]) {\n continue;\n }\n const stateAccountBalances = stateAssetsBalance[accountId] ?? {};\n const customForAccount = stateCustomAssets?.[accountId] ?? [];\n const newCustomAssets = customForAccount.filter((assetId) => {\n const inBalance = stateAccountBalances[assetId] !== undefined;\n const inInfo = stateAssetsInfo[assetId] !== undefined;\n return !inBalance && !inInfo;\n });\n if (newCustomAssets.length > 0) {\n detectedAssets[accountId] = newCustomAssets;\n }\n }\n\n if (Object.keys(detectedAssets).length > 0) {\n response.detectedAssets = detectedAssets;\n }\n\n // Queue prices for:\n // 1) newly detected assets missing a price, and\n // 2) assets in this balance response that already exist in state but still\n // lack a price (e.g. natives seeded before the first price poll).\n // PriceDataSource filters non-priceable IDs before calling the API.\n const prices = stateAssetsPrice as Record<string, unknown>;\n const missingPriceAssets = new Set<Caip19AssetId>();\n\n const maybeQueue = (assetId: Caip19AssetId): void => {\n const normalizedAssetId = normalizeAssetId(assetId);\n if (\n prices[normalizedAssetId] === undefined &&\n prices[assetId] === undefined\n ) {\n missingPriceAssets.add(normalizedAssetId);\n }\n };\n\n for (const accountAssetIds of Object.values(detectedAssets)) {\n for (const assetId of accountAssetIds) {\n maybeQueue(assetId);\n }\n }\n\n if (response.assetsBalance) {\n for (const accountBalances of Object.values(response.assetsBalance)) {\n for (const assetId of Object.keys(\n accountBalances as Record<string, unknown>,\n )) {\n maybeQueue(assetId as Caip19AssetId);\n }\n }\n }\n\n if (missingPriceAssets.size > 0) {\n request.assetsForPriceUpdate = [\n ...(request.assetsForPriceUpdate ?? []),\n ...missingPriceAssets,\n ];\n }\n\n return next(ctx);\n });\n }\n}\n"]}
|
|
@@ -12,14 +12,30 @@ import type { Middleware } from "../types.cjs";
|
|
|
12
12
|
* - Each account's custom assets from state are always included because they
|
|
13
13
|
* may have no balance yet and are explicitly managed by the user.
|
|
14
14
|
*
|
|
15
|
+
* When token detection is disabled (`isTokenDetectionEnabled` returns false),
|
|
16
|
+
* new-to-state fungible tokens (`erc20` / `token` namespaces) are neither
|
|
17
|
+
* detected nor persisted: their balances and stub metadata are stripped from
|
|
18
|
+
* the response. Natives, staking-contract assets, custom (user-imported)
|
|
19
|
+
* assets, and assets already tracked in state are unaffected.
|
|
20
|
+
*
|
|
15
21
|
* Usage:
|
|
16
22
|
* ```typescript
|
|
17
23
|
* const detectionMiddleware = new DetectionMiddleware();
|
|
18
24
|
* const middleware = detectionMiddleware.assetsMiddleware;
|
|
19
25
|
* ```
|
|
20
26
|
*/
|
|
27
|
+
/** Constructor options for {@link DetectionMiddleware}. */
|
|
28
|
+
export type DetectionMiddlewareOptions = {
|
|
29
|
+
/**
|
|
30
|
+
* Whether automatic token detection is enabled (e.g. the user's
|
|
31
|
+
* "Autodetect tokens" preference). Defaults to `() => true`.
|
|
32
|
+
*/
|
|
33
|
+
isTokenDetectionEnabled?: () => boolean;
|
|
34
|
+
};
|
|
21
35
|
export declare class DetectionMiddleware {
|
|
36
|
+
#private;
|
|
22
37
|
readonly name = "DetectionMiddleware";
|
|
38
|
+
constructor(options?: DetectionMiddlewareOptions);
|
|
23
39
|
getName(): string;
|
|
24
40
|
/**
|
|
25
41
|
* Get the middleware that builds detectedAssets for metadata and price fetching.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DetectionMiddleware.d.cts","sourceRoot":"","sources":["../../src/middlewares/DetectionMiddleware.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"DetectionMiddleware.d.cts","sourceRoot":"","sources":["../../src/middlewares/DetectionMiddleware.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAA4B,UAAU,EAAE,qBAAoB;AAoCxE;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,2DAA2D;AAC3D,MAAM,MAAM,0BAA0B,GAAG;IACvC;;;OAGG;IACH,uBAAuB,CAAC,EAAE,MAAM,OAAO,CAAC;CACzC,CAAC;AAEF,qBAAa,mBAAmB;;IAC9B,QAAQ,CAAC,IAAI,yBAAmB;gBAIpB,OAAO,GAAE,0BAA+B;IAKpD,OAAO,IAAI,MAAM;IAIjB;;;;;;;;;;;;;OAaG;IACH,IAAI,gBAAgB,IAAI,UAAU,CA4LjC;CACF"}
|
|
@@ -12,14 +12,30 @@ import type { Middleware } from "../types.mjs";
|
|
|
12
12
|
* - Each account's custom assets from state are always included because they
|
|
13
13
|
* may have no balance yet and are explicitly managed by the user.
|
|
14
14
|
*
|
|
15
|
+
* When token detection is disabled (`isTokenDetectionEnabled` returns false),
|
|
16
|
+
* new-to-state fungible tokens (`erc20` / `token` namespaces) are neither
|
|
17
|
+
* detected nor persisted: their balances and stub metadata are stripped from
|
|
18
|
+
* the response. Natives, staking-contract assets, custom (user-imported)
|
|
19
|
+
* assets, and assets already tracked in state are unaffected.
|
|
20
|
+
*
|
|
15
21
|
* Usage:
|
|
16
22
|
* ```typescript
|
|
17
23
|
* const detectionMiddleware = new DetectionMiddleware();
|
|
18
24
|
* const middleware = detectionMiddleware.assetsMiddleware;
|
|
19
25
|
* ```
|
|
20
26
|
*/
|
|
27
|
+
/** Constructor options for {@link DetectionMiddleware}. */
|
|
28
|
+
export type DetectionMiddlewareOptions = {
|
|
29
|
+
/**
|
|
30
|
+
* Whether automatic token detection is enabled (e.g. the user's
|
|
31
|
+
* "Autodetect tokens" preference). Defaults to `() => true`.
|
|
32
|
+
*/
|
|
33
|
+
isTokenDetectionEnabled?: () => boolean;
|
|
34
|
+
};
|
|
21
35
|
export declare class DetectionMiddleware {
|
|
36
|
+
#private;
|
|
22
37
|
readonly name = "DetectionMiddleware";
|
|
38
|
+
constructor(options?: DetectionMiddlewareOptions);
|
|
23
39
|
getName(): string;
|
|
24
40
|
/**
|
|
25
41
|
* Get the middleware that builds detectedAssets for metadata and price fetching.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DetectionMiddleware.d.mts","sourceRoot":"","sources":["../../src/middlewares/DetectionMiddleware.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"DetectionMiddleware.d.mts","sourceRoot":"","sources":["../../src/middlewares/DetectionMiddleware.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAA4B,UAAU,EAAE,qBAAoB;AAoCxE;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,2DAA2D;AAC3D,MAAM,MAAM,0BAA0B,GAAG;IACvC;;;OAGG;IACH,uBAAuB,CAAC,EAAE,MAAM,OAAO,CAAC;CACzC,CAAC;AAEF,qBAAa,mBAAmB;;IAC9B,QAAQ,CAAC,IAAI,yBAAmB;gBAIpB,OAAO,GAAE,0BAA+B;IAKpD,OAAO,IAAI,MAAM;IAIjB;;;;;;;;;;;;;OAaG;IACH,IAAI,gBAAgB,IAAI,UAAU,CA4LjC;CACF"}
|
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
+
};
|
|
7
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
+
};
|
|
12
|
+
var _DetectionMiddleware_isTokenDetectionEnabled;
|
|
13
|
+
import { parseCaipAssetType } from "@metamask/utils";
|
|
14
|
+
import { isStakingContractAssetId } from "../data-sources/evm-rpc-services/index.mjs";
|
|
15
|
+
import { CaipAssetNamespace } from "../data-sources/TokenDataSource.mjs";
|
|
1
16
|
import { projectLogger, createModuleLogger } from "../logger.mjs";
|
|
2
17
|
import { forDataTypes } from "../types.mjs";
|
|
3
18
|
import { normalizeAssetId } from "../utils/index.mjs";
|
|
@@ -5,33 +20,31 @@ import { normalizeAssetId } from "../utils/index.mjs";
|
|
|
5
20
|
// CONSTANTS
|
|
6
21
|
// ============================================================================
|
|
7
22
|
const CONTROLLER_NAME = 'DetectionMiddleware';
|
|
8
|
-
|
|
9
|
-
createModuleLogger(projectLogger, CONTROLLER_NAME);
|
|
10
|
-
// ============================================================================
|
|
11
|
-
// DETECTION MIDDLEWARE
|
|
12
|
-
// ============================================================================
|
|
23
|
+
const log = createModuleLogger(projectLogger, CONTROLLER_NAME);
|
|
13
24
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
25
|
+
* Whether an asset is subject to the token-detection toggle: fungible tokens
|
|
26
|
+
* (EVM `erc20`, non-EVM `token` — SPL, TRC, etc.). Natives (`slip44`),
|
|
27
|
+
* staking-contract assets, and anything unparseable are never gated.
|
|
16
28
|
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* from BOTH `state.assetsBalance` (never tracked before) AND `state.assetsInfo`
|
|
20
|
-
* (no metadata yet). Assets already present in either collection are considered
|
|
21
|
-
* known and are intentionally excluded — PriceDataSource's own subscription
|
|
22
|
-
* handles periodic refreshes for those.
|
|
23
|
-
* - Each account's custom assets from state are always included because they
|
|
24
|
-
* may have no balance yet and are explicitly managed by the user.
|
|
25
|
-
*
|
|
26
|
-
* Usage:
|
|
27
|
-
* ```typescript
|
|
28
|
-
* const detectionMiddleware = new DetectionMiddleware();
|
|
29
|
-
* const middleware = detectionMiddleware.assetsMiddleware;
|
|
30
|
-
* ```
|
|
29
|
+
* @param assetId - The CAIP-19 asset ID to classify.
|
|
30
|
+
* @returns `true` when the asset should be blocked while detection is off.
|
|
31
31
|
*/
|
|
32
|
+
function isDetectionGatedAsset(assetId) {
|
|
33
|
+
try {
|
|
34
|
+
const { assetNamespace } = parseCaipAssetType(assetId);
|
|
35
|
+
return ((assetNamespace === CaipAssetNamespace.Erc20 ||
|
|
36
|
+
assetNamespace === CaipAssetNamespace.Token) &&
|
|
37
|
+
!isStakingContractAssetId(assetId));
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
32
43
|
export class DetectionMiddleware {
|
|
33
|
-
constructor() {
|
|
44
|
+
constructor(options = {}) {
|
|
34
45
|
this.name = CONTROLLER_NAME;
|
|
46
|
+
_DetectionMiddleware_isTokenDetectionEnabled.set(this, void 0);
|
|
47
|
+
__classPrivateFieldSet(this, _DetectionMiddleware_isTokenDetectionEnabled, options.isTokenDetectionEnabled ?? (() => true), "f");
|
|
35
48
|
}
|
|
36
49
|
getName() {
|
|
37
50
|
return this.name;
|
|
@@ -57,12 +70,31 @@ export class DetectionMiddleware {
|
|
|
57
70
|
const state = ctx.getAssetsState();
|
|
58
71
|
const { customAssets: stateCustomAssets, assetsBalance: stateAssetsBalance, assetsInfo: stateAssetsInfo, assetsPrice: stateAssetsPrice, } = state;
|
|
59
72
|
const detectedAssets = {};
|
|
73
|
+
const detectionEnabled = __classPrivateFieldGet(this, _DetectionMiddleware_isTokenDetectionEnabled, "f").call(this);
|
|
74
|
+
// Lower-cased asset IDs stripped from the response because token
|
|
75
|
+
// detection is off; used to purge their stub metadata afterwards.
|
|
76
|
+
const strippedAssetIds = new Set();
|
|
77
|
+
// Lower-cased state metadata keys, built lazily (only when detection is
|
|
78
|
+
// off) so the destructive strip below cannot misfire on a known holding
|
|
79
|
+
// reported by a source in a different address case.
|
|
80
|
+
let knownMetadataLower = null;
|
|
81
|
+
const getKnownMetadataLower = () => {
|
|
82
|
+
knownMetadataLower ?? (knownMetadataLower = new Set(Object.keys(stateAssetsInfo).map((id) => id.toLowerCase())));
|
|
83
|
+
return knownMetadataLower;
|
|
84
|
+
};
|
|
60
85
|
// 1. From balance response: only include assets that are genuinely new —
|
|
61
86
|
// not already present in state.assetsBalance or state.assetsInfo.
|
|
62
87
|
if (response.assetsBalance) {
|
|
63
88
|
for (const [accountId, accountBalances] of Object.entries(response.assetsBalance)) {
|
|
64
89
|
const detected = [];
|
|
65
90
|
const stateAccountBalances = stateAssetsBalance[accountId] ?? {};
|
|
91
|
+
const customForAccount = stateCustomAssets?.[accountId] ?? [];
|
|
92
|
+
const customLowerIds = detectionEnabled
|
|
93
|
+
? null
|
|
94
|
+
: new Set(customForAccount.map((id) => id.toLowerCase()));
|
|
95
|
+
const knownBalanceLower = detectionEnabled
|
|
96
|
+
? null
|
|
97
|
+
: new Set(Object.keys(stateAccountBalances).map((id) => id.toLowerCase()));
|
|
66
98
|
for (const assetId of Object.keys(accountBalances)) {
|
|
67
99
|
const caipAssetId = assetId;
|
|
68
100
|
// Skip if already tracked in state balances or already has metadata
|
|
@@ -70,11 +102,25 @@ export class DetectionMiddleware {
|
|
|
70
102
|
stateAssetsInfo[caipAssetId] !== undefined) {
|
|
71
103
|
continue;
|
|
72
104
|
}
|
|
105
|
+
// Token detection off: new-to-state fungible tokens (erc20 / SPL
|
|
106
|
+
// and similar `token` namespaces) are neither detected nor
|
|
107
|
+
// persisted. Natives, staking contracts, custom assets, and
|
|
108
|
+
// holdings already known to state (any address case) still flow.
|
|
109
|
+
if (!detectionEnabled &&
|
|
110
|
+
isDetectionGatedAsset(assetId) &&
|
|
111
|
+
!customLowerIds?.has(assetId.toLowerCase())) {
|
|
112
|
+
const lowerId = assetId.toLowerCase();
|
|
113
|
+
if (!knownBalanceLower?.has(lowerId) &&
|
|
114
|
+
!getKnownMetadataLower().has(lowerId)) {
|
|
115
|
+
delete accountBalances[assetId];
|
|
116
|
+
strippedAssetIds.add(lowerId);
|
|
117
|
+
}
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
73
120
|
detected.push(caipAssetId);
|
|
74
121
|
}
|
|
75
122
|
// Merge custom assets for this account, applying the same filter:
|
|
76
123
|
// skip if already in state balance or already has metadata.
|
|
77
|
-
const customForAccount = stateCustomAssets?.[accountId] ?? [];
|
|
78
124
|
for (const assetId of customForAccount) {
|
|
79
125
|
if (detected.includes(assetId)) {
|
|
80
126
|
continue;
|
|
@@ -90,6 +136,22 @@ export class DetectionMiddleware {
|
|
|
90
136
|
}
|
|
91
137
|
}
|
|
92
138
|
}
|
|
139
|
+
// Drop stub metadata (e.g. websocket-seeded name/symbol) of stripped
|
|
140
|
+
// tokens so it never persists to state — a persisted stub would make
|
|
141
|
+
// the token look "known" on the next update and let it bypass the
|
|
142
|
+
// detection gate.
|
|
143
|
+
if (strippedAssetIds.size > 0) {
|
|
144
|
+
if (response.assetsInfo) {
|
|
145
|
+
for (const assetId of Object.keys(response.assetsInfo)) {
|
|
146
|
+
if (strippedAssetIds.has(assetId.toLowerCase())) {
|
|
147
|
+
delete response.assetsInfo[assetId];
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
log('Token detection disabled - stripped new tokens from response', {
|
|
152
|
+
assetIds: [...strippedAssetIds],
|
|
153
|
+
});
|
|
154
|
+
}
|
|
93
155
|
// 2. Accounts in request that weren't in balance response: include their
|
|
94
156
|
// custom assets that are not yet in state.
|
|
95
157
|
for (const { account } of request.accountsWithSupportedChains) {
|
|
@@ -147,4 +209,5 @@ export class DetectionMiddleware {
|
|
|
147
209
|
});
|
|
148
210
|
}
|
|
149
211
|
}
|
|
212
|
+
_DetectionMiddleware_isTokenDetectionEnabled = new WeakMap();
|
|
150
213
|
//# sourceMappingURL=DetectionMiddleware.mjs.map
|