@metamask-previews/assets-controller 11.2.1-preview-97f066f → 11.2.1-preview-2dc3d26a4
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 +6 -5
- package/dist/AssetsController.cjs +23 -51
- package/dist/AssetsController.cjs.map +1 -1
- package/dist/AssetsController.d.cts +3 -3
- package/dist/AssetsController.d.cts.map +1 -1
- package/dist/AssetsController.d.mts +3 -3
- package/dist/AssetsController.d.mts.map +1 -1
- package/dist/AssetsController.mjs +23 -51
- package/dist/AssetsController.mjs.map +1 -1
- package/dist/data-sources/AccountActivityDataSource.cjs +262 -0
- package/dist/data-sources/AccountActivityDataSource.cjs.map +1 -0
- package/dist/data-sources/AccountActivityDataSource.d.cts +80 -0
- package/dist/data-sources/AccountActivityDataSource.d.cts.map +1 -0
- package/dist/data-sources/AccountActivityDataSource.d.mts +80 -0
- package/dist/data-sources/AccountActivityDataSource.d.mts.map +1 -0
- package/dist/data-sources/AccountActivityDataSource.mjs +254 -0
- package/dist/data-sources/AccountActivityDataSource.mjs.map +1 -0
- package/dist/data-sources/index.cjs +4 -4
- package/dist/data-sources/index.cjs.map +1 -1
- package/dist/data-sources/index.d.cts +1 -1
- package/dist/data-sources/index.d.cts.map +1 -1
- package/dist/data-sources/index.d.mts +1 -1
- package/dist/data-sources/index.d.mts.map +1 -1
- package/dist/data-sources/index.mjs +1 -1
- package/dist/data-sources/index.mjs.map +1 -1
- package/dist/index.cjs +22 -26
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +0 -2
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +0 -2
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +0 -2
- package/dist/index.mjs.map +1 -1
- package/dist/middlewares/CustomAssetGraduationMiddleware.cjs +1 -1
- package/dist/middlewares/CustomAssetGraduationMiddleware.cjs.map +1 -1
- package/dist/middlewares/CustomAssetGraduationMiddleware.mjs +1 -1
- package/dist/middlewares/CustomAssetGraduationMiddleware.mjs.map +1 -1
- package/package.json +1 -1
- package/dist/data-sources/BackendWebsocketDataSource.cjs +0 -597
- package/dist/data-sources/BackendWebsocketDataSource.cjs.map +0 -1
- package/dist/data-sources/BackendWebsocketDataSource.d.cts +0 -65
- package/dist/data-sources/BackendWebsocketDataSource.d.cts.map +0 -1
- package/dist/data-sources/BackendWebsocketDataSource.d.mts +0 -65
- package/dist/data-sources/BackendWebsocketDataSource.d.mts.map +0 -1
- package/dist/data-sources/BackendWebsocketDataSource.mjs +0 -592
- package/dist/data-sources/BackendWebsocketDataSource.mjs.map +0 -1
- package/dist/utils/processAccountActivityBalanceUpdates.cjs +0 -54
- package/dist/utils/processAccountActivityBalanceUpdates.cjs.map +0 -1
- package/dist/utils/processAccountActivityBalanceUpdates.d.cts +0 -13
- package/dist/utils/processAccountActivityBalanceUpdates.d.cts.map +0 -1
- package/dist/utils/processAccountActivityBalanceUpdates.d.mts +0 -13
- package/dist/utils/processAccountActivityBalanceUpdates.d.mts.map +0 -1
- package/dist/utils/processAccountActivityBalanceUpdates.mjs +0 -47
- package/dist/utils/processAccountActivityBalanceUpdates.mjs.map +0 -1
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,kCAAkC,EAClC,sBAAsB,EACtB,sBAAsB,EACtB,+BAA+B,EAC/B,uBAAuB,EACxB,uBAAsB;AAGvB,4CAA4C;AAC5C,OAAO,EACL,gCAAgC,EAChC,iCAAiC,EACjC,yBAAyB,EACzB,gCAAgC,EAChC,sBAAsB,EACtB,+BAA+B,EAC/B,8BAA8B,EAC/B,2CAA0C;AAsF3C,sCAAsC;AAC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cesContent":["// 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 AssetsControllerGetAssetAction,\n AssetsControllerGetAssetsPriceAction,\n AssetsControllerAddCustomAssetAction,\n AssetsControllerRemoveCustomAssetAction,\n AssetsControllerGetCustomAssetsAction,\n AssetsControllerHideAssetAction,\n AssetsControllerUnhideAssetAction,\n AssetsControllerGetExchangeRatesForBridgeAction,\n AssetsControllerGetStateForTransactionPayAction,\n AssetsControllerSetSelectedCurrencyAction,\n} from './AssetsController-method-action-types.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 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"]}
|
|
@@ -72,7 +72,7 @@ class CustomAssetGraduationMiddleware {
|
|
|
72
72
|
}
|
|
73
73
|
// customAssets state is stored with checksummed/normalized asset IDs.
|
|
74
74
|
// AccountsApiDataSource normalizes its response IDs, but
|
|
75
|
-
//
|
|
75
|
+
// AccountActivityDataSource does not — so we normalize the response
|
|
76
76
|
// side here to make the comparison robust to lower-case addresses
|
|
77
77
|
// delivered over the websocket.
|
|
78
78
|
const customSet = new Set(customForAccount);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CustomAssetGraduationMiddleware.cjs","sourceRoot":"","sources":["../../src/middlewares/CustomAssetGraduationMiddleware.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAqD;AAErD,6CAAiE;AACjE,2CAA2C;AAO3C,i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,IAAI,gBAAgB,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBAClC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;YACnB,CAAC;YAED,sEAAsE;YACtE,yDAAyD;YACzD,
|
|
1
|
+
{"version":3,"file":"CustomAssetGraduationMiddleware.cjs","sourceRoot":"","sources":["../../src/middlewares/CustomAssetGraduationMiddleware.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAqD;AAErD,6CAAiE;AACjE,2CAA2C;AAO3C,iDAAqD;AAErD,MAAM,eAAe,GAAG,iCAAiC,CAAC;AAE1D,MAAM,GAAG,GAAG,IAAA,8BAAkB,EAAC,yBAAa,EAAE,eAAe,CAAC,CAAC;AAO/D;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAa,+BAA+B;IAU1C,YAAY,OAA+C;QATlD,SAAI,GAAG,eAAe,CAAC;QAEvB,wEAAmD;QAEnD,qEAGC;QAGR,uBAAA,IAAI,yDAAyB,OAAO,CAAC,oBAAoB,MAAA,CAAC;QAC1D,uBAAA,IAAI,sDAAsB,OAAO,CAAC,iBAAiB,MAAA,CAAC;IACtD,CAAC;IAED,OAAO;QACL,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IAED,IAAI,gBAAgB;QAClB,OAAO,IAAA,uBAAY,EAAC,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;YACnD,iEAAiE;YACjE,uEAAuE;YACvE,oEAAoE;YACpE,kEAAkE;YAClE,4BAA4B;YAC5B,MAAM,SAAS,GAAG,uBAAA,IAAI,6DAAsB,MAA1B,IAAI,CAAwB,CAAC;YAC/C,IAAI,CAAC,SAAS,EAAE,CAAC;gBACf,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;YACnB,CAAC;YAED,MAAM,KAAK,GAAG,GAAG,CAAC,cAAc,EAAE,CAAC;YACnC,MAAM,gBAAgB,GAAG,KAAK,CAAC,YAAY,EAAE,CAA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;;AAED;;;;;GAKG;AACH,SAAS,YAAY,CAAC,OAAsB;IAC1C,qEAAqE;IACrE,oEAAoE;IACpE,MAAM,SAAS,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IACxC,OAAO,SAAS,KAAK,0BAAkB,CAAC,MAAM,CAAC;AACjD,CAAC;AAED;;;;;;;;GAQG;AACH,SAAS,aAAa,CAAC,OAAsB;IAC3C,IAAI,CAAC;QACH,OAAO,IAAA,2BAAgB,EAAC,OAAO,CAAC,CAAC;IACnC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,OAAO,CAAC;IACjB,CAAC;AACH,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,SAAS,kBAAkB,CAAC,OAAiC;IAC3D,OAAO,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC;AACrC,CAAC","sourcesContent":["import { KnownCaipNamespace } from '@metamask/utils';\n\nimport { projectLogger, createModuleLogger } from '../logger.js';\nimport { forDataTypes } from '../types.js';\nimport type {\n AccountId,\n AssetBalance,\n Caip19AssetId,\n Middleware,\n} from '../types.js';\nimport { normalizeAssetId } from '../utils/index.js';\n\nconst CONTROLLER_NAME = 'CustomAssetGraduationMiddleware';\n\nconst log = createModuleLogger(projectLogger, CONTROLLER_NAME);\n\nexport type CustomAssetGraduationMiddlewareOptions = {\n getSelectedAccountId: () => AccountId | undefined;\n removeCustomAsset: (accountId: AccountId, assetId: Caip19AssetId) => void;\n};\n\n/**\n * CustomAssetGraduationMiddleware removes EVM assets from `customAssets` when\n * an upstream balance source (AccountsAPI / Websocket) reports a non-zero\n * balance for them. Once a detector sees the asset with a real balance, it\n * no longer needs to be tracked as \"custom\" — the regular detection flow\n * will keep it fresh.\n *\n * Rules:\n * - Only the selected account's custom assets are considered. Switching the\n * selected account triggers a fresh fetch, which re-runs graduation\n * against the new account's balances.\n * - Only EVM (CAIP-2 namespace `eip155`) assets graduate. Non-EVM custom\n * assets (Solana, BTC, Tron, etc. — served by Snap data sources) are left\n * alone.\n * - Only positive balances graduate. A zero balance from AccountsAPI means\n * the API knows about the token but the user does not currently hold it;\n * keeping it in `customAssets` ensures RPC keeps polling so a future\n * incoming transfer is reflected promptly.\n */\nexport class CustomAssetGraduationMiddleware {\n readonly name = CONTROLLER_NAME;\n\n readonly #getSelectedAccountId: () => AccountId | undefined;\n\n readonly #removeCustomAsset: (\n accountId: AccountId,\n assetId: Caip19AssetId,\n ) => void;\n\n constructor(options: CustomAssetGraduationMiddlewareOptions) {\n this.#getSelectedAccountId = options.getSelectedAccountId;\n this.#removeCustomAsset = options.removeCustomAsset;\n }\n\n getName(): string {\n return this.name;\n }\n\n get assetsMiddleware(): Middleware {\n return forDataTypes(['balance'], async (ctx, next) => {\n // Inspect the response BEFORE calling next() so we only consider\n // balances populated by upstream middleware (AccountsApi / Websocket /\n // Staked). This middleware is positioned in the pipeline before the\n // RPC fallback — RPC intentionally carries custom assets and must\n // never trigger graduation.\n const accountId = this.#getSelectedAccountId();\n if (!accountId) {\n return next(ctx);\n }\n\n const state = ctx.getAssetsState();\n const customForAccount = state.customAssets?.[accountId] ?? [];\n if (customForAccount.length === 0) {\n return next(ctx);\n }\n\n const returnedBalances = ctx.response.assetsBalance?.[accountId] ?? {};\n const returnedAssetIds = Object.keys(returnedBalances) as Caip19AssetId[];\n if (returnedAssetIds.length === 0) {\n return next(ctx);\n }\n\n // customAssets state is stored with checksummed/normalized asset IDs.\n // AccountsApiDataSource normalizes its response IDs, but\n // AccountActivityDataSource does not — so we normalize the response\n // side here to make the comparison robust to lower-case addresses\n // delivered over the websocket.\n const customSet = new Set(customForAccount);\n for (const rawAssetId of returnedAssetIds) {\n if (!isEvmAssetId(rawAssetId)) {\n continue;\n }\n if (!hasPositiveBalance(returnedBalances[rawAssetId])) {\n continue;\n }\n const normalizedAssetId = safeNormalize(rawAssetId);\n if (!customSet.has(normalizedAssetId)) {\n continue;\n }\n log('Graduating custom asset', {\n accountId,\n assetId: normalizedAssetId,\n });\n this.#removeCustomAsset(accountId, normalizedAssetId);\n }\n\n return next(ctx);\n });\n }\n}\n\n/**\n * Check whether a CAIP-19 asset ID belongs to an EVM chain.\n *\n * @param assetId - The CAIP-19 asset ID to inspect.\n * @returns `true` when the asset's chain namespace is `eip155`.\n */\nfunction isEvmAssetId(assetId: Caip19AssetId): boolean {\n // CAIP-19 format: <namespace>:<chainRef>/<assetNamespace>:<assetRef>\n // The chain namespace is always the segment before the first colon.\n const namespace = assetId.split(':')[0];\n return namespace === KnownCaipNamespace.Eip155;\n}\n\n/**\n * Normalize a CAIP-19 asset ID, returning the original on failure. Some\n * malformed IDs (e.g. an asset reference that fails address checksumming)\n * make `normalizeAssetId` throw — in that case we fall back to the raw ID\n * so the graduation pass can still proceed for other assets.\n *\n * @param assetId - The CAIP-19 asset ID to normalize.\n * @returns The normalized ID, or the original on failure.\n */\nfunction safeNormalize(assetId: Caip19AssetId): Caip19AssetId {\n try {\n return normalizeAssetId(assetId);\n } catch {\n return assetId;\n }\n}\n\n/**\n * Whether a balance entry reports a strictly positive amount. AccountsAPI\n * may return zero for tokens it indexes but the user no longer holds; we\n * treat those as non-graduating so RPC keeps polling and surfaces any\n * future incoming transfer immediately.\n *\n * `AssetBalance.amount` is already a human-readable decimal string from\n * both AccountsApi (e.g. \"0.283549083429656057\") and the websocket data\n * source (which divides by `decimals` before emitting), so a `Number()`\n * sign check is safe: `NaN`, `undefined`, empty strings, and zero all\n * fail the comparison.\n *\n * @param balance - The balance entry from the response.\n * @returns `true` when the balance amount represents a value greater than 0.\n */\nfunction hasPositiveBalance(balance: AssetBalance | undefined): boolean {\n return Number(balance?.amount) > 0;\n}\n"]}
|
|
@@ -69,7 +69,7 @@ export class CustomAssetGraduationMiddleware {
|
|
|
69
69
|
}
|
|
70
70
|
// customAssets state is stored with checksummed/normalized asset IDs.
|
|
71
71
|
// AccountsApiDataSource normalizes its response IDs, but
|
|
72
|
-
//
|
|
72
|
+
// AccountActivityDataSource does not — so we normalize the response
|
|
73
73
|
// side here to make the comparison robust to lower-case addresses
|
|
74
74
|
// delivered over the websocket.
|
|
75
75
|
const customSet = new Set(customForAccount);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CustomAssetGraduationMiddleware.mjs","sourceRoot":"","sources":["../../src/middlewares/CustomAssetGraduationMiddleware.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,kBAAkB,EAAE,wBAAwB;AAErD,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,sBAAqB;AACjE,OAAO,EAAE,YAAY,EAAE,qBAAoB;AAO3C,OAAO,EAAE,gBAAgB,EAAE,2BAA0B;AAErD,MAAM,eAAe,GAAG,iCAAiC,CAAC;AAE1D,MAAM,GAAG,GAAG,kBAAkB,CAAC,aAAa,EAAE,eAAe,CAAC,CAAC;AAO/D;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,OAAO,+BAA+B;IAU1C,YAAY,OAA+C;QATlD,SAAI,GAAG,eAAe,CAAC;QAEvB,wEAAmD;QAEnD,qEAGC;QAGR,uBAAA,IAAI,yDAAyB,OAAO,CAAC,oBAAoB,MAAA,CAAC;QAC1D,uBAAA,IAAI,sDAAsB,OAAO,CAAC,iBAAiB,MAAA,CAAC;IACtD,CAAC;IAED,OAAO;QACL,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IAED,IAAI,gBAAgB;QAClB,OAAO,YAAY,CAAC,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;YACnD,iEAAiE;YACjE,uEAAuE;YACvE,oEAAoE;YACpE,kEAAkE;YAClE,4BAA4B;YAC5B,MAAM,SAAS,GAAG,uBAAA,IAAI,6DAAsB,MAA1B,IAAI,CAAwB,CAAC;YAC/C,IAAI,CAAC,SAAS,EAAE,CAAC;gBACf,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;YACnB,CAAC;YAED,MAAM,KAAK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,kBAAkB,CAAC,gBAAgB,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC;oBACtD,SAAS;gBACX,CAAC;gBACD,MAAM,iBAAiB,GAAG,aAAa,CAAC,UAAU,CAAC,CAAC;gBACpD,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,iBAAiB,CAAC,EAAE,CAAC;oBACtC,SAAS;gBACX,CAAC;gBACD,GAAG,CAAC,yBAAyB,EAAE;oBAC7B,SAAS;oBACT,OAAO,EAAE,iBAAiB;iBAC3B,CAAC,CAAC;gBACH,uBAAA,IAAI,0DAAmB,MAAvB,IAAI,EAAoB,SAAS,EAAE,iBAAiB,CAAC,CAAC;YACxD,CAAC;YAED,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;QACnB,CAAC,CAAC,CAAC;IACL,CAAC;CACF;;AAED;;;;;GAKG;AACH,SAAS,YAAY,CAAC,OAAsB;IAC1C,qEAAqE;IACrE,oEAAoE;IACpE,MAAM,SAAS,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IACxC,OAAO,SAAS,KAAK,kBAAkB,CAAC,MAAM,CAAC;AACjD,CAAC;AAED;;;;;;;;GAQG;AACH,SAAS,aAAa,CAAC,OAAsB;IAC3C,IAAI,CAAC;QACH,OAAO,gBAAgB,CAAC,OAAO,CAAC,CAAC;IACnC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,OAAO,CAAC;IACjB,CAAC;AACH,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,SAAS,kBAAkB,CAAC,OAAiC;IAC3D,OAAO,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC;AACrC,CAAC","sourcesContent":["import { KnownCaipNamespace } from '@metamask/utils';\n\nimport { projectLogger, createModuleLogger } from '../logger.js';\nimport { forDataTypes } from '../types.js';\nimport type {\n AccountId,\n AssetBalance,\n Caip19AssetId,\n Middleware,\n} from '../types.js';\nimport { normalizeAssetId } from '../utils/index.js';\n\nconst CONTROLLER_NAME = 'CustomAssetGraduationMiddleware';\n\nconst log = createModuleLogger(projectLogger, CONTROLLER_NAME);\n\nexport type CustomAssetGraduationMiddlewareOptions = {\n getSelectedAccountId: () => AccountId | undefined;\n removeCustomAsset: (accountId: AccountId, assetId: Caip19AssetId) => void;\n};\n\n/**\n * CustomAssetGraduationMiddleware removes EVM assets from `customAssets` when\n * an upstream balance source (AccountsAPI / Websocket) reports a non-zero\n * balance for them. Once a detector sees the asset with a real balance, it\n * no longer needs to be tracked as \"custom\" — the regular detection flow\n * will keep it fresh.\n *\n * Rules:\n * - Only the selected account's custom assets are considered. Switching the\n * selected account triggers a fresh fetch, which re-runs graduation\n * against the new account's balances.\n * - Only EVM (CAIP-2 namespace `eip155`) assets graduate. Non-EVM custom\n * assets (Solana, BTC, Tron, etc. — served by Snap data sources) are left\n * alone.\n * - Only positive balances graduate. A zero balance from AccountsAPI means\n * the API knows about the token but the user does not currently hold it;\n * keeping it in `customAssets` ensures RPC keeps polling so a future\n * incoming transfer is reflected promptly.\n */\nexport class CustomAssetGraduationMiddleware {\n readonly name = CONTROLLER_NAME;\n\n readonly #getSelectedAccountId: () => AccountId | undefined;\n\n readonly #removeCustomAsset: (\n accountId: AccountId,\n assetId: Caip19AssetId,\n ) => void;\n\n constructor(options: CustomAssetGraduationMiddlewareOptions) {\n this.#getSelectedAccountId = options.getSelectedAccountId;\n this.#removeCustomAsset = options.removeCustomAsset;\n }\n\n getName(): string {\n return this.name;\n }\n\n get assetsMiddleware(): Middleware {\n return forDataTypes(['balance'], async (ctx, next) => {\n // Inspect the response BEFORE calling next() so we only consider\n // balances populated by upstream middleware (AccountsApi / Websocket /\n // Staked). This middleware is positioned in the pipeline before the\n // RPC fallback — RPC intentionally carries custom assets and must\n // never trigger graduation.\n const accountId = this.#getSelectedAccountId();\n if (!accountId) {\n return next(ctx);\n }\n\n const state = ctx.getAssetsState();\n const customForAccount = state.customAssets?.[accountId] ?? [];\n if (customForAccount.length === 0) {\n return next(ctx);\n }\n\n const returnedBalances = ctx.response.assetsBalance?.[accountId] ?? {};\n const returnedAssetIds = Object.keys(returnedBalances) as Caip19AssetId[];\n if (returnedAssetIds.length === 0) {\n return next(ctx);\n }\n\n // customAssets state is stored with checksummed/normalized asset IDs.\n // AccountsApiDataSource normalizes its response IDs, but\n // AccountActivityDataSource does not — so we normalize the response\n // side here to make the comparison robust to lower-case addresses\n // delivered over the websocket.\n const customSet = new Set(customForAccount);\n for (const rawAssetId of returnedAssetIds) {\n if (!isEvmAssetId(rawAssetId)) {\n continue;\n }\n if (!hasPositiveBalance(returnedBalances[rawAssetId])) {\n continue;\n }\n const normalizedAssetId = safeNormalize(rawAssetId);\n if (!customSet.has(normalizedAssetId)) {\n continue;\n }\n log('Graduating custom asset', {\n accountId,\n assetId: normalizedAssetId,\n });\n this.#removeCustomAsset(accountId, normalizedAssetId);\n }\n\n return next(ctx);\n });\n }\n}\n\n/**\n * Check whether a CAIP-19 asset ID belongs to an EVM chain.\n *\n * @param assetId - The CAIP-19 asset ID to inspect.\n * @returns `true` when the asset's chain namespace is `eip155`.\n */\nfunction isEvmAssetId(assetId: Caip19AssetId): boolean {\n // CAIP-19 format: <namespace>:<chainRef>/<assetNamespace>:<assetRef>\n // The chain namespace is always the segment before the first colon.\n const namespace = assetId.split(':')[0];\n return namespace === KnownCaipNamespace.Eip155;\n}\n\n/**\n * Normalize a CAIP-19 asset ID, returning the original on failure. Some\n * malformed IDs (e.g. an asset reference that fails address checksumming)\n * make `normalizeAssetId` throw — in that case we fall back to the raw ID\n * so the graduation pass can still proceed for other assets.\n *\n * @param assetId - The CAIP-19 asset ID to normalize.\n * @returns The normalized ID, or the original on failure.\n */\nfunction safeNormalize(assetId: Caip19AssetId): Caip19AssetId {\n try {\n return normalizeAssetId(assetId);\n } catch {\n return assetId;\n }\n}\n\n/**\n * Whether a balance entry reports a strictly positive amount. AccountsAPI\n * may return zero for tokens it indexes but the user no longer holds; we\n * treat those as non-graduating so RPC keeps polling and surfaces any\n * future incoming transfer immediately.\n *\n * `AssetBalance.amount` is already a human-readable decimal string from\n * both AccountsApi (e.g. \"0.283549083429656057\") and the websocket data\n * source (which divides by `decimals` before emitting), so a `Number()`\n * sign check is safe: `NaN`, `undefined`, empty strings, and zero all\n * fail the comparison.\n *\n * @param balance - The balance entry from the response.\n * @returns `true` when the balance amount represents a value greater than 0.\n */\nfunction hasPositiveBalance(balance: AssetBalance | undefined): boolean {\n return Number(balance?.amount) > 0;\n}\n"]}
|
package/package.json
CHANGED