@metamask/assets-controller 1.0.0 → 2.0.0
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 +23 -1
- package/dist/AssetsController.cjs +175 -64
- package/dist/AssetsController.cjs.map +1 -1
- package/dist/AssetsController.d.cts +68 -9
- package/dist/AssetsController.d.cts.map +1 -1
- package/dist/AssetsController.d.mts +68 -9
- package/dist/AssetsController.d.mts.map +1 -1
- package/dist/AssetsController.mjs +176 -65
- package/dist/AssetsController.mjs.map +1 -1
- package/dist/data-sources/AccountsApiDataSource.cjs +70 -15
- package/dist/data-sources/AccountsApiDataSource.cjs.map +1 -1
- package/dist/data-sources/AccountsApiDataSource.d.cts +22 -3
- package/dist/data-sources/AccountsApiDataSource.d.cts.map +1 -1
- package/dist/data-sources/AccountsApiDataSource.d.mts +22 -3
- package/dist/data-sources/AccountsApiDataSource.d.mts.map +1 -1
- package/dist/data-sources/AccountsApiDataSource.mjs +66 -12
- package/dist/data-sources/AccountsApiDataSource.mjs.map +1 -1
- package/dist/data-sources/BackendWebsocketDataSource.cjs +7 -5
- package/dist/data-sources/BackendWebsocketDataSource.cjs.map +1 -1
- package/dist/data-sources/BackendWebsocketDataSource.d.cts.map +1 -1
- package/dist/data-sources/BackendWebsocketDataSource.d.mts.map +1 -1
- package/dist/data-sources/BackendWebsocketDataSource.mjs +7 -5
- package/dist/data-sources/BackendWebsocketDataSource.mjs.map +1 -1
- package/dist/data-sources/PriceDataSource.cjs +17 -4
- package/dist/data-sources/PriceDataSource.cjs.map +1 -1
- package/dist/data-sources/PriceDataSource.d.cts +8 -4
- package/dist/data-sources/PriceDataSource.d.cts.map +1 -1
- package/dist/data-sources/PriceDataSource.d.mts +8 -4
- package/dist/data-sources/PriceDataSource.d.mts.map +1 -1
- package/dist/data-sources/PriceDataSource.mjs +17 -4
- package/dist/data-sources/PriceDataSource.mjs.map +1 -1
- package/dist/data-sources/RpcDataSource.cjs +122 -42
- package/dist/data-sources/RpcDataSource.cjs.map +1 -1
- package/dist/data-sources/RpcDataSource.d.cts +16 -62
- package/dist/data-sources/RpcDataSource.d.cts.map +1 -1
- package/dist/data-sources/RpcDataSource.d.mts +16 -62
- package/dist/data-sources/RpcDataSource.d.mts.map +1 -1
- package/dist/data-sources/RpcDataSource.mjs +123 -43
- package/dist/data-sources/RpcDataSource.mjs.map +1 -1
- package/dist/data-sources/SnapDataSource.cjs +22 -10
- package/dist/data-sources/SnapDataSource.cjs.map +1 -1
- package/dist/data-sources/SnapDataSource.d.cts +2 -1
- package/dist/data-sources/SnapDataSource.d.cts.map +1 -1
- package/dist/data-sources/SnapDataSource.d.mts +2 -1
- package/dist/data-sources/SnapDataSource.d.mts.map +1 -1
- package/dist/data-sources/SnapDataSource.mjs +22 -10
- package/dist/data-sources/SnapDataSource.mjs.map +1 -1
- package/dist/data-sources/StakedBalanceDataSource.cjs +609 -0
- package/dist/data-sources/StakedBalanceDataSource.cjs.map +1 -0
- package/dist/data-sources/StakedBalanceDataSource.d.cts +72 -0
- package/dist/data-sources/StakedBalanceDataSource.d.cts.map +1 -0
- package/dist/data-sources/StakedBalanceDataSource.d.mts +72 -0
- package/dist/data-sources/StakedBalanceDataSource.d.mts.map +1 -0
- package/dist/data-sources/StakedBalanceDataSource.mjs +605 -0
- package/dist/data-sources/StakedBalanceDataSource.mjs.map +1 -0
- package/dist/data-sources/TokenDataSource.cjs +12 -5
- package/dist/data-sources/TokenDataSource.cjs.map +1 -1
- package/dist/data-sources/TokenDataSource.d.cts +1 -0
- package/dist/data-sources/TokenDataSource.d.cts.map +1 -1
- package/dist/data-sources/TokenDataSource.d.mts +1 -0
- package/dist/data-sources/TokenDataSource.d.mts.map +1 -1
- package/dist/data-sources/TokenDataSource.mjs +12 -5
- package/dist/data-sources/TokenDataSource.mjs.map +1 -1
- package/dist/data-sources/evm-rpc-services/index.cjs +5 -1
- package/dist/data-sources/evm-rpc-services/index.cjs.map +1 -1
- package/dist/data-sources/evm-rpc-services/index.d.cts +1 -1
- package/dist/data-sources/evm-rpc-services/index.d.cts.map +1 -1
- package/dist/data-sources/evm-rpc-services/index.d.mts +1 -1
- package/dist/data-sources/evm-rpc-services/index.d.mts.map +1 -1
- package/dist/data-sources/evm-rpc-services/index.mjs +1 -1
- package/dist/data-sources/evm-rpc-services/index.mjs.map +1 -1
- package/dist/data-sources/evm-rpc-services/services/StakedBalanceFetcher.cjs +132 -0
- package/dist/data-sources/evm-rpc-services/services/StakedBalanceFetcher.cjs.map +1 -0
- package/dist/data-sources/evm-rpc-services/services/StakedBalanceFetcher.d.cts +78 -0
- package/dist/data-sources/evm-rpc-services/services/StakedBalanceFetcher.d.cts.map +1 -0
- package/dist/data-sources/evm-rpc-services/services/StakedBalanceFetcher.d.mts +78 -0
- package/dist/data-sources/evm-rpc-services/services/StakedBalanceFetcher.d.mts.map +1 -0
- package/dist/data-sources/evm-rpc-services/services/StakedBalanceFetcher.mjs +126 -0
- package/dist/data-sources/evm-rpc-services/services/StakedBalanceFetcher.mjs.map +1 -0
- package/dist/data-sources/evm-rpc-services/services/TokenDetector.cjs +16 -0
- package/dist/data-sources/evm-rpc-services/services/TokenDetector.cjs.map +1 -1
- package/dist/data-sources/evm-rpc-services/services/TokenDetector.d.cts +5 -1
- package/dist/data-sources/evm-rpc-services/services/TokenDetector.d.cts.map +1 -1
- package/dist/data-sources/evm-rpc-services/services/TokenDetector.d.mts +5 -1
- package/dist/data-sources/evm-rpc-services/services/TokenDetector.d.mts.map +1 -1
- package/dist/data-sources/evm-rpc-services/services/TokenDetector.mjs +16 -0
- package/dist/data-sources/evm-rpc-services/services/TokenDetector.mjs.map +1 -1
- package/dist/data-sources/evm-rpc-services/services/index.cjs +6 -1
- package/dist/data-sources/evm-rpc-services/services/index.cjs.map +1 -1
- package/dist/data-sources/evm-rpc-services/services/index.d.cts +1 -0
- package/dist/data-sources/evm-rpc-services/services/index.d.cts.map +1 -1
- package/dist/data-sources/evm-rpc-services/services/index.d.mts +1 -0
- package/dist/data-sources/evm-rpc-services/services/index.d.mts.map +1 -1
- package/dist/data-sources/evm-rpc-services/services/index.mjs +1 -0
- package/dist/data-sources/evm-rpc-services/services/index.mjs.map +1 -1
- package/dist/data-sources/evm-rpc-services/types/services.cjs.map +1 -1
- package/dist/data-sources/evm-rpc-services/types/services.d.cts +4 -0
- package/dist/data-sources/evm-rpc-services/types/services.d.cts.map +1 -1
- package/dist/data-sources/evm-rpc-services/types/services.d.mts +4 -0
- package/dist/data-sources/evm-rpc-services/types/services.d.mts.map +1 -1
- package/dist/data-sources/evm-rpc-services/types/services.mjs.map +1 -1
- package/dist/data-sources/evm-rpc-services/types/state.cjs.map +1 -1
- package/dist/data-sources/evm-rpc-services/types/state.d.cts +3 -3
- package/dist/data-sources/evm-rpc-services/types/state.d.cts.map +1 -1
- package/dist/data-sources/evm-rpc-services/types/state.d.mts +3 -3
- package/dist/data-sources/evm-rpc-services/types/state.d.mts.map +1 -1
- package/dist/data-sources/evm-rpc-services/types/state.mjs.map +1 -1
- package/dist/data-sources/evm-rpc-services/utils/index.cjs +9 -1
- package/dist/data-sources/evm-rpc-services/utils/index.cjs.map +1 -1
- package/dist/data-sources/evm-rpc-services/utils/index.d.cts +2 -0
- package/dist/data-sources/evm-rpc-services/utils/index.d.cts.map +1 -1
- package/dist/data-sources/evm-rpc-services/utils/index.d.mts +2 -0
- package/dist/data-sources/evm-rpc-services/utils/index.d.mts.map +1 -1
- package/dist/data-sources/evm-rpc-services/utils/index.mjs +2 -0
- package/dist/data-sources/evm-rpc-services/utils/index.mjs.map +1 -1
- package/dist/data-sources/evm-rpc-services/utils/parsing.cjs +47 -0
- package/dist/data-sources/evm-rpc-services/utils/parsing.cjs.map +1 -0
- package/dist/data-sources/evm-rpc-services/utils/parsing.d.cts +25 -0
- package/dist/data-sources/evm-rpc-services/utils/parsing.d.cts.map +1 -0
- package/dist/data-sources/evm-rpc-services/utils/parsing.d.mts +25 -0
- package/dist/data-sources/evm-rpc-services/utils/parsing.d.mts.map +1 -0
- package/dist/data-sources/evm-rpc-services/utils/parsing.mjs +39 -0
- package/dist/data-sources/evm-rpc-services/utils/parsing.mjs.map +1 -0
- package/dist/data-sources/evm-rpc-services/utils/staking-contracts.cjs +68 -0
- package/dist/data-sources/evm-rpc-services/utils/staking-contracts.cjs.map +1 -0
- package/dist/data-sources/evm-rpc-services/utils/staking-contracts.d.cts +25 -0
- package/dist/data-sources/evm-rpc-services/utils/staking-contracts.d.cts.map +1 -0
- package/dist/data-sources/evm-rpc-services/utils/staking-contracts.d.mts +25 -0
- package/dist/data-sources/evm-rpc-services/utils/staking-contracts.d.mts.map +1 -0
- package/dist/data-sources/evm-rpc-services/utils/staking-contracts.mjs +62 -0
- package/dist/data-sources/evm-rpc-services/utils/staking-contracts.mjs.map +1 -0
- package/dist/data-sources/index.cjs +3 -1
- package/dist/data-sources/index.cjs.map +1 -1
- package/dist/data-sources/index.d.cts +3 -2
- package/dist/data-sources/index.d.cts.map +1 -1
- package/dist/data-sources/index.d.mts +3 -2
- package/dist/data-sources/index.d.mts.map +1 -1
- package/dist/data-sources/index.mjs +1 -0
- package/dist/data-sources/index.mjs.map +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +3 -3
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/middlewares/DetectionMiddleware.cjs +4 -1
- package/dist/middlewares/DetectionMiddleware.cjs.map +1 -1
- package/dist/middlewares/DetectionMiddleware.d.cts +1 -0
- package/dist/middlewares/DetectionMiddleware.d.cts.map +1 -1
- package/dist/middlewares/DetectionMiddleware.d.mts +1 -0
- package/dist/middlewares/DetectionMiddleware.d.mts.map +1 -1
- package/dist/middlewares/DetectionMiddleware.mjs +4 -1
- package/dist/middlewares/DetectionMiddleware.mjs.map +1 -1
- package/dist/selectors/balance.cjs +2 -2
- package/dist/selectors/balance.cjs.map +1 -1
- package/dist/selectors/balance.d.cts.map +1 -1
- package/dist/selectors/balance.d.mts.map +1 -1
- package/dist/selectors/balance.mjs +2 -2
- package/dist/selectors/balance.mjs.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +3 -3
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +3 -3
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/package.json +13 -10
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TokenDetector.mjs","sourceRoot":"","sources":["../../../../src/data-sources/evm-rpc-services/services/TokenDetector.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,mCAAmC,EAAE,qCAAqC;AAiBnF,OAAO,EAAE,uBAAuB,EAAE,2BAAiB;AAEnD,MAAM,0BAA0B,GAAG,MAAO,CAAC,CAAC,YAAY;AAiCxD;;;GAGG;AACH,MAAM,OAAO,aAAc,SAAQ,mCAAmC,EAAyB;IAS7F,YACE,eAAgC,EAChC,SAAiC,EACjC,MAA4B;QAE5B,KAAK,EAAE,CAAC;;QAbD,iDAAkC;QAElC,2CAAmC;QAEnC,wCAAgE;QAEzE,mDAA0D;QAQxD,uBAAA,IAAI,kCAAoB,eAAe,MAAA,CAAC;QACxC,uBAAA,IAAI,4BAAc,SAAS,MAAA,CAAC;QAC5B,uBAAA,IAAI,yBAAW;YACb,gBAAgB,EAAE,MAAM,EAAE,gBAAgB,IAAI,GAAG;YACjD,gBAAgB,EAAE,MAAM,EAAE,gBAAgB,IAAI,KAAK;SACpD,MAAA,CAAC;QAEF,2BAA2B;QAC3B,IAAI,CAAC,iBAAiB,CACpB,MAAM,EAAE,eAAe,IAAI,0BAA0B,CACtD,CAAC;IACJ,CAAC;IAED;;;;OAIG;IACH,oBAAoB,CAAC,QAAmC;QACtD,uBAAA,IAAI,oCAAsB,QAAQ,MAAA,CAAC;IACrC,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,YAAY,CAAC,KAA4B;QAC7C,kDAA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C,WAAW,EAAE,CAAC;IAChD,KAAK,MAAM,CAAC,OAAO,EAAE,QAAQ,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,EAAE,CAAC;QACjE,IAAI,OAAO,CAAC,WAAW,EAAE,KAAK,YAAY,EAAE,CAAC;YAC3C,OAAO,QAAQ,CAAC;QAClB,CAAC;IACH,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC,mEAGC,OAAgB,EAChB,YAAqB,EACrB,QAAoC;IAEpC,MAAM,cAAc,GAAG,QAAQ,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;IAE7C,MAAM,OAAO,GACX,UAAU,cAAc,UAAU,YAAY,CAAC,WAAW,EAAE,EAAmB,CAAC;IAElF,OAAO;QACL,OAAO;QACP,OAAO;QACP,OAAO,EAAE,YAAY;QACrB,IAAI,EAAE,OAAO;QACb,MAAM,EAAE,QAAQ,EAAE,MAAM;QACxB,IAAI,EAAE,QAAQ,EAAE,IAAI;QACpB,QAAQ,EAAE,QAAQ,EAAE,QAAQ;QAC5B,KAAK,EAAE,QAAQ,EAAE,OAAO;QACxB,QAAQ,EAAE,KAAK;QACf,WAAW,EAAE,QAAQ,EAAE,WAAW;KACnC,CAAC;AACJ,CAAC","sourcesContent":["import { StaticIntervalPollingControllerOnly } from '@metamask/polling-controller';\nimport type { CaipAssetType } from '@metamask/utils';\n\nimport type { MulticallClient } from '../clients';\nimport type {\n AccountId,\n Address,\n Asset,\n AssetBalance,\n BalanceOfRequest,\n BalanceOfResponse,\n ChainId,\n TokenDetectionOptions,\n TokenDetectionResult,\n TokenListEntry,\n TokenListState,\n} from '../types';\nimport { reduceInBatchesSerially } from '../utils';\n\nconst DEFAULT_DETECTION_INTERVAL = 180_000; // 3 minutes\n\n/**\n * Minimal messenger interface for TokenDetector.\n */\nexport type TokenDetectorMessenger = {\n call: (action: 'TokenListController:getState') => TokenListState;\n};\n\nexport type TokenDetectorConfig = {\n defaultBatchSize?: number;\n defaultTimeoutMs?: number;\n /** Polling interval in ms (default: 3 minutes) */\n pollingInterval?: number;\n};\n\n/**\n * Polling input for TokenDetector - identifies what to poll for.\n */\nexport type DetectionPollingInput = {\n /** Chain ID (hex format) */\n chainId: ChainId;\n /** Account ID */\n accountId: AccountId;\n /** Account address */\n accountAddress: Address;\n};\n\n/**\n * Callback type for token detection updates.\n */\nexport type OnDetectionUpdateCallback = (result: TokenDetectionResult) => void;\n\n/**\n * TokenDetector - Detects tokens with non-zero balances via multicall.\n * Extends StaticIntervalPollingControllerOnly for built-in polling support.\n */\nexport class TokenDetector extends StaticIntervalPollingControllerOnly<DetectionPollingInput>() {\n readonly #multicallClient: MulticallClient;\n\n readonly #messenger: TokenDetectorMessenger;\n\n readonly #config: Required<Omit<TokenDetectorConfig, 'pollingInterval'>>;\n\n #onDetectionUpdate: OnDetectionUpdateCallback | undefined;\n\n constructor(\n multicallClient: MulticallClient,\n messenger: TokenDetectorMessenger,\n config?: TokenDetectorConfig,\n ) {\n super();\n this.#multicallClient = multicallClient;\n this.#messenger = messenger;\n this.#config = {\n defaultBatchSize: config?.defaultBatchSize ?? 300,\n defaultTimeoutMs: config?.defaultTimeoutMs ?? 30000,\n };\n\n // Set the polling interval\n this.setIntervalLength(\n config?.pollingInterval ?? DEFAULT_DETECTION_INTERVAL,\n );\n }\n\n /**\n * Set the callback to receive detection updates during polling.\n *\n * @param callback - Function to call with detection results.\n */\n setOnDetectionUpdate(callback: OnDetectionUpdateCallback): void {\n this.#onDetectionUpdate = callback;\n }\n\n /**\n * Execute a poll cycle (required by base class).\n * Detects tokens and calls the update callback.\n *\n * @param input - The polling input.\n */\n async _executePoll(input: DetectionPollingInput): Promise<void> {\n // Check if token list is available for this chain\n const tokensToCheck = this.getTokensToCheck(input.chainId);\n if (tokensToCheck.length === 0) {\n // No tokens in list for chain, will retry on next poll\n return;\n }\n\n const result = await this.detectTokens(\n input.chainId,\n input.accountId,\n input.accountAddress,\n );\n\n if (this.#onDetectionUpdate && result.detectedAssets.length > 0) {\n this.#onDetectionUpdate(result);\n }\n }\n\n getTokensToCheck(chainId: ChainId): Address[] {\n const tokenListState = this.#messenger.call('TokenListController:getState');\n\n // Defensive check for tokensChainsCache\n if (!tokenListState?.tokensChainsCache) {\n return [];\n }\n\n // Try direct lookup first\n let chainCacheEntry = tokenListState.tokensChainsCache[chainId];\n\n // If not found, try normalizing the chain ID (e.g., 0x0a -> 0xa)\n if (!chainCacheEntry) {\n const normalizedChainId: ChainId = `0x${parseInt(chainId, 16).toString(\n 16,\n )}`;\n chainCacheEntry = tokenListState.tokensChainsCache[normalizedChainId];\n }\n\n const chainTokenList = chainCacheEntry?.data;\n\n if (!chainTokenList) {\n return [];\n }\n\n return Object.keys(chainTokenList) as Address[];\n }\n\n async detectTokens(\n chainId: ChainId,\n accountId: AccountId,\n accountAddress: Address,\n options?: TokenDetectionOptions,\n ): Promise<TokenDetectionResult> {\n const batchSize = options?.batchSize ?? this.#config.defaultBatchSize;\n const timestamp = Date.now();\n\n const tokensToCheck = this.getTokensToCheck(chainId);\n\n if (tokensToCheck.length === 0) {\n return {\n chainId,\n accountId,\n accountAddress,\n detectedAssets: [],\n detectedBalances: [],\n zeroBalanceAddresses: [],\n failedAddresses: [],\n timestamp,\n };\n }\n\n const balanceRequests: BalanceOfRequest[] = tokensToCheck.map(\n (tokenAddress) => ({\n tokenAddress,\n accountAddress,\n }),\n );\n\n type DetectionAccumulator = {\n detectedAssets: Asset[];\n detectedBalances: AssetBalance[];\n zeroBalanceAddresses: Address[];\n failedAddresses: Address[];\n };\n\n const result = await reduceInBatchesSerially<\n BalanceOfRequest,\n DetectionAccumulator\n >({\n values: balanceRequests,\n batchSize,\n initialResult: {\n detectedAssets: [],\n detectedBalances: [],\n zeroBalanceAddresses: [],\n failedAddresses: [],\n },\n eachBatch: async (workingResult, batch) => {\n const responses = await this.#multicallClient.batchBalanceOf(\n chainId,\n batch,\n );\n\n return this.#processBalanceResponses(\n responses,\n workingResult as DetectionAccumulator,\n chainId,\n accountId,\n timestamp,\n );\n },\n });\n\n return {\n chainId,\n accountId,\n accountAddress,\n ...result,\n timestamp,\n };\n }\n\n #processBalanceResponses(\n responses: BalanceOfResponse[],\n accumulator: {\n detectedAssets: Asset[];\n detectedBalances: AssetBalance[];\n zeroBalanceAddresses: Address[];\n failedAddresses: Address[];\n },\n chainId: ChainId,\n accountId: AccountId,\n timestamp: number,\n ): {\n detectedAssets: Asset[];\n detectedBalances: AssetBalance[];\n zeroBalanceAddresses: Address[];\n failedAddresses: Address[];\n } {\n const {\n detectedAssets,\n detectedBalances,\n zeroBalanceAddresses,\n failedAddresses,\n } = accumulator;\n\n for (const response of responses) {\n if (!response.success) {\n failedAddresses.push(response.tokenAddress);\n continue;\n }\n\n const balance = response.balance ?? '0';\n\n if (balance === '0' || balance === '') {\n zeroBalanceAddresses.push(response.tokenAddress);\n continue;\n }\n\n const tokenMetadata = this.#getTokenMetadata(\n chainId,\n response.tokenAddress,\n );\n\n const asset = this.#createAsset(\n chainId,\n response.tokenAddress,\n tokenMetadata,\n );\n detectedAssets.push(asset);\n\n const decimals = tokenMetadata?.decimals ?? 18;\n const formattedBalance = this.#formatBalance(balance, decimals);\n\n detectedBalances.push({\n assetId: asset.assetId,\n accountId,\n chainId,\n balance,\n formattedBalance,\n decimals,\n timestamp,\n });\n }\n\n return {\n detectedAssets,\n detectedBalances,\n zeroBalanceAddresses,\n failedAddresses,\n };\n }\n\n #formatBalance(rawBalance: string, decimals: number): string {\n try {\n const balanceBigInt = BigInt(rawBalance);\n const divisor = BigInt(10 ** decimals);\n\n const integerPart = balanceBigInt / divisor;\n const remainder = balanceBigInt % divisor;\n const fractionalStr = remainder.toString().padStart(decimals, '0');\n const trimmedFractional = fractionalStr.replace(/0+$/u, '');\n\n if (trimmedFractional === '') {\n return integerPart.toString();\n }\n\n return `${integerPart}.${trimmedFractional}`;\n } catch {\n return rawBalance;\n }\n }\n\n #getTokenMetadata(\n chainId: ChainId,\n tokenAddress: Address,\n ): TokenListEntry | undefined {\n const tokenListState = this.#messenger.call('TokenListController:getState');\n if (!tokenListState?.tokensChainsCache) {\n return undefined;\n }\n\n const chainCacheEntry = tokenListState.tokensChainsCache[chainId];\n const chainTokenList = chainCacheEntry?.data;\n if (!chainTokenList) {\n return undefined;\n }\n\n if (chainTokenList[tokenAddress]) {\n return chainTokenList[tokenAddress];\n }\n\n const lowerAddress = tokenAddress.toLowerCase();\n for (const [address, metadata] of Object.entries(chainTokenList)) {\n if (address.toLowerCase() === lowerAddress) {\n return metadata;\n }\n }\n\n return undefined;\n }\n\n #createAsset(\n chainId: ChainId,\n tokenAddress: Address,\n metadata: TokenListEntry | undefined,\n ): Asset {\n const chainIdDecimal = parseInt(chainId, 16);\n\n const assetId =\n `eip155:${chainIdDecimal}/erc20:${tokenAddress.toLowerCase()}` as CaipAssetType;\n\n return {\n assetId,\n chainId,\n address: tokenAddress,\n type: 'erc20',\n symbol: metadata?.symbol,\n name: metadata?.name,\n decimals: metadata?.decimals,\n image: metadata?.iconUrl,\n isNative: false,\n aggregators: metadata?.aggregators,\n };\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"TokenDetector.mjs","sourceRoot":"","sources":["../../../../src/data-sources/evm-rpc-services/services/TokenDetector.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,mCAAmC,EAAE,qCAAqC;AAiBnF,OAAO,EAAE,uBAAuB,EAAE,2BAAiB;AAEnD,MAAM,0BAA0B,GAAG,MAAO,CAAC,CAAC,YAAY;AAqCxD;;;GAGG;AACH,MAAM,OAAO,aAAc,SAAQ,mCAAmC,EAAyB;IAS7F,YACE,eAAgC,EAChC,SAAiC,EACjC,MAA4B;QAE5B,KAAK,EAAE,CAAC;;QAbD,iDAAkC;QAElC,2CAAmC;QAEnC,wCAAgE;QAEzE,mDAA0D;QAQxD,uBAAA,IAAI,kCAAoB,eAAe,MAAA,CAAC;QACxC,uBAAA,IAAI,4BAAc,SAAS,MAAA,CAAC;QAC5B,uBAAA,IAA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AC3C,OAAO,QAAQ,CAAC;QAClB,CAAC;IACH,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC,mEAGC,OAAgB,EAChB,YAAqB,EACrB,QAAoC;IAEpC,MAAM,cAAc,GAAG,QAAQ,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;IAE7C,MAAM,OAAO,GACX,UAAU,cAAc,UAAU,YAAY,CAAC,WAAW,EAAE,EAAmB,CAAC;IAElF,OAAO;QACL,OAAO;QACP,OAAO;QACP,OAAO,EAAE,YAAY;QACrB,IAAI,EAAE,OAAO;QACb,MAAM,EAAE,QAAQ,EAAE,MAAM;QACxB,IAAI,EAAE,QAAQ,EAAE,IAAI;QACpB,QAAQ,EAAE,QAAQ,EAAE,QAAQ;QAC5B,KAAK,EAAE,QAAQ,EAAE,OAAO;QACxB,QAAQ,EAAE,KAAK;QACf,WAAW,EAAE,QAAQ,EAAE,WAAW;KACnC,CAAC;AACJ,CAAC","sourcesContent":["import { StaticIntervalPollingControllerOnly } from '@metamask/polling-controller';\nimport type { CaipAssetType } from '@metamask/utils';\n\nimport type { MulticallClient } from '../clients';\nimport type {\n AccountId,\n Address,\n Asset,\n AssetBalance,\n BalanceOfRequest,\n BalanceOfResponse,\n ChainId,\n TokenDetectionOptions,\n TokenDetectionResult,\n TokenListEntry,\n TokenListState,\n} from '../types';\nimport { reduceInBatchesSerially } from '../utils';\n\nconst DEFAULT_DETECTION_INTERVAL = 180_000; // 3 minutes\n\n/**\n * Minimal messenger interface for TokenDetector.\n */\nexport type TokenDetectorMessenger = {\n call: (action: 'TokenListController:getState') => TokenListState;\n};\n\nexport type TokenDetectorConfig = {\n /** Function returning whether token detection is enabled (avoids stale value) */\n tokenDetectionEnabled?: () => boolean;\n /** Function returning whether external services are allowed (avoids stale value; default: () => true) */\n useExternalService?: () => boolean;\n defaultBatchSize?: number;\n defaultTimeoutMs?: number;\n /** Polling interval in ms (default: 3 minutes) */\n pollingInterval?: number;\n};\n\n/**\n * Polling input for TokenDetector - identifies what to poll for.\n */\nexport type DetectionPollingInput = {\n /** Chain ID (hex format) */\n chainId: ChainId;\n /** Account ID */\n accountId: AccountId;\n /** Account address */\n accountAddress: Address;\n};\n\n/**\n * Callback type for token detection updates.\n */\nexport type OnDetectionUpdateCallback = (result: TokenDetectionResult) => void;\n\n/**\n * TokenDetector - Detects tokens with non-zero balances via multicall.\n * Extends StaticIntervalPollingControllerOnly for built-in polling support.\n */\nexport class TokenDetector extends StaticIntervalPollingControllerOnly<DetectionPollingInput>() {\n readonly #multicallClient: MulticallClient;\n\n readonly #messenger: TokenDetectorMessenger;\n\n readonly #config: Required<Omit<TokenDetectorConfig, 'pollingInterval'>>;\n\n #onDetectionUpdate: OnDetectionUpdateCallback | undefined;\n\n constructor(\n multicallClient: MulticallClient,\n messenger: TokenDetectorMessenger,\n config?: TokenDetectorConfig,\n ) {\n super();\n this.#multicallClient = multicallClient;\n this.#messenger = messenger;\n this.#config = {\n tokenDetectionEnabled:\n config?.tokenDetectionEnabled ?? ((): boolean => true),\n useExternalService: config?.useExternalService ?? ((): boolean => true),\n defaultBatchSize: config?.defaultBatchSize ?? 300,\n defaultTimeoutMs: config?.defaultTimeoutMs ?? 30000,\n };\n\n // Set the polling interval\n this.setIntervalLength(\n config?.pollingInterval ?? DEFAULT_DETECTION_INTERVAL,\n );\n }\n\n /**\n * Set the callback to receive detection updates during polling.\n *\n * @param callback - Function to call with detection results.\n */\n setOnDetectionUpdate(callback: OnDetectionUpdateCallback): void {\n this.#onDetectionUpdate = callback;\n }\n\n /**\n * Execute a poll cycle (required by base class).\n * Detects tokens and calls the update callback.\n *\n * @param input - The polling input.\n */\n async _executePoll(input: DetectionPollingInput): Promise<void> {\n // Check if token list is available for this chain\n const tokensToCheck = this.getTokensToCheck(input.chainId);\n if (tokensToCheck.length === 0) {\n // No tokens in list for chain, will retry on next poll\n return;\n }\n\n const result = await this.detectTokens(\n input.chainId,\n input.accountId,\n input.accountAddress,\n );\n\n if (this.#onDetectionUpdate && result.detectedAssets.length > 0) {\n this.#onDetectionUpdate(result);\n }\n }\n\n getTokensToCheck(chainId: ChainId): Address[] {\n const tokenListState = this.#messenger.call('TokenListController:getState');\n\n // Defensive check for tokensChainsCache\n if (!tokenListState?.tokensChainsCache) {\n return [];\n }\n\n // Try direct lookup first\n let chainCacheEntry = tokenListState.tokensChainsCache[chainId];\n\n // If not found, try normalizing the chain ID (e.g., 0x0a -> 0xa)\n if (!chainCacheEntry) {\n const normalizedChainId: ChainId = `0x${parseInt(chainId, 16).toString(\n 16,\n )}`;\n chainCacheEntry = tokenListState.tokensChainsCache[normalizedChainId];\n }\n\n const chainTokenList = chainCacheEntry?.data;\n\n if (!chainTokenList) {\n return [];\n }\n\n return Object.keys(chainTokenList) as Address[];\n }\n\n async detectTokens(\n chainId: ChainId,\n accountId: AccountId,\n accountAddress: Address,\n options?: TokenDetectionOptions,\n ): Promise<TokenDetectionResult> {\n const tokenDetectionEnabled =\n options?.tokenDetectionEnabled ?? this.#config.tokenDetectionEnabled();\n const useExternalService =\n options?.useExternalService ?? this.#config.useExternalService();\n if (!tokenDetectionEnabled || !useExternalService) {\n return {\n chainId,\n accountId,\n accountAddress,\n detectedAssets: [],\n detectedBalances: [],\n zeroBalanceAddresses: [],\n failedAddresses: [],\n timestamp: Date.now(),\n };\n }\n const batchSize = options?.batchSize ?? this.#config.defaultBatchSize;\n const timestamp = Date.now();\n\n const tokensToCheck = this.getTokensToCheck(chainId);\n\n if (tokensToCheck.length === 0) {\n return {\n chainId,\n accountId,\n accountAddress,\n detectedAssets: [],\n detectedBalances: [],\n zeroBalanceAddresses: [],\n failedAddresses: [],\n timestamp,\n };\n }\n\n const balanceRequests: BalanceOfRequest[] = tokensToCheck.map(\n (tokenAddress) => ({\n tokenAddress,\n accountAddress,\n }),\n );\n\n type DetectionAccumulator = {\n detectedAssets: Asset[];\n detectedBalances: AssetBalance[];\n zeroBalanceAddresses: Address[];\n failedAddresses: Address[];\n };\n\n const result = await reduceInBatchesSerially<\n BalanceOfRequest,\n DetectionAccumulator\n >({\n values: balanceRequests,\n batchSize,\n initialResult: {\n detectedAssets: [],\n detectedBalances: [],\n zeroBalanceAddresses: [],\n failedAddresses: [],\n },\n eachBatch: async (workingResult, batch) => {\n const responses = await this.#multicallClient.batchBalanceOf(\n chainId,\n batch,\n );\n\n return this.#processBalanceResponses(\n responses,\n workingResult as DetectionAccumulator,\n chainId,\n accountId,\n timestamp,\n );\n },\n });\n\n return {\n chainId,\n accountId,\n accountAddress,\n ...result,\n timestamp,\n };\n }\n\n #processBalanceResponses(\n responses: BalanceOfResponse[],\n accumulator: {\n detectedAssets: Asset[];\n detectedBalances: AssetBalance[];\n zeroBalanceAddresses: Address[];\n failedAddresses: Address[];\n },\n chainId: ChainId,\n accountId: AccountId,\n timestamp: number,\n ): {\n detectedAssets: Asset[];\n detectedBalances: AssetBalance[];\n zeroBalanceAddresses: Address[];\n failedAddresses: Address[];\n } {\n const {\n detectedAssets,\n detectedBalances,\n zeroBalanceAddresses,\n failedAddresses,\n } = accumulator;\n\n for (const response of responses) {\n if (!response.success) {\n failedAddresses.push(response.tokenAddress);\n continue;\n }\n\n const balance = response.balance ?? '0';\n\n if (balance === '0' || balance === '') {\n zeroBalanceAddresses.push(response.tokenAddress);\n continue;\n }\n\n const tokenMetadata = this.#getTokenMetadata(\n chainId,\n response.tokenAddress,\n );\n\n const asset = this.#createAsset(\n chainId,\n response.tokenAddress,\n tokenMetadata,\n );\n detectedAssets.push(asset);\n\n const decimals = tokenMetadata?.decimals ?? 18;\n const formattedBalance = this.#formatBalance(balance, decimals);\n\n detectedBalances.push({\n assetId: asset.assetId,\n accountId,\n chainId,\n balance,\n formattedBalance,\n decimals,\n timestamp,\n });\n }\n\n return {\n detectedAssets,\n detectedBalances,\n zeroBalanceAddresses,\n failedAddresses,\n };\n }\n\n #formatBalance(rawBalance: string, decimals: number): string {\n try {\n const balanceBigInt = BigInt(rawBalance);\n const divisor = BigInt(10 ** decimals);\n\n const integerPart = balanceBigInt / divisor;\n const remainder = balanceBigInt % divisor;\n const fractionalStr = remainder.toString().padStart(decimals, '0');\n const trimmedFractional = fractionalStr.replace(/0+$/u, '');\n\n if (trimmedFractional === '') {\n return integerPart.toString();\n }\n\n return `${integerPart}.${trimmedFractional}`;\n } catch {\n return rawBalance;\n }\n }\n\n #getTokenMetadata(\n chainId: ChainId,\n tokenAddress: Address,\n ): TokenListEntry | undefined {\n const tokenListState = this.#messenger.call('TokenListController:getState');\n if (!tokenListState?.tokensChainsCache) {\n return undefined;\n }\n\n const chainCacheEntry = tokenListState.tokensChainsCache[chainId];\n const chainTokenList = chainCacheEntry?.data;\n if (!chainTokenList) {\n return undefined;\n }\n\n if (chainTokenList[tokenAddress]) {\n return chainTokenList[tokenAddress];\n }\n\n const lowerAddress = tokenAddress.toLowerCase();\n for (const [address, metadata] of Object.entries(chainTokenList)) {\n if (address.toLowerCase() === lowerAddress) {\n return metadata;\n }\n }\n\n return undefined;\n }\n\n #createAsset(\n chainId: ChainId,\n tokenAddress: Address,\n metadata: TokenListEntry | undefined,\n ): Asset {\n const chainIdDecimal = parseInt(chainId, 16);\n\n const assetId =\n `eip155:${chainIdDecimal}/erc20:${tokenAddress.toLowerCase()}` as CaipAssetType;\n\n return {\n assetId,\n chainId,\n address: tokenAddress,\n type: 'erc20',\n symbol: metadata?.symbol,\n name: metadata?.name,\n decimals: metadata?.decimals,\n image: metadata?.iconUrl,\n isNative: false,\n aggregators: metadata?.aggregators,\n };\n }\n}\n"]}
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BalanceFetcher = exports.TokenDetector = void 0;
|
|
3
|
+
exports.isStakingContractAssetId = exports.getStakingContractAddress = exports.getSupportedStakingChainIds = exports.StakedBalanceFetcher = exports.BalanceFetcher = exports.TokenDetector = void 0;
|
|
4
4
|
var TokenDetector_1 = require("./TokenDetector.cjs");
|
|
5
5
|
Object.defineProperty(exports, "TokenDetector", { enumerable: true, get: function () { return TokenDetector_1.TokenDetector; } });
|
|
6
6
|
var BalanceFetcher_1 = require("./BalanceFetcher.cjs");
|
|
7
7
|
Object.defineProperty(exports, "BalanceFetcher", { enumerable: true, get: function () { return BalanceFetcher_1.BalanceFetcher; } });
|
|
8
|
+
var StakedBalanceFetcher_1 = require("./StakedBalanceFetcher.cjs");
|
|
9
|
+
Object.defineProperty(exports, "StakedBalanceFetcher", { enumerable: true, get: function () { return StakedBalanceFetcher_1.StakedBalanceFetcher; } });
|
|
10
|
+
Object.defineProperty(exports, "getSupportedStakingChainIds", { enumerable: true, get: function () { return StakedBalanceFetcher_1.getSupportedStakingChainIds; } });
|
|
11
|
+
Object.defineProperty(exports, "getStakingContractAddress", { enumerable: true, get: function () { return StakedBalanceFetcher_1.getStakingContractAddress; } });
|
|
12
|
+
Object.defineProperty(exports, "isStakingContractAssetId", { enumerable: true, get: function () { return StakedBalanceFetcher_1.isStakingContractAssetId; } });
|
|
8
13
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../../../src/data-sources/evm-rpc-services/services/index.ts"],"names":[],"mappings":";;;AAAA,qDAMyB;AALvB,8GAAA,aAAa,OAAA;AAMf,uDAM0B;AALxB,gHAAA,cAAc,OAAA","sourcesContent":["export {\n TokenDetector,\n type TokenDetectorConfig,\n type TokenDetectorMessenger,\n type DetectionPollingInput,\n type OnDetectionUpdateCallback,\n} from './TokenDetector';\nexport {\n BalanceFetcher,\n type BalanceFetcherConfig,\n type BalanceFetcherMessenger,\n type BalancePollingInput,\n type OnBalanceUpdateCallback,\n} from './BalanceFetcher';\n"]}
|
|
1
|
+
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../../../src/data-sources/evm-rpc-services/services/index.ts"],"names":[],"mappings":";;;AAAA,qDAMyB;AALvB,8GAAA,aAAa,OAAA;AAMf,uDAM0B;AALxB,gHAAA,cAAc,OAAA;AAMhB,mEASgC;AAR9B,4HAAA,oBAAoB,OAAA;AACpB,mIAAA,2BAA2B,OAAA;AAC3B,iIAAA,yBAAyB,OAAA;AACzB,gIAAA,wBAAwB,OAAA","sourcesContent":["export {\n TokenDetector,\n type TokenDetectorConfig,\n type TokenDetectorMessenger,\n type DetectionPollingInput,\n type OnDetectionUpdateCallback,\n} from './TokenDetector';\nexport {\n BalanceFetcher,\n type BalanceFetcherConfig,\n type BalanceFetcherMessenger,\n type BalancePollingInput,\n type OnBalanceUpdateCallback,\n} from './BalanceFetcher';\nexport {\n StakedBalanceFetcher,\n getSupportedStakingChainIds,\n getStakingContractAddress,\n isStakingContractAssetId,\n type StakedBalanceFetcherConfig,\n type StakedBalancePollingInput,\n type StakedBalanceFetchResult,\n type OnStakedBalanceUpdateCallback,\n} from './StakedBalanceFetcher';\n"]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export { TokenDetector, type TokenDetectorConfig, type TokenDetectorMessenger, type DetectionPollingInput, type OnDetectionUpdateCallback, } from "./TokenDetector.cjs";
|
|
2
2
|
export { BalanceFetcher, type BalanceFetcherConfig, type BalanceFetcherMessenger, type BalancePollingInput, type OnBalanceUpdateCallback, } from "./BalanceFetcher.cjs";
|
|
3
|
+
export { StakedBalanceFetcher, getSupportedStakingChainIds, getStakingContractAddress, isStakingContractAssetId, type StakedBalanceFetcherConfig, type StakedBalancePollingInput, type StakedBalanceFetchResult, type OnStakedBalanceUpdateCallback, } from "./StakedBalanceFetcher.cjs";
|
|
3
4
|
//# sourceMappingURL=index.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../../../src/data-sources/evm-rpc-services/services/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,KAAK,mBAAmB,EACxB,KAAK,sBAAsB,EAC3B,KAAK,qBAAqB,EAC1B,KAAK,yBAAyB,GAC/B,4BAAwB;AACzB,OAAO,EACL,cAAc,EACd,KAAK,oBAAoB,EACzB,KAAK,uBAAuB,EAC5B,KAAK,mBAAmB,EACxB,KAAK,uBAAuB,GAC7B,6BAAyB"}
|
|
1
|
+
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../../../src/data-sources/evm-rpc-services/services/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,KAAK,mBAAmB,EACxB,KAAK,sBAAsB,EAC3B,KAAK,qBAAqB,EAC1B,KAAK,yBAAyB,GAC/B,4BAAwB;AACzB,OAAO,EACL,cAAc,EACd,KAAK,oBAAoB,EACzB,KAAK,uBAAuB,EAC5B,KAAK,mBAAmB,EACxB,KAAK,uBAAuB,GAC7B,6BAAyB;AAC1B,OAAO,EACL,oBAAoB,EACpB,2BAA2B,EAC3B,yBAAyB,EACzB,wBAAwB,EACxB,KAAK,0BAA0B,EAC/B,KAAK,yBAAyB,EAC9B,KAAK,wBAAwB,EAC7B,KAAK,6BAA6B,GACnC,mCAA+B"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export { TokenDetector, type TokenDetectorConfig, type TokenDetectorMessenger, type DetectionPollingInput, type OnDetectionUpdateCallback, } from "./TokenDetector.mjs";
|
|
2
2
|
export { BalanceFetcher, type BalanceFetcherConfig, type BalanceFetcherMessenger, type BalancePollingInput, type OnBalanceUpdateCallback, } from "./BalanceFetcher.mjs";
|
|
3
|
+
export { StakedBalanceFetcher, getSupportedStakingChainIds, getStakingContractAddress, isStakingContractAssetId, type StakedBalanceFetcherConfig, type StakedBalancePollingInput, type StakedBalanceFetchResult, type OnStakedBalanceUpdateCallback, } from "./StakedBalanceFetcher.mjs";
|
|
3
4
|
//# sourceMappingURL=index.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../../../src/data-sources/evm-rpc-services/services/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,KAAK,mBAAmB,EACxB,KAAK,sBAAsB,EAC3B,KAAK,qBAAqB,EAC1B,KAAK,yBAAyB,GAC/B,4BAAwB;AACzB,OAAO,EACL,cAAc,EACd,KAAK,oBAAoB,EACzB,KAAK,uBAAuB,EAC5B,KAAK,mBAAmB,EACxB,KAAK,uBAAuB,GAC7B,6BAAyB"}
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../../../src/data-sources/evm-rpc-services/services/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,KAAK,mBAAmB,EACxB,KAAK,sBAAsB,EAC3B,KAAK,qBAAqB,EAC1B,KAAK,yBAAyB,GAC/B,4BAAwB;AACzB,OAAO,EACL,cAAc,EACd,KAAK,oBAAoB,EACzB,KAAK,uBAAuB,EAC5B,KAAK,mBAAmB,EACxB,KAAK,uBAAuB,GAC7B,6BAAyB;AAC1B,OAAO,EACL,oBAAoB,EACpB,2BAA2B,EAC3B,yBAAyB,EACzB,wBAAwB,EACxB,KAAK,0BAA0B,EAC/B,KAAK,yBAAyB,EAC9B,KAAK,wBAAwB,EAC7B,KAAK,6BAA6B,GACnC,mCAA+B"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export { TokenDetector } from "./TokenDetector.mjs";
|
|
2
2
|
export { BalanceFetcher } from "./BalanceFetcher.mjs";
|
|
3
|
+
export { StakedBalanceFetcher, getSupportedStakingChainIds, getStakingContractAddress, isStakingContractAssetId } from "./StakedBalanceFetcher.mjs";
|
|
3
4
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../../../src/data-sources/evm-rpc-services/services/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EAKd,4BAAwB;AACzB,OAAO,EACL,cAAc,EAKf,6BAAyB","sourcesContent":["export {\n TokenDetector,\n type TokenDetectorConfig,\n type TokenDetectorMessenger,\n type DetectionPollingInput,\n type OnDetectionUpdateCallback,\n} from './TokenDetector';\nexport {\n BalanceFetcher,\n type BalanceFetcherConfig,\n type BalanceFetcherMessenger,\n type BalancePollingInput,\n type OnBalanceUpdateCallback,\n} from './BalanceFetcher';\n"]}
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../../../src/data-sources/evm-rpc-services/services/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EAKd,4BAAwB;AACzB,OAAO,EACL,cAAc,EAKf,6BAAyB;AAC1B,OAAO,EACL,oBAAoB,EACpB,2BAA2B,EAC3B,yBAAyB,EACzB,wBAAwB,EAKzB,mCAA+B","sourcesContent":["export {\n TokenDetector,\n type TokenDetectorConfig,\n type TokenDetectorMessenger,\n type DetectionPollingInput,\n type OnDetectionUpdateCallback,\n} from './TokenDetector';\nexport {\n BalanceFetcher,\n type BalanceFetcherConfig,\n type BalanceFetcherMessenger,\n type BalancePollingInput,\n type OnBalanceUpdateCallback,\n} from './BalanceFetcher';\nexport {\n StakedBalanceFetcher,\n getSupportedStakingChainIds,\n getStakingContractAddress,\n isStakingContractAssetId,\n type StakedBalanceFetcherConfig,\n type StakedBalancePollingInput,\n type StakedBalanceFetchResult,\n type OnStakedBalanceUpdateCallback,\n} from './StakedBalanceFetcher';\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"services.cjs","sourceRoot":"","sources":["../../../../src/data-sources/evm-rpc-services/types/services.ts"],"names":[],"mappings":"","sourcesContent":["import type { Asset, AssetBalance } from './assets';\nimport type { AccountId, Address, ChainId } from './core';\n\n/**\n * Token detection result.\n */\nexport type TokenDetectionResult = {\n /** Chain ID */\n chainId: ChainId;\n /** Account ID */\n accountId: AccountId;\n /** Account address used for detection */\n accountAddress: Address;\n /** Newly detected tokens with non-zero balances */\n detectedAssets: Asset[];\n /** Balances for newly detected tokens */\n detectedBalances: AssetBalance[];\n /** Tokens that were checked but had zero balance */\n zeroBalanceAddresses: Address[];\n /** Tokens that failed to be checked */\n failedAddresses: Address[];\n /** Timestamp of detection */\n timestamp: number;\n};\n\n/**\n * Token detection options.\n */\nexport type TokenDetectionOptions = {\n /** Maximum number of tokens to check per batch */\n batchSize?: number;\n /** Timeout for detection in milliseconds */\n timeout?: number;\n};\n\n/**\n * Balance fetch result.\n */\nexport type BalanceFetchResult = {\n /** Chain ID */\n chainId: ChainId;\n /** Account ID */\n accountId: AccountId;\n /** Account address */\n accountAddress: Address;\n /** Fetched balances */\n balances: AssetBalance[];\n /** Token addresses that failed to fetch */\n failedAddresses: Address[];\n /** Block number when balances were fetched */\n blockNumber?: number;\n /** Timestamp of fetch */\n timestamp: number;\n};\n\n/**\n * Balance fetch options.\n */\nexport type BalanceFetchOptions = {\n /** Maximum number of tokens to fetch per batch */\n batchSize?: number;\n /** Timeout for fetch in milliseconds */\n timeout?: number;\n /** Include native token balance */\n includeNative?: boolean;\n};\n\n/**\n * Token info for balance fetching.\n */\nexport type TokenFetchInfo = {\n /** Token contract address */\n address: Address;\n /** Token decimals */\n decimals: number;\n /** Token symbol (optional) */\n symbol?: string;\n};\n"]}
|
|
1
|
+
{"version":3,"file":"services.cjs","sourceRoot":"","sources":["../../../../src/data-sources/evm-rpc-services/types/services.ts"],"names":[],"mappings":"","sourcesContent":["import type { Asset, AssetBalance } from './assets';\nimport type { AccountId, Address, ChainId } from './core';\n\n/**\n * Token detection result.\n */\nexport type TokenDetectionResult = {\n /** Chain ID */\n chainId: ChainId;\n /** Account ID */\n accountId: AccountId;\n /** Account address used for detection */\n accountAddress: Address;\n /** Newly detected tokens with non-zero balances */\n detectedAssets: Asset[];\n /** Balances for newly detected tokens */\n detectedBalances: AssetBalance[];\n /** Tokens that were checked but had zero balance */\n zeroBalanceAddresses: Address[];\n /** Tokens that failed to be checked */\n failedAddresses: Address[];\n /** Timestamp of detection */\n timestamp: number;\n};\n\n/**\n * Token detection options.\n */\nexport type TokenDetectionOptions = {\n /** Whether token detection is enabled */\n tokenDetectionEnabled?: boolean;\n /** Whether external services (e.g. token list API) are allowed; detection stops when false */\n useExternalService?: boolean;\n /** Maximum number of tokens to check per batch */\n batchSize?: number;\n /** Timeout for detection in milliseconds */\n timeout?: number;\n};\n\n/**\n * Balance fetch result.\n */\nexport type BalanceFetchResult = {\n /** Chain ID */\n chainId: ChainId;\n /** Account ID */\n accountId: AccountId;\n /** Account address */\n accountAddress: Address;\n /** Fetched balances */\n balances: AssetBalance[];\n /** Token addresses that failed to fetch */\n failedAddresses: Address[];\n /** Block number when balances were fetched */\n blockNumber?: number;\n /** Timestamp of fetch */\n timestamp: number;\n};\n\n/**\n * Balance fetch options.\n */\nexport type BalanceFetchOptions = {\n /** Maximum number of tokens to fetch per batch */\n batchSize?: number;\n /** Timeout for fetch in milliseconds */\n timeout?: number;\n /** Include native token balance */\n includeNative?: boolean;\n};\n\n/**\n * Token info for balance fetching.\n */\nexport type TokenFetchInfo = {\n /** Token contract address */\n address: Address;\n /** Token decimals */\n decimals: number;\n /** Token symbol (optional) */\n symbol?: string;\n};\n"]}
|
|
@@ -25,6 +25,10 @@ export type TokenDetectionResult = {
|
|
|
25
25
|
* Token detection options.
|
|
26
26
|
*/
|
|
27
27
|
export type TokenDetectionOptions = {
|
|
28
|
+
/** Whether token detection is enabled */
|
|
29
|
+
tokenDetectionEnabled?: boolean;
|
|
30
|
+
/** Whether external services (e.g. token list API) are allowed; detection stops when false */
|
|
31
|
+
useExternalService?: boolean;
|
|
28
32
|
/** Maximum number of tokens to check per batch */
|
|
29
33
|
batchSize?: number;
|
|
30
34
|
/** Timeout for detection in milliseconds */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"services.d.cts","sourceRoot":"","sources":["../../../../src/data-sources/evm-rpc-services/types/services.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,qBAAiB;AACpD,OAAO,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,mBAAe;AAE1D;;GAEG;AACH,MAAM,MAAM,oBAAo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AAE,OAAO,CAAC;IACjB,qBAAqB;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,8BAA8B;IAC9B,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC"}
|
|
1
|
+
{"version":3,"file":"services.d.cts","sourceRoot":"","sources":["../../../../src/data-sources/evm-rpc-services/types/services.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,qBAAiB;AACpD,OAAO,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,mBAAe;AAE1D;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG;IACjC,eAAe;IACf,OAAO,EAAE,OAAO,CAAC;IACjB,iBAAiB;IACjB,SAAS,EAAE,SAAS,CAAC;IACrB,yCAAyC;IACzC,cAAc,EAAE,OAAO,CAAC;IACxB,mDAAmD;IACnD,cAAc,EAAE,KAAK,EAAE,CAAC;IACxB,yCAAyC;IACzC,gBAAgB,EAAE,YAAY,EAAE,CAAC;IACjC,oDAAoD;IACpD,oBAAoB,EAAE,OAAO,EAAE,CAAC;IAChC,uCAAuC;IACvC,eAAe,EAAE,OAAO,EAAE,CAAC;IAC3B,6BAA6B;IAC7B,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG;IAClC,yCAAyC;IACzC,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,8FAA8F;IAC9F,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,kDAAkD;IAClD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,4CAA4C;IAC5C,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B,eAAe;IACf,OAAO,EAAE,OAAO,CAAC;IACjB,iBAAiB;IACjB,SAAS,EAAE,SAAS,CAAC;IACrB,sBAAsB;IACtB,cAAc,EAAE,OAAO,CAAC;IACxB,uBAAuB;IACvB,QAAQ,EAAE,YAAY,EAAE,CAAC;IACzB,2CAA2C;IAC3C,eAAe,EAAE,OAAO,EAAE,CAAC;IAC3B,8CAA8C;IAC9C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,yBAAyB;IACzB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG;IAChC,kDAAkD;IAClD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,wCAAwC;IACxC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,mCAAmC;IACnC,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B,6BAA6B;IAC7B,OAAO,EAAE,OAAO,CAAC;IACjB,qBAAqB;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,8BAA8B;IAC9B,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC"}
|
|
@@ -25,6 +25,10 @@ export type TokenDetectionResult = {
|
|
|
25
25
|
* Token detection options.
|
|
26
26
|
*/
|
|
27
27
|
export type TokenDetectionOptions = {
|
|
28
|
+
/** Whether token detection is enabled */
|
|
29
|
+
tokenDetectionEnabled?: boolean;
|
|
30
|
+
/** Whether external services (e.g. token list API) are allowed; detection stops when false */
|
|
31
|
+
useExternalService?: boolean;
|
|
28
32
|
/** Maximum number of tokens to check per batch */
|
|
29
33
|
batchSize?: number;
|
|
30
34
|
/** Timeout for detection in milliseconds */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"services.d.mts","sourceRoot":"","sources":["../../../../src/data-sources/evm-rpc-services/types/services.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,qBAAiB;AACpD,OAAO,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,mBAAe;AAE1D;;GAEG;AACH,MAAM,MAAM,oB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O,EAAE,OAAO,CAAC;IACjB,qBAAqB;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,8BAA8B;IAC9B,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC"}
|
|
1
|
+
{"version":3,"file":"services.d.mts","sourceRoot":"","sources":["../../../../src/data-sources/evm-rpc-services/types/services.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,qBAAiB;AACpD,OAAO,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,mBAAe;AAE1D;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG;IACjC,eAAe;IACf,OAAO,EAAE,OAAO,CAAC;IACjB,iBAAiB;IACjB,SAAS,EAAE,SAAS,CAAC;IACrB,yCAAyC;IACzC,cAAc,EAAE,OAAO,CAAC;IACxB,mDAAmD;IACnD,cAAc,EAAE,KAAK,EAAE,CAAC;IACxB,yCAAyC;IACzC,gBAAgB,EAAE,YAAY,EAAE,CAAC;IACjC,oDAAoD;IACpD,oBAAoB,EAAE,OAAO,EAAE,CAAC;IAChC,uCAAuC;IACvC,eAAe,EAAE,OAAO,EAAE,CAAC;IAC3B,6BAA6B;IAC7B,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG;IAClC,yCAAyC;IACzC,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,8FAA8F;IAC9F,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,kDAAkD;IAClD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,4CAA4C;IAC5C,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B,eAAe;IACf,OAAO,EAAE,OAAO,CAAC;IACjB,iBAAiB;IACjB,SAAS,EAAE,SAAS,CAAC;IACrB,sBAAsB;IACtB,cAAc,EAAE,OAAO,CAAC;IACxB,uBAAuB;IACvB,QAAQ,EAAE,YAAY,EAAE,CAAC;IACzB,2CAA2C;IAC3C,eAAe,EAAE,OAAO,EAAE,CAAC;IAC3B,8CAA8C;IAC9C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,yBAAyB;IACzB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG;IAChC,kDAAkD;IAClD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,wCAAwC;IACxC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,mCAAmC;IACnC,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B,6BAA6B;IAC7B,OAAO,EAAE,OAAO,CAAC;IACjB,qBAAqB;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,8BAA8B;IAC9B,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"services.mjs","sourceRoot":"","sources":["../../../../src/data-sources/evm-rpc-services/types/services.ts"],"names":[],"mappings":"","sourcesContent":["import type { Asset, AssetBalance } from './assets';\nimport type { AccountId, Address, ChainId } from './core';\n\n/**\n * Token detection result.\n */\nexport type TokenDetectionResult = {\n /** Chain ID */\n chainId: ChainId;\n /** Account ID */\n accountId: AccountId;\n /** Account address used for detection */\n accountAddress: Address;\n /** Newly detected tokens with non-zero balances */\n detectedAssets: Asset[];\n /** Balances for newly detected tokens */\n detectedBalances: AssetBalance[];\n /** Tokens that were checked but had zero balance */\n zeroBalanceAddresses: Address[];\n /** Tokens that failed to be checked */\n failedAddresses: Address[];\n /** Timestamp of detection */\n timestamp: number;\n};\n\n/**\n * Token detection options.\n */\nexport type TokenDetectionOptions = {\n /** Maximum number of tokens to check per batch */\n batchSize?: number;\n /** Timeout for detection in milliseconds */\n timeout?: number;\n};\n\n/**\n * Balance fetch result.\n */\nexport type BalanceFetchResult = {\n /** Chain ID */\n chainId: ChainId;\n /** Account ID */\n accountId: AccountId;\n /** Account address */\n accountAddress: Address;\n /** Fetched balances */\n balances: AssetBalance[];\n /** Token addresses that failed to fetch */\n failedAddresses: Address[];\n /** Block number when balances were fetched */\n blockNumber?: number;\n /** Timestamp of fetch */\n timestamp: number;\n};\n\n/**\n * Balance fetch options.\n */\nexport type BalanceFetchOptions = {\n /** Maximum number of tokens to fetch per batch */\n batchSize?: number;\n /** Timeout for fetch in milliseconds */\n timeout?: number;\n /** Include native token balance */\n includeNative?: boolean;\n};\n\n/**\n * Token info for balance fetching.\n */\nexport type TokenFetchInfo = {\n /** Token contract address */\n address: Address;\n /** Token decimals */\n decimals: number;\n /** Token symbol (optional) */\n symbol?: string;\n};\n"]}
|
|
1
|
+
{"version":3,"file":"services.mjs","sourceRoot":"","sources":["../../../../src/data-sources/evm-rpc-services/types/services.ts"],"names":[],"mappings":"","sourcesContent":["import type { Asset, AssetBalance } from './assets';\nimport type { AccountId, Address, ChainId } from './core';\n\n/**\n * Token detection result.\n */\nexport type TokenDetectionResult = {\n /** Chain ID */\n chainId: ChainId;\n /** Account ID */\n accountId: AccountId;\n /** Account address used for detection */\n accountAddress: Address;\n /** Newly detected tokens with non-zero balances */\n detectedAssets: Asset[];\n /** Balances for newly detected tokens */\n detectedBalances: AssetBalance[];\n /** Tokens that were checked but had zero balance */\n zeroBalanceAddresses: Address[];\n /** Tokens that failed to be checked */\n failedAddresses: Address[];\n /** Timestamp of detection */\n timestamp: number;\n};\n\n/**\n * Token detection options.\n */\nexport type TokenDetectionOptions = {\n /** Whether token detection is enabled */\n tokenDetectionEnabled?: boolean;\n /** Whether external services (e.g. token list API) are allowed; detection stops when false */\n useExternalService?: boolean;\n /** Maximum number of tokens to check per batch */\n batchSize?: number;\n /** Timeout for detection in milliseconds */\n timeout?: number;\n};\n\n/**\n * Balance fetch result.\n */\nexport type BalanceFetchResult = {\n /** Chain ID */\n chainId: ChainId;\n /** Account ID */\n accountId: AccountId;\n /** Account address */\n accountAddress: Address;\n /** Fetched balances */\n balances: AssetBalance[];\n /** Token addresses that failed to fetch */\n failedAddresses: Address[];\n /** Block number when balances were fetched */\n blockNumber?: number;\n /** Timestamp of fetch */\n timestamp: number;\n};\n\n/**\n * Balance fetch options.\n */\nexport type BalanceFetchOptions = {\n /** Maximum number of tokens to fetch per batch */\n batchSize?: number;\n /** Timeout for fetch in milliseconds */\n timeout?: number;\n /** Include native token balance */\n includeNative?: boolean;\n};\n\n/**\n * Token info for balance fetching.\n */\nexport type TokenFetchInfo = {\n /** Token contract address */\n address: Address;\n /** Token decimals */\n decimals: number;\n /** Token symbol (optional) */\n symbol?: string;\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"state.cjs","sourceRoot":"","sources":["../../../../src/data-sources/evm-rpc-services/types/state.ts"],"names":[],"mappings":"","sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"state.cjs","sourceRoot":"","sources":["../../../../src/data-sources/evm-rpc-services/types/state.ts"],"names":[],"mappings":"","sourcesContent":["import type { ChainId } from './core';\n\n/**\n * Single token entry from token list.\n */\nexport type TokenListEntry = {\n /** Contract address */\n address: string;\n /** Token symbol */\n symbol: string;\n /** Token name */\n name: string;\n /** Token decimals */\n decimals: number;\n /** Logo URL */\n iconUrl?: string;\n /** Aggregator sources */\n aggregators?: string[];\n /** Occurrence count in lists */\n occurrences?: number;\n};\n\n/**\n * Cache entry for a chain's token list.\n */\nexport type TokenChainsCacheEntry = {\n /** Timestamp when the cache was last updated */\n timestamp: number;\n /** Token list data: address -> TokenListEntry */\n data: Record<string, TokenListEntry>;\n};\n\n/**\n * Token list state shape (from TokenListController).\n */\nexport type TokenListState = {\n /** Map of chain ID to token list cache entry */\n tokensChainsCache: Record<ChainId, TokenChainsCacheEntry>;\n};\n\n/**\n * Single asset balance entry.\n */\nexport type AssetBalanceEntry = {\n /** Human-readable balance amount */\n amount: string;\n};\n\n/**\n * Assets balance state shape (from AssetsController).\n * Maps accountId -> assetId (CAIP-19) -> balance entry.\n */\nexport type AssetsBalanceState = {\n /** Balance data per account: accountId -> assetId -> balance */\n assetsBalance: Record<string, Record<string, AssetBalanceEntry>>;\n};\n"]}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ChainId } from "./core.cjs";
|
|
2
2
|
/**
|
|
3
3
|
* Single token entry from token list.
|
|
4
4
|
*/
|
|
5
5
|
export type TokenListEntry = {
|
|
6
6
|
/** Contract address */
|
|
7
|
-
address:
|
|
7
|
+
address: string;
|
|
8
8
|
/** Token symbol */
|
|
9
9
|
symbol: string;
|
|
10
10
|
/** Token name */
|
|
@@ -25,7 +25,7 @@ export type TokenChainsCacheEntry = {
|
|
|
25
25
|
/** Timestamp when the cache was last updated */
|
|
26
26
|
timestamp: number;
|
|
27
27
|
/** Token list data: address -> TokenListEntry */
|
|
28
|
-
data: Record<
|
|
28
|
+
data: Record<string, TokenListEntry>;
|
|
29
29
|
};
|
|
30
30
|
/**
|
|
31
31
|
* Token list state shape (from TokenListController).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"state.d.cts","sourceRoot":"","sources":["../../../../src/data-sources/evm-rpc-services/types/state.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"state.d.cts","sourceRoot":"","sources":["../../../../src/data-sources/evm-rpc-services/types/state.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,mBAAe;AAEtC;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B,uBAAuB;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,mBAAmB;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,iBAAiB;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,qBAAqB;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,eAAe;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,yBAAyB;IACzB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,gCAAgC;IAChC,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG;IAClC,gDAAgD;IAChD,SAAS,EAAE,MAAM,CAAC;IAClB,iDAAiD;IACjD,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;CACtC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B,gDAAgD;IAChD,iBAAiB,EAAE,MAAM,CAAC,OAAO,EAAE,qBAAqB,CAAC,CAAC;CAC3D,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC9B,oCAAoC;IACpC,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B,gEAAgE;IAChE,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC,CAAC;CAClE,CAAC"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ChainId } from "./core.mjs";
|
|
2
2
|
/**
|
|
3
3
|
* Single token entry from token list.
|
|
4
4
|
*/
|
|
5
5
|
export type TokenListEntry = {
|
|
6
6
|
/** Contract address */
|
|
7
|
-
address:
|
|
7
|
+
address: string;
|
|
8
8
|
/** Token symbol */
|
|
9
9
|
symbol: string;
|
|
10
10
|
/** Token name */
|
|
@@ -25,7 +25,7 @@ export type TokenChainsCacheEntry = {
|
|
|
25
25
|
/** Timestamp when the cache was last updated */
|
|
26
26
|
timestamp: number;
|
|
27
27
|
/** Token list data: address -> TokenListEntry */
|
|
28
|
-
data: Record<
|
|
28
|
+
data: Record<string, TokenListEntry>;
|
|
29
29
|
};
|
|
30
30
|
/**
|
|
31
31
|
* Token list state shape (from TokenListController).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"state.d.mts","sourceRoot":"","sources":["../../../../src/data-sources/evm-rpc-services/types/state.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"state.d.mts","sourceRoot":"","sources":["../../../../src/data-sources/evm-rpc-services/types/state.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,mBAAe;AAEtC;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B,uBAAuB;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,mBAAmB;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,iBAAiB;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,qBAAqB;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,eAAe;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,yBAAyB;IACzB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,gCAAgC;IAChC,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG;IAClC,gDAAgD;IAChD,SAAS,EAAE,MAAM,CAAC;IAClB,iDAAiD;IACjD,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;CACtC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B,gDAAgD;IAChD,iBAAiB,EAAE,MAAM,CAAC,OAAO,EAAE,qBAAqB,CAAC,CAAC;CAC3D,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC9B,oCAAoC;IACpC,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B,gEAAgE;IAChE,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC,CAAC;CAClE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"state.mjs","sourceRoot":"","sources":["../../../../src/data-sources/evm-rpc-services/types/state.ts"],"names":[],"mappings":"","sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"state.mjs","sourceRoot":"","sources":["../../../../src/data-sources/evm-rpc-services/types/state.ts"],"names":[],"mappings":"","sourcesContent":["import type { ChainId } from './core';\n\n/**\n * Single token entry from token list.\n */\nexport type TokenListEntry = {\n /** Contract address */\n address: string;\n /** Token symbol */\n symbol: string;\n /** Token name */\n name: string;\n /** Token decimals */\n decimals: number;\n /** Logo URL */\n iconUrl?: string;\n /** Aggregator sources */\n aggregators?: string[];\n /** Occurrence count in lists */\n occurrences?: number;\n};\n\n/**\n * Cache entry for a chain's token list.\n */\nexport type TokenChainsCacheEntry = {\n /** Timestamp when the cache was last updated */\n timestamp: number;\n /** Token list data: address -> TokenListEntry */\n data: Record<string, TokenListEntry>;\n};\n\n/**\n * Token list state shape (from TokenListController).\n */\nexport type TokenListState = {\n /** Map of chain ID to token list cache entry */\n tokensChainsCache: Record<ChainId, TokenChainsCacheEntry>;\n};\n\n/**\n * Single asset balance entry.\n */\nexport type AssetBalanceEntry = {\n /** Human-readable balance amount */\n amount: string;\n};\n\n/**\n * Assets balance state shape (from AssetsController).\n * Maps accountId -> assetId (CAIP-19) -> balance entry.\n */\nexport type AssetsBalanceState = {\n /** Balance data per account: accountId -> assetId -> balance */\n assetsBalance: Record<string, Record<string, AssetBalanceEntry>>;\n};\n"]}
|
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.reduceInBatchesSerially = exports.divideIntoBatches = void 0;
|
|
3
|
+
exports.STAKING_CONTRACT_ADDRESS_BY_CHAINID = exports.isStakingContractAssetId = exports.getSupportedStakingChainIds = exports.getStakingContractAddress = exports.weiToHumanReadable = exports.chainIdToHex = exports.reduceInBatchesSerially = exports.divideIntoBatches = void 0;
|
|
4
4
|
var batch_1 = require("./batch.cjs");
|
|
5
5
|
Object.defineProperty(exports, "divideIntoBatches", { enumerable: true, get: function () { return batch_1.divideIntoBatches; } });
|
|
6
6
|
Object.defineProperty(exports, "reduceInBatchesSerially", { enumerable: true, get: function () { return batch_1.reduceInBatchesSerially; } });
|
|
7
|
+
var parsing_1 = require("./parsing.cjs");
|
|
8
|
+
Object.defineProperty(exports, "chainIdToHex", { enumerable: true, get: function () { return parsing_1.chainIdToHex; } });
|
|
9
|
+
Object.defineProperty(exports, "weiToHumanReadable", { enumerable: true, get: function () { return parsing_1.weiToHumanReadable; } });
|
|
10
|
+
var staking_contracts_1 = require("./staking-contracts.cjs");
|
|
11
|
+
Object.defineProperty(exports, "getStakingContractAddress", { enumerable: true, get: function () { return staking_contracts_1.getStakingContractAddress; } });
|
|
12
|
+
Object.defineProperty(exports, "getSupportedStakingChainIds", { enumerable: true, get: function () { return staking_contracts_1.getSupportedStakingChainIds; } });
|
|
13
|
+
Object.defineProperty(exports, "isStakingContractAssetId", { enumerable: true, get: function () { return staking_contracts_1.isStakingContractAssetId; } });
|
|
14
|
+
Object.defineProperty(exports, "STAKING_CONTRACT_ADDRESS_BY_CHAINID", { enumerable: true, get: function () { return staking_contracts_1.STAKING_CONTRACT_ADDRESS_BY_CHAINID; } });
|
|
7
15
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../../../src/data-sources/evm-rpc-services/utils/index.ts"],"names":[],"mappings":";;;AAAA,qCAAqE;AAA5D,0GAAA,iBAAiB,OAAA;AAAE,gHAAA,uBAAuB,OAAA","sourcesContent":["export { divideIntoBatches, reduceInBatchesSerially } from './batch';\n"]}
|
|
1
|
+
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../../../src/data-sources/evm-rpc-services/utils/index.ts"],"names":[],"mappings":";;;AAAA,qCAAqE;AAA5D,0GAAA,iBAAiB,OAAA;AAAE,gHAAA,uBAAuB,OAAA;AACnD,yCAA6D;AAApD,uGAAA,YAAY,OAAA;AAAE,6GAAA,kBAAkB,OAAA;AACzC,6DAK6B;AAJ3B,8HAAA,yBAAyB,OAAA;AACzB,gIAAA,2BAA2B,OAAA;AAC3B,6HAAA,wBAAwB,OAAA;AACxB,wIAAA,mCAAmC,OAAA","sourcesContent":["export { divideIntoBatches, reduceInBatchesSerially } from './batch';\nexport { chainIdToHex, weiToHumanReadable } from './parsing';\nexport {\n getStakingContractAddress,\n getSupportedStakingChainIds,\n isStakingContractAssetId,\n STAKING_CONTRACT_ADDRESS_BY_CHAINID,\n} from './staking-contracts';\n"]}
|
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
export { divideIntoBatches, reduceInBatchesSerially } from "./batch.cjs";
|
|
2
|
+
export { chainIdToHex, weiToHumanReadable } from "./parsing.cjs";
|
|
3
|
+
export { getStakingContractAddress, getSupportedStakingChainIds, isStakingContractAssetId, STAKING_CONTRACT_ADDRESS_BY_CHAINID, } from "./staking-contracts.cjs";
|
|
2
4
|
//# sourceMappingURL=index.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../../../src/data-sources/evm-rpc-services/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,oBAAgB"}
|
|
1
|
+
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../../../src/data-sources/evm-rpc-services/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,oBAAgB;AACrE,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,sBAAkB;AAC7D,OAAO,EACL,yBAAyB,EACzB,2BAA2B,EAC3B,wBAAwB,EACxB,mCAAmC,GACpC,gCAA4B"}
|
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
export { divideIntoBatches, reduceInBatchesSerially } from "./batch.mjs";
|
|
2
|
+
export { chainIdToHex, weiToHumanReadable } from "./parsing.mjs";
|
|
3
|
+
export { getStakingContractAddress, getSupportedStakingChainIds, isStakingContractAssetId, STAKING_CONTRACT_ADDRESS_BY_CHAINID, } from "./staking-contracts.mjs";
|
|
2
4
|
//# sourceMappingURL=index.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../../../src/data-sources/evm-rpc-services/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,oBAAgB"}
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../../../src/data-sources/evm-rpc-services/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,oBAAgB;AACrE,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,sBAAkB;AAC7D,OAAO,EACL,yBAAyB,EACzB,2BAA2B,EAC3B,wBAAwB,EACxB,mCAAmC,GACpC,gCAA4B"}
|
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
export { divideIntoBatches, reduceInBatchesSerially } from "./batch.mjs";
|
|
2
|
+
export { chainIdToHex, weiToHumanReadable } from "./parsing.mjs";
|
|
3
|
+
export { getStakingContractAddress, getSupportedStakingChainIds, isStakingContractAssetId, STAKING_CONTRACT_ADDRESS_BY_CHAINID } from "./staking-contracts.mjs";
|
|
2
4
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../../../src/data-sources/evm-rpc-services/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,oBAAgB","sourcesContent":["export { divideIntoBatches, reduceInBatchesSerially } from './batch';\n"]}
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../../../src/data-sources/evm-rpc-services/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,oBAAgB;AACrE,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,sBAAkB;AAC7D,OAAO,EACL,yBAAyB,EACzB,2BAA2B,EAC3B,wBAAwB,EACxB,mCAAmC,EACpC,gCAA4B","sourcesContent":["export { divideIntoBatches, reduceInBatchesSerially } from './batch';\nexport { chainIdToHex, weiToHumanReadable } from './parsing';\nexport {\n getStakingContractAddress,\n getSupportedStakingChainIds,\n isStakingContractAssetId,\n STAKING_CONTRACT_ADDRESS_BY_CHAINID,\n} from './staking-contracts';\n"]}
|
|
@@ -0,0 +1,47 @@
|
|
|
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.chainIdToHex = exports.weiToHumanReadable = void 0;
|
|
7
|
+
const utils_1 = require("@metamask/utils");
|
|
8
|
+
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
9
|
+
/**
|
|
10
|
+
* Convert wei to human-readable amount with decimals, trim trailing zeros.
|
|
11
|
+
* Uses BigNumber for precision.
|
|
12
|
+
*
|
|
13
|
+
* Note: `.shiftedBy(-decimals).toFixed()` (no args) rounds to DECIMAL_PLACES (0
|
|
14
|
+
* by default in bignumber.js), producing integers (e.g. 1.5 ETH → "2").
|
|
15
|
+
* We use `.toFixed(decimals)` to preserve fractional precision, then trim
|
|
16
|
+
* trailing zeros so the result is e.g. "1.5" instead of "1.500000000000000000".
|
|
17
|
+
*
|
|
18
|
+
* @param wei - Balance in wei as bigint or decimal string.
|
|
19
|
+
* @param decimals - Token decimals (e.g. 18).
|
|
20
|
+
* @returns Human-readable amount string (e.g. "1.5").
|
|
21
|
+
*/
|
|
22
|
+
function weiToHumanReadable(wei, decimals) {
|
|
23
|
+
const weiStr = typeof wei === 'bigint' ? wei.toString() : wei;
|
|
24
|
+
const fixed = new bignumber_js_1.default(weiStr).shiftedBy(-decimals).toFixed(decimals);
|
|
25
|
+
const trimmed = fixed.replace(/\.?0+$/u, '');
|
|
26
|
+
return trimmed === '' ? '0' : trimmed;
|
|
27
|
+
}
|
|
28
|
+
exports.weiToHumanReadable = weiToHumanReadable;
|
|
29
|
+
/**
|
|
30
|
+
* Normalize chain ID to hex for contract lookup (e.g. eip155:1 -> 0x1).
|
|
31
|
+
* Uses @metamask/utils for CAIP parsing.
|
|
32
|
+
*
|
|
33
|
+
* @param chainId - CAIP-2 or hex chain ID.
|
|
34
|
+
* @returns Hex chain ID for contract map lookup.
|
|
35
|
+
*/
|
|
36
|
+
function chainIdToHex(chainId) {
|
|
37
|
+
if ((0, utils_1.isStrictHexString)(chainId)) {
|
|
38
|
+
return chainId;
|
|
39
|
+
}
|
|
40
|
+
if ((0, utils_1.isCaipChainId)(chainId)) {
|
|
41
|
+
const { reference } = (0, utils_1.parseCaipChainId)(chainId);
|
|
42
|
+
return (0, utils_1.numberToHex)(parseInt(reference, 10));
|
|
43
|
+
}
|
|
44
|
+
return chainId;
|
|
45
|
+
}
|
|
46
|
+
exports.chainIdToHex = chainIdToHex;
|
|
47
|
+
//# sourceMappingURL=parsing.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parsing.cjs","sourceRoot":"","sources":["../../../../src/data-sources/evm-rpc-services/utils/parsing.ts"],"names":[],"mappings":";;;;;;AAAA,2CAKyB;AAEzB,gEAAuC;AAIvC;;;;;;;;;;;;GAYG;AACH,SAAgB,kBAAkB,CAChC,GAAoB,EACpB,QAAgB;IAEhB,MAAM,MAAM,GAAG,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC;IAC9D,MAAM,KAAK,GAAG,IAAI,sBAAW,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC7E,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;IAC7C,OAAO,OAAO,KAAK,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC;AACxC,CAAC;AARD,gDAQC;AAED;;;;;;GAMG;AACH,SAAgB,YAAY,CAAC,OAA8B;IACzD,IAAI,IAAA,yBAAiB,EAAC,OAAO,CAAC,EAAE,CAAC;QAC/B,OAAO,OAAO,CAAC;IACjB,CAAC;IACD,IAAI,IAAA,qBAAa,EAAC,OAAO,CAAC,EAAE,CAAC;QAC3B,MAAM,EAAE,SAAS,EAAE,GAAG,IAAA,wBAAgB,EAAC,OAAO,CAAC,CAAC;QAChD,OAAO,IAAA,mBAAW,EAAC,QAAQ,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,CAAC;IAC9C,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AATD,oCASC","sourcesContent":["import {\n isCaipChainId,\n isStrictHexString,\n numberToHex,\n parseCaipChainId,\n} from '@metamask/utils';\nimport type { CaipChainId, Hex } from '@metamask/utils';\nimport BigNumberJS from 'bignumber.js';\n\nimport type { ChainId } from '../types';\n\n/**\n * Convert wei to human-readable amount with decimals, trim trailing zeros.\n * Uses BigNumber for precision.\n *\n * Note: `.shiftedBy(-decimals).toFixed()` (no args) rounds to DECIMAL_PLACES (0\n * by default in bignumber.js), producing integers (e.g. 1.5 ETH → \"2\").\n * We use `.toFixed(decimals)` to preserve fractional precision, then trim\n * trailing zeros so the result is e.g. \"1.5\" instead of \"1.500000000000000000\".\n *\n * @param wei - Balance in wei as bigint or decimal string.\n * @param decimals - Token decimals (e.g. 18).\n * @returns Human-readable amount string (e.g. \"1.5\").\n */\nexport function weiToHumanReadable(\n wei: string | bigint,\n decimals: number,\n): string {\n const weiStr = typeof wei === 'bigint' ? wei.toString() : wei;\n const fixed = new BigNumberJS(weiStr).shiftedBy(-decimals).toFixed(decimals);\n const trimmed = fixed.replace(/\\.?0+$/u, '');\n return trimmed === '' ? '0' : trimmed;\n}\n\n/**\n * Normalize chain ID to hex for contract lookup (e.g. eip155:1 -> 0x1).\n * Uses @metamask/utils for CAIP parsing.\n *\n * @param chainId - CAIP-2 or hex chain ID.\n * @returns Hex chain ID for contract map lookup.\n */\nexport function chainIdToHex(chainId: ChainId | CaipChainId): Hex {\n if (isStrictHexString(chainId)) {\n return chainId;\n }\n if (isCaipChainId(chainId)) {\n const { reference } = parseCaipChainId(chainId);\n return numberToHex(parseInt(reference, 10));\n }\n return chainId;\n}\n"]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { CaipChainId, Hex } from "@metamask/utils";
|
|
2
|
+
import type { ChainId } from "../types/index.cjs";
|
|
3
|
+
/**
|
|
4
|
+
* Convert wei to human-readable amount with decimals, trim trailing zeros.
|
|
5
|
+
* Uses BigNumber for precision.
|
|
6
|
+
*
|
|
7
|
+
* Note: `.shiftedBy(-decimals).toFixed()` (no args) rounds to DECIMAL_PLACES (0
|
|
8
|
+
* by default in bignumber.js), producing integers (e.g. 1.5 ETH → "2").
|
|
9
|
+
* We use `.toFixed(decimals)` to preserve fractional precision, then trim
|
|
10
|
+
* trailing zeros so the result is e.g. "1.5" instead of "1.500000000000000000".
|
|
11
|
+
*
|
|
12
|
+
* @param wei - Balance in wei as bigint or decimal string.
|
|
13
|
+
* @param decimals - Token decimals (e.g. 18).
|
|
14
|
+
* @returns Human-readable amount string (e.g. "1.5").
|
|
15
|
+
*/
|
|
16
|
+
export declare function weiToHumanReadable(wei: string | bigint, decimals: number): string;
|
|
17
|
+
/**
|
|
18
|
+
* Normalize chain ID to hex for contract lookup (e.g. eip155:1 -> 0x1).
|
|
19
|
+
* Uses @metamask/utils for CAIP parsing.
|
|
20
|
+
*
|
|
21
|
+
* @param chainId - CAIP-2 or hex chain ID.
|
|
22
|
+
* @returns Hex chain ID for contract map lookup.
|
|
23
|
+
*/
|
|
24
|
+
export declare function chainIdToHex(chainId: ChainId | CaipChainId): Hex;
|
|
25
|
+
//# sourceMappingURL=parsing.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parsing.d.cts","sourceRoot":"","sources":["../../../../src/data-sources/evm-rpc-services/utils/parsing.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,WAAW,EAAE,GAAG,EAAE,wBAAwB;AAGxD,OAAO,KAAK,EAAE,OAAO,EAAE,2BAAiB;AAExC;;;;;;;;;;;;GAYG;AACH,wBAAgB,kBAAkB,CAChC,GAAG,EAAE,MAAM,GAAG,MAAM,EACpB,QAAQ,EAAE,MAAM,GACf,MAAM,CAKR;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,OAAO,GAAG,WAAW,GAAG,GAAG,CAShE"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { CaipChainId, Hex } from "@metamask/utils";
|
|
2
|
+
import type { ChainId } from "../types/index.mjs";
|
|
3
|
+
/**
|
|
4
|
+
* Convert wei to human-readable amount with decimals, trim trailing zeros.
|
|
5
|
+
* Uses BigNumber for precision.
|
|
6
|
+
*
|
|
7
|
+
* Note: `.shiftedBy(-decimals).toFixed()` (no args) rounds to DECIMAL_PLACES (0
|
|
8
|
+
* by default in bignumber.js), producing integers (e.g. 1.5 ETH → "2").
|
|
9
|
+
* We use `.toFixed(decimals)` to preserve fractional precision, then trim
|
|
10
|
+
* trailing zeros so the result is e.g. "1.5" instead of "1.500000000000000000".
|
|
11
|
+
*
|
|
12
|
+
* @param wei - Balance in wei as bigint or decimal string.
|
|
13
|
+
* @param decimals - Token decimals (e.g. 18).
|
|
14
|
+
* @returns Human-readable amount string (e.g. "1.5").
|
|
15
|
+
*/
|
|
16
|
+
export declare function weiToHumanReadable(wei: string | bigint, decimals: number): string;
|
|
17
|
+
/**
|
|
18
|
+
* Normalize chain ID to hex for contract lookup (e.g. eip155:1 -> 0x1).
|
|
19
|
+
* Uses @metamask/utils for CAIP parsing.
|
|
20
|
+
*
|
|
21
|
+
* @param chainId - CAIP-2 or hex chain ID.
|
|
22
|
+
* @returns Hex chain ID for contract map lookup.
|
|
23
|
+
*/
|
|
24
|
+
export declare function chainIdToHex(chainId: ChainId | CaipChainId): Hex;
|
|
25
|
+
//# sourceMappingURL=parsing.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parsing.d.mts","sourceRoot":"","sources":["../../../../src/data-sources/evm-rpc-services/utils/parsing.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,WAAW,EAAE,GAAG,EAAE,wBAAwB;AAGxD,OAAO,KAAK,EAAE,OAAO,EAAE,2BAAiB;AAExC;;;;;;;;;;;;GAYG;AACH,wBAAgB,kBAAkB,CAChC,GAAG,EAAE,MAAM,GAAG,MAAM,EACpB,QAAQ,EAAE,MAAM,GACf,MAAM,CAKR;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,OAAO,GAAG,WAAW,GAAG,GAAG,CAShE"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { isCaipChainId, isStrictHexString, numberToHex, parseCaipChainId } from "@metamask/utils";
|
|
2
|
+
import BigNumberJS from "bignumber.js";
|
|
3
|
+
/**
|
|
4
|
+
* Convert wei to human-readable amount with decimals, trim trailing zeros.
|
|
5
|
+
* Uses BigNumber for precision.
|
|
6
|
+
*
|
|
7
|
+
* Note: `.shiftedBy(-decimals).toFixed()` (no args) rounds to DECIMAL_PLACES (0
|
|
8
|
+
* by default in bignumber.js), producing integers (e.g. 1.5 ETH → "2").
|
|
9
|
+
* We use `.toFixed(decimals)` to preserve fractional precision, then trim
|
|
10
|
+
* trailing zeros so the result is e.g. "1.5" instead of "1.500000000000000000".
|
|
11
|
+
*
|
|
12
|
+
* @param wei - Balance in wei as bigint or decimal string.
|
|
13
|
+
* @param decimals - Token decimals (e.g. 18).
|
|
14
|
+
* @returns Human-readable amount string (e.g. "1.5").
|
|
15
|
+
*/
|
|
16
|
+
export function weiToHumanReadable(wei, decimals) {
|
|
17
|
+
const weiStr = typeof wei === 'bigint' ? wei.toString() : wei;
|
|
18
|
+
const fixed = new BigNumberJS(weiStr).shiftedBy(-decimals).toFixed(decimals);
|
|
19
|
+
const trimmed = fixed.replace(/\.?0+$/u, '');
|
|
20
|
+
return trimmed === '' ? '0' : trimmed;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Normalize chain ID to hex for contract lookup (e.g. eip155:1 -> 0x1).
|
|
24
|
+
* Uses @metamask/utils for CAIP parsing.
|
|
25
|
+
*
|
|
26
|
+
* @param chainId - CAIP-2 or hex chain ID.
|
|
27
|
+
* @returns Hex chain ID for contract map lookup.
|
|
28
|
+
*/
|
|
29
|
+
export function chainIdToHex(chainId) {
|
|
30
|
+
if (isStrictHexString(chainId)) {
|
|
31
|
+
return chainId;
|
|
32
|
+
}
|
|
33
|
+
if (isCaipChainId(chainId)) {
|
|
34
|
+
const { reference } = parseCaipChainId(chainId);
|
|
35
|
+
return numberToHex(parseInt(reference, 10));
|
|
36
|
+
}
|
|
37
|
+
return chainId;
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=parsing.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parsing.mjs","sourceRoot":"","sources":["../../../../src/data-sources/evm-rpc-services/utils/parsing.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,iBAAiB,EACjB,WAAW,EACX,gBAAgB,EACjB,wBAAwB;AAEzB,OAAO,WAAW,qBAAqB;AAIvC;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,kBAAkB,CAChC,GAAoB,EACpB,QAAgB;IAEhB,MAAM,MAAM,GAAG,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC;IAC9D,MAAM,KAAK,GAAG,IAAI,WAAW,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC7E,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;IAC7C,OAAO,OAAO,KAAK,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC;AACxC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAAC,OAA8B;IACzD,IAAI,iBAAiB,CAAC,OAAO,CAAC,EAAE,CAAC;QAC/B,OAAO,OAAO,CAAC;IACjB,CAAC;IACD,IAAI,aAAa,CAAC,OAAO,CAAC,EAAE,CAAC;QAC3B,MAAM,EAAE,SAAS,EAAE,GAAG,gBAAgB,CAAC,OAAO,CAAC,CAAC;QAChD,OAAO,WAAW,CAAC,QAAQ,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,CAAC;IAC9C,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import {\n isCaipChainId,\n isStrictHexString,\n numberToHex,\n parseCaipChainId,\n} from '@metamask/utils';\nimport type { CaipChainId, Hex } from '@metamask/utils';\nimport BigNumberJS from 'bignumber.js';\n\nimport type { ChainId } from '../types';\n\n/**\n * Convert wei to human-readable amount with decimals, trim trailing zeros.\n * Uses BigNumber for precision.\n *\n * Note: `.shiftedBy(-decimals).toFixed()` (no args) rounds to DECIMAL_PLACES (0\n * by default in bignumber.js), producing integers (e.g. 1.5 ETH → \"2\").\n * We use `.toFixed(decimals)` to preserve fractional precision, then trim\n * trailing zeros so the result is e.g. \"1.5\" instead of \"1.500000000000000000\".\n *\n * @param wei - Balance in wei as bigint or decimal string.\n * @param decimals - Token decimals (e.g. 18).\n * @returns Human-readable amount string (e.g. \"1.5\").\n */\nexport function weiToHumanReadable(\n wei: string | bigint,\n decimals: number,\n): string {\n const weiStr = typeof wei === 'bigint' ? wei.toString() : wei;\n const fixed = new BigNumberJS(weiStr).shiftedBy(-decimals).toFixed(decimals);\n const trimmed = fixed.replace(/\\.?0+$/u, '');\n return trimmed === '' ? '0' : trimmed;\n}\n\n/**\n * Normalize chain ID to hex for contract lookup (e.g. eip155:1 -> 0x1).\n * Uses @metamask/utils for CAIP parsing.\n *\n * @param chainId - CAIP-2 or hex chain ID.\n * @returns Hex chain ID for contract map lookup.\n */\nexport function chainIdToHex(chainId: ChainId | CaipChainId): Hex {\n if (isStrictHexString(chainId)) {\n return chainId;\n }\n if (isCaipChainId(chainId)) {\n const { reference } = parseCaipChainId(chainId);\n return numberToHex(parseInt(reference, 10));\n }\n return chainId;\n}\n"]}
|