@metamask/assets-controller 0.1.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 +37 -0
- package/LICENSE +20 -0
- package/README.md +15 -0
- package/dist/AssetsController.cjs +1057 -0
- package/dist/AssetsController.cjs.map +1 -0
- package/dist/AssetsController.d.cts +260 -0
- package/dist/AssetsController.d.cts.map +1 -0
- package/dist/AssetsController.d.mts +260 -0
- package/dist/AssetsController.d.mts.map +1 -0
- package/dist/AssetsController.mjs +1050 -0
- package/dist/AssetsController.mjs.map +1 -0
- package/dist/data-sources/AbstractDataSource.cjs +103 -0
- package/dist/data-sources/AbstractDataSource.cjs.map +1 -0
- package/dist/data-sources/AbstractDataSource.d.cts +92 -0
- package/dist/data-sources/AbstractDataSource.d.cts.map +1 -0
- package/dist/data-sources/AbstractDataSource.d.mts +92 -0
- package/dist/data-sources/AbstractDataSource.d.mts.map +1 -0
- package/dist/data-sources/AbstractDataSource.mjs +99 -0
- package/dist/data-sources/AbstractDataSource.mjs.map +1 -0
- package/dist/data-sources/AccountsApiDataSource.cjs +421 -0
- package/dist/data-sources/AccountsApiDataSource.cjs.map +1 -0
- package/dist/data-sources/AccountsApiDataSource.d.cts +103 -0
- package/dist/data-sources/AccountsApiDataSource.d.cts.map +1 -0
- package/dist/data-sources/AccountsApiDataSource.d.mts +103 -0
- package/dist/data-sources/AccountsApiDataSource.d.mts.map +1 -0
- package/dist/data-sources/AccountsApiDataSource.mjs +416 -0
- package/dist/data-sources/AccountsApiDataSource.mjs.map +1 -0
- package/dist/data-sources/BackendWebsocketDataSource.cjs +388 -0
- package/dist/data-sources/BackendWebsocketDataSource.cjs.map +1 -0
- package/dist/data-sources/BackendWebsocketDataSource.d.cts +95 -0
- package/dist/data-sources/BackendWebsocketDataSource.d.cts.map +1 -0
- package/dist/data-sources/BackendWebsocketDataSource.d.mts +95 -0
- package/dist/data-sources/BackendWebsocketDataSource.d.mts.map +1 -0
- package/dist/data-sources/BackendWebsocketDataSource.mjs +383 -0
- package/dist/data-sources/BackendWebsocketDataSource.mjs.map +1 -0
- package/dist/data-sources/PriceDataSource.cjs +343 -0
- package/dist/data-sources/PriceDataSource.cjs.map +1 -0
- package/dist/data-sources/PriceDataSource.d.cts +153 -0
- package/dist/data-sources/PriceDataSource.d.cts.map +1 -0
- package/dist/data-sources/PriceDataSource.d.mts +153 -0
- package/dist/data-sources/PriceDataSource.d.mts.map +1 -0
- package/dist/data-sources/PriceDataSource.mjs +339 -0
- package/dist/data-sources/PriceDataSource.mjs.map +1 -0
- package/dist/data-sources/RpcDataSource.cjs +829 -0
- package/dist/data-sources/RpcDataSource.cjs.map +1 -0
- package/dist/data-sources/RpcDataSource.d.cts +243 -0
- package/dist/data-sources/RpcDataSource.d.cts.map +1 -0
- package/dist/data-sources/RpcDataSource.d.mts +243 -0
- package/dist/data-sources/RpcDataSource.d.mts.map +1 -0
- package/dist/data-sources/RpcDataSource.mjs +820 -0
- package/dist/data-sources/RpcDataSource.mjs.map +1 -0
- package/dist/data-sources/SnapDataSource.cjs +463 -0
- package/dist/data-sources/SnapDataSource.cjs.map +1 -0
- package/dist/data-sources/SnapDataSource.d.cts +155 -0
- package/dist/data-sources/SnapDataSource.d.cts.map +1 -0
- package/dist/data-sources/SnapDataSource.d.mts +155 -0
- package/dist/data-sources/SnapDataSource.d.mts.map +1 -0
- package/dist/data-sources/SnapDataSource.mjs +456 -0
- package/dist/data-sources/SnapDataSource.mjs.map +1 -0
- package/dist/data-sources/TokenDataSource.cjs +211 -0
- package/dist/data-sources/TokenDataSource.cjs.map +1 -0
- package/dist/data-sources/TokenDataSource.d.cts +62 -0
- package/dist/data-sources/TokenDataSource.d.cts.map +1 -0
- package/dist/data-sources/TokenDataSource.d.mts +62 -0
- package/dist/data-sources/TokenDataSource.d.mts.map +1 -0
- package/dist/data-sources/TokenDataSource.mjs +207 -0
- package/dist/data-sources/TokenDataSource.mjs.map +1 -0
- package/dist/data-sources/evm-rpc-services/clients/MulticallClient.cjs +638 -0
- package/dist/data-sources/evm-rpc-services/clients/MulticallClient.cjs.map +1 -0
- package/dist/data-sources/evm-rpc-services/clients/MulticallClient.d.cts +47 -0
- package/dist/data-sources/evm-rpc-services/clients/MulticallClient.d.cts.map +1 -0
- package/dist/data-sources/evm-rpc-services/clients/MulticallClient.d.mts +47 -0
- package/dist/data-sources/evm-rpc-services/clients/MulticallClient.d.mts.map +1 -0
- package/dist/data-sources/evm-rpc-services/clients/MulticallClient.mjs +632 -0
- package/dist/data-sources/evm-rpc-services/clients/MulticallClient.mjs.map +1 -0
- package/dist/data-sources/evm-rpc-services/clients/index.cjs +8 -0
- package/dist/data-sources/evm-rpc-services/clients/index.cjs.map +1 -0
- package/dist/data-sources/evm-rpc-services/clients/index.d.cts +3 -0
- package/dist/data-sources/evm-rpc-services/clients/index.d.cts.map +1 -0
- package/dist/data-sources/evm-rpc-services/clients/index.d.mts +3 -0
- package/dist/data-sources/evm-rpc-services/clients/index.d.mts.map +1 -0
- package/dist/data-sources/evm-rpc-services/clients/index.mjs +2 -0
- package/dist/data-sources/evm-rpc-services/clients/index.mjs.map +1 -0
- package/dist/data-sources/evm-rpc-services/index.cjs +12 -0
- package/dist/data-sources/evm-rpc-services/index.cjs.map +1 -0
- package/dist/data-sources/evm-rpc-services/index.d.cts +5 -0
- package/dist/data-sources/evm-rpc-services/index.d.cts.map +1 -0
- package/dist/data-sources/evm-rpc-services/index.d.mts +5 -0
- package/dist/data-sources/evm-rpc-services/index.d.mts.map +1 -0
- package/dist/data-sources/evm-rpc-services/index.mjs +4 -0
- package/dist/data-sources/evm-rpc-services/index.mjs.map +1 -0
- package/dist/data-sources/evm-rpc-services/services/BalanceFetcher.cjs +202 -0
- package/dist/data-sources/evm-rpc-services/services/BalanceFetcher.cjs.map +1 -0
- package/dist/data-sources/evm-rpc-services/services/BalanceFetcher.d.cts +75 -0
- package/dist/data-sources/evm-rpc-services/services/BalanceFetcher.d.cts.map +1 -0
- package/dist/data-sources/evm-rpc-services/services/BalanceFetcher.d.mts +75 -0
- package/dist/data-sources/evm-rpc-services/services/BalanceFetcher.d.mts.map +1 -0
- package/dist/data-sources/evm-rpc-services/services/BalanceFetcher.mjs +198 -0
- package/dist/data-sources/evm-rpc-services/services/BalanceFetcher.mjs.map +1 -0
- package/dist/data-sources/evm-rpc-services/services/TokenDetector.cjs +214 -0
- package/dist/data-sources/evm-rpc-services/services/TokenDetector.cjs.map +1 -0
- package/dist/data-sources/evm-rpc-services/services/TokenDetector.d.cts +71 -0
- package/dist/data-sources/evm-rpc-services/services/TokenDetector.d.cts.map +1 -0
- package/dist/data-sources/evm-rpc-services/services/TokenDetector.d.mts +71 -0
- package/dist/data-sources/evm-rpc-services/services/TokenDetector.d.mts.map +1 -0
- package/dist/data-sources/evm-rpc-services/services/TokenDetector.mjs +210 -0
- package/dist/data-sources/evm-rpc-services/services/TokenDetector.mjs.map +1 -0
- package/dist/data-sources/evm-rpc-services/services/index.cjs +8 -0
- package/dist/data-sources/evm-rpc-services/services/index.cjs.map +1 -0
- package/dist/data-sources/evm-rpc-services/services/index.d.cts +3 -0
- package/dist/data-sources/evm-rpc-services/services/index.d.cts.map +1 -0
- package/dist/data-sources/evm-rpc-services/services/index.d.mts +3 -0
- package/dist/data-sources/evm-rpc-services/services/index.d.mts.map +1 -0
- package/dist/data-sources/evm-rpc-services/services/index.mjs +3 -0
- package/dist/data-sources/evm-rpc-services/services/index.mjs.map +1 -0
- package/dist/data-sources/evm-rpc-services/types/assets.cjs +3 -0
- package/dist/data-sources/evm-rpc-services/types/assets.cjs.map +1 -0
- package/dist/data-sources/evm-rpc-services/types/assets.d.cts +53 -0
- package/dist/data-sources/evm-rpc-services/types/assets.d.cts.map +1 -0
- package/dist/data-sources/evm-rpc-services/types/assets.d.mts +53 -0
- package/dist/data-sources/evm-rpc-services/types/assets.d.mts.map +1 -0
- package/dist/data-sources/evm-rpc-services/types/assets.mjs +2 -0
- package/dist/data-sources/evm-rpc-services/types/assets.mjs.map +1 -0
- package/dist/data-sources/evm-rpc-services/types/config.cjs +3 -0
- package/dist/data-sources/evm-rpc-services/types/config.cjs.map +1 -0
- package/dist/data-sources/evm-rpc-services/types/config.d.cts +18 -0
- package/dist/data-sources/evm-rpc-services/types/config.d.cts.map +1 -0
- package/dist/data-sources/evm-rpc-services/types/config.d.mts +18 -0
- package/dist/data-sources/evm-rpc-services/types/config.d.mts.map +1 -0
- package/dist/data-sources/evm-rpc-services/types/config.mjs +2 -0
- package/dist/data-sources/evm-rpc-services/types/config.mjs.map +1 -0
- package/dist/data-sources/evm-rpc-services/types/core.cjs +3 -0
- package/dist/data-sources/evm-rpc-services/types/core.cjs.map +1 -0
- package/dist/data-sources/evm-rpc-services/types/core.d.cts +19 -0
- package/dist/data-sources/evm-rpc-services/types/core.d.cts.map +1 -0
- package/dist/data-sources/evm-rpc-services/types/core.d.mts +19 -0
- package/dist/data-sources/evm-rpc-services/types/core.d.mts.map +1 -0
- package/dist/data-sources/evm-rpc-services/types/core.mjs +2 -0
- package/dist/data-sources/evm-rpc-services/types/core.mjs.map +1 -0
- package/dist/data-sources/evm-rpc-services/types/index.cjs +3 -0
- package/dist/data-sources/evm-rpc-services/types/index.cjs.map +1 -0
- package/dist/data-sources/evm-rpc-services/types/index.d.cts +7 -0
- package/dist/data-sources/evm-rpc-services/types/index.d.cts.map +1 -0
- package/dist/data-sources/evm-rpc-services/types/index.d.mts +7 -0
- package/dist/data-sources/evm-rpc-services/types/index.d.mts.map +1 -0
- package/dist/data-sources/evm-rpc-services/types/index.mjs +2 -0
- package/dist/data-sources/evm-rpc-services/types/index.mjs.map +1 -0
- package/dist/data-sources/evm-rpc-services/types/multicall.cjs +3 -0
- package/dist/data-sources/evm-rpc-services/types/multicall.cjs.map +1 -0
- package/dist/data-sources/evm-rpc-services/types/multicall.d.cts +24 -0
- package/dist/data-sources/evm-rpc-services/types/multicall.d.cts.map +1 -0
- package/dist/data-sources/evm-rpc-services/types/multicall.d.mts +24 -0
- package/dist/data-sources/evm-rpc-services/types/multicall.d.mts.map +1 -0
- package/dist/data-sources/evm-rpc-services/types/multicall.mjs +2 -0
- package/dist/data-sources/evm-rpc-services/types/multicall.mjs.map +1 -0
- package/dist/data-sources/evm-rpc-services/types/services.cjs +3 -0
- package/dist/data-sources/evm-rpc-services/types/services.cjs.map +1 -0
- package/dist/data-sources/evm-rpc-services/types/services.d.cts +74 -0
- package/dist/data-sources/evm-rpc-services/types/services.d.cts.map +1 -0
- package/dist/data-sources/evm-rpc-services/types/services.d.mts +74 -0
- package/dist/data-sources/evm-rpc-services/types/services.d.mts.map +1 -0
- package/dist/data-sources/evm-rpc-services/types/services.mjs +2 -0
- package/dist/data-sources/evm-rpc-services/types/services.mjs.map +1 -0
- package/dist/data-sources/evm-rpc-services/types/state.cjs +3 -0
- package/dist/data-sources/evm-rpc-services/types/state.cjs.map +1 -0
- package/dist/data-sources/evm-rpc-services/types/state.d.cts +52 -0
- package/dist/data-sources/evm-rpc-services/types/state.d.cts.map +1 -0
- package/dist/data-sources/evm-rpc-services/types/state.d.mts +52 -0
- package/dist/data-sources/evm-rpc-services/types/state.d.mts.map +1 -0
- package/dist/data-sources/evm-rpc-services/types/state.mjs +2 -0
- package/dist/data-sources/evm-rpc-services/types/state.mjs.map +1 -0
- package/dist/data-sources/evm-rpc-services/utils/batch.cjs +45 -0
- package/dist/data-sources/evm-rpc-services/utils/batch.cjs.map +1 -0
- package/dist/data-sources/evm-rpc-services/utils/batch.d.cts +28 -0
- package/dist/data-sources/evm-rpc-services/utils/batch.d.cts.map +1 -0
- package/dist/data-sources/evm-rpc-services/utils/batch.d.mts +28 -0
- package/dist/data-sources/evm-rpc-services/utils/batch.d.mts.map +1 -0
- package/dist/data-sources/evm-rpc-services/utils/batch.mjs +40 -0
- package/dist/data-sources/evm-rpc-services/utils/batch.mjs.map +1 -0
- package/dist/data-sources/evm-rpc-services/utils/index.cjs +7 -0
- package/dist/data-sources/evm-rpc-services/utils/index.cjs.map +1 -0
- 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 -0
- 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 -0
- package/dist/data-sources/evm-rpc-services/utils/index.mjs +2 -0
- package/dist/data-sources/evm-rpc-services/utils/index.mjs.map +1 -0
- package/dist/data-sources/index.cjs +33 -0
- package/dist/data-sources/index.cjs.map +1 -0
- package/dist/data-sources/index.d.cts +9 -0
- package/dist/data-sources/index.d.cts.map +1 -0
- package/dist/data-sources/index.d.mts +9 -0
- package/dist/data-sources/index.d.mts.map +1 -0
- package/dist/data-sources/index.mjs +15 -0
- package/dist/data-sources/index.mjs.map +1 -0
- package/dist/data-sources/initDataSources.cjs +215 -0
- package/dist/data-sources/initDataSources.cjs.map +1 -0
- package/dist/data-sources/initDataSources.d.cts +140 -0
- package/dist/data-sources/initDataSources.d.cts.map +1 -0
- package/dist/data-sources/initDataSources.d.mts +140 -0
- package/dist/data-sources/initDataSources.d.mts.map +1 -0
- package/dist/data-sources/initDataSources.mjs +210 -0
- package/dist/data-sources/initDataSources.mjs.map +1 -0
- package/dist/index.cjs +47 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +21 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +21 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +25 -0
- package/dist/index.mjs.map +1 -0
- package/dist/logger.cjs +7 -0
- package/dist/logger.cjs.map +1 -0
- package/dist/logger.d.cts +5 -0
- package/dist/logger.d.cts.map +1 -0
- package/dist/logger.d.mts +5 -0
- package/dist/logger.d.mts.map +1 -0
- package/dist/logger.mjs +4 -0
- package/dist/logger.mjs.map +1 -0
- package/dist/middlewares/DetectionMiddleware.cjs +101 -0
- package/dist/middlewares/DetectionMiddleware.cjs.map +1 -0
- package/dist/middlewares/DetectionMiddleware.d.cts +54 -0
- package/dist/middlewares/DetectionMiddleware.d.cts.map +1 -0
- package/dist/middlewares/DetectionMiddleware.d.mts +54 -0
- package/dist/middlewares/DetectionMiddleware.d.mts.map +1 -0
- package/dist/middlewares/DetectionMiddleware.mjs +97 -0
- package/dist/middlewares/DetectionMiddleware.mjs.map +1 -0
- package/dist/middlewares/index.cjs +6 -0
- package/dist/middlewares/index.cjs.map +1 -0
- package/dist/middlewares/index.d.cts +2 -0
- package/dist/middlewares/index.d.cts.map +1 -0
- package/dist/middlewares/index.d.mts +2 -0
- package/dist/middlewares/index.d.mts.map +1 -0
- package/dist/middlewares/index.mjs +2 -0
- package/dist/middlewares/index.mjs.map +1 -0
- package/dist/types.cjs +39 -0
- package/dist/types.cjs.map +1 -0
- package/dist/types.d.cts +433 -0
- package/dist/types.d.cts.map +1 -0
- package/dist/types.d.mts +433 -0
- package/dist/types.d.mts.map +1 -0
- package/dist/types.mjs +35 -0
- package/dist/types.mjs.map +1 -0
- package/dist/utils.cjs +28 -0
- package/dist/utils.cjs.map +1 -0
- package/dist/utils.d.cts +13 -0
- package/dist/utils.d.cts.map +1 -0
- package/dist/utils.d.mts +13 -0
- package/dist/utils.d.mts.map +1 -0
- package/dist/utils.mjs +24 -0
- package/dist/utils.mjs.map +1 -0
- package/package.json +93 -0
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
+
};
|
|
7
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
+
};
|
|
12
|
+
var _TokenDetector_instances, _TokenDetector_multicallClient, _TokenDetector_messenger, _TokenDetector_config, _TokenDetector_onDetectionUpdate, _TokenDetector_processBalanceResponses, _TokenDetector_formatBalance, _TokenDetector_getTokenMetadata, _TokenDetector_createAsset;
|
|
13
|
+
import { StaticIntervalPollingControllerOnly } from "@metamask/polling-controller";
|
|
14
|
+
import { reduceInBatchesSerially } from "../utils/index.mjs";
|
|
15
|
+
const DEFAULT_DETECTION_INTERVAL = 180000; // 3 minutes
|
|
16
|
+
/**
|
|
17
|
+
* TokenDetector - Detects tokens with non-zero balances via multicall.
|
|
18
|
+
* Extends StaticIntervalPollingControllerOnly for built-in polling support.
|
|
19
|
+
*/
|
|
20
|
+
export class TokenDetector extends StaticIntervalPollingControllerOnly() {
|
|
21
|
+
constructor(multicallClient, messenger, config) {
|
|
22
|
+
super();
|
|
23
|
+
_TokenDetector_instances.add(this);
|
|
24
|
+
_TokenDetector_multicallClient.set(this, void 0);
|
|
25
|
+
_TokenDetector_messenger.set(this, void 0);
|
|
26
|
+
_TokenDetector_config.set(this, void 0);
|
|
27
|
+
_TokenDetector_onDetectionUpdate.set(this, void 0);
|
|
28
|
+
__classPrivateFieldSet(this, _TokenDetector_multicallClient, multicallClient, "f");
|
|
29
|
+
__classPrivateFieldSet(this, _TokenDetector_messenger, messenger, "f");
|
|
30
|
+
__classPrivateFieldSet(this, _TokenDetector_config, {
|
|
31
|
+
defaultBatchSize: config?.defaultBatchSize ?? 300,
|
|
32
|
+
defaultTimeoutMs: config?.defaultTimeoutMs ?? 30000,
|
|
33
|
+
}, "f");
|
|
34
|
+
// Set the polling interval
|
|
35
|
+
this.setIntervalLength(config?.pollingInterval ?? DEFAULT_DETECTION_INTERVAL);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Set the callback to receive detection updates during polling.
|
|
39
|
+
*
|
|
40
|
+
* @param callback - Function to call with detection results.
|
|
41
|
+
*/
|
|
42
|
+
setOnDetectionUpdate(callback) {
|
|
43
|
+
__classPrivateFieldSet(this, _TokenDetector_onDetectionUpdate, callback, "f");
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Execute a poll cycle (required by base class).
|
|
47
|
+
* Detects tokens and calls the update callback.
|
|
48
|
+
*
|
|
49
|
+
* @param input - The polling input.
|
|
50
|
+
*/
|
|
51
|
+
async _executePoll(input) {
|
|
52
|
+
// Check if token list is available for this chain
|
|
53
|
+
const tokensToCheck = this.getTokensToCheck(input.chainId);
|
|
54
|
+
if (tokensToCheck.length === 0) {
|
|
55
|
+
// No tokens in list for chain, will retry on next poll
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
const result = await this.detectTokens(input.chainId, input.accountId, input.accountAddress);
|
|
59
|
+
if (__classPrivateFieldGet(this, _TokenDetector_onDetectionUpdate, "f") && result.detectedAssets.length > 0) {
|
|
60
|
+
__classPrivateFieldGet(this, _TokenDetector_onDetectionUpdate, "f").call(this, result);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
getTokensToCheck(chainId) {
|
|
64
|
+
const tokenListState = __classPrivateFieldGet(this, _TokenDetector_messenger, "f").call('TokenListController:getState');
|
|
65
|
+
// Defensive check for tokensChainsCache
|
|
66
|
+
if (!tokenListState?.tokensChainsCache) {
|
|
67
|
+
return [];
|
|
68
|
+
}
|
|
69
|
+
// Try direct lookup first
|
|
70
|
+
let chainCacheEntry = tokenListState.tokensChainsCache[chainId];
|
|
71
|
+
// If not found, try normalizing the chain ID (e.g., 0x0a -> 0xa)
|
|
72
|
+
if (!chainCacheEntry) {
|
|
73
|
+
const normalizedChainId = `0x${parseInt(chainId, 16).toString(16)}`;
|
|
74
|
+
chainCacheEntry = tokenListState.tokensChainsCache[normalizedChainId];
|
|
75
|
+
}
|
|
76
|
+
const chainTokenList = chainCacheEntry?.data;
|
|
77
|
+
if (!chainTokenList) {
|
|
78
|
+
return [];
|
|
79
|
+
}
|
|
80
|
+
return Object.keys(chainTokenList);
|
|
81
|
+
}
|
|
82
|
+
async detectTokens(chainId, accountId, accountAddress, options) {
|
|
83
|
+
const batchSize = options?.batchSize ?? __classPrivateFieldGet(this, _TokenDetector_config, "f").defaultBatchSize;
|
|
84
|
+
const timestamp = Date.now();
|
|
85
|
+
const tokensToCheck = this.getTokensToCheck(chainId);
|
|
86
|
+
if (tokensToCheck.length === 0) {
|
|
87
|
+
return {
|
|
88
|
+
chainId,
|
|
89
|
+
accountId,
|
|
90
|
+
accountAddress,
|
|
91
|
+
detectedAssets: [],
|
|
92
|
+
detectedBalances: [],
|
|
93
|
+
zeroBalanceAddresses: [],
|
|
94
|
+
failedAddresses: [],
|
|
95
|
+
timestamp,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
const balanceRequests = tokensToCheck.map((tokenAddress) => ({
|
|
99
|
+
tokenAddress,
|
|
100
|
+
accountAddress,
|
|
101
|
+
}));
|
|
102
|
+
const result = await reduceInBatchesSerially({
|
|
103
|
+
values: balanceRequests,
|
|
104
|
+
batchSize,
|
|
105
|
+
initialResult: {
|
|
106
|
+
detectedAssets: [],
|
|
107
|
+
detectedBalances: [],
|
|
108
|
+
zeroBalanceAddresses: [],
|
|
109
|
+
failedAddresses: [],
|
|
110
|
+
},
|
|
111
|
+
eachBatch: async (workingResult, batch) => {
|
|
112
|
+
const responses = await __classPrivateFieldGet(this, _TokenDetector_multicallClient, "f").batchBalanceOf(chainId, batch);
|
|
113
|
+
return __classPrivateFieldGet(this, _TokenDetector_instances, "m", _TokenDetector_processBalanceResponses).call(this, responses, workingResult, chainId, accountId, timestamp);
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
return {
|
|
117
|
+
chainId,
|
|
118
|
+
accountId,
|
|
119
|
+
accountAddress,
|
|
120
|
+
...result,
|
|
121
|
+
timestamp,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
_TokenDetector_multicallClient = new WeakMap(), _TokenDetector_messenger = new WeakMap(), _TokenDetector_config = new WeakMap(), _TokenDetector_onDetectionUpdate = new WeakMap(), _TokenDetector_instances = new WeakSet(), _TokenDetector_processBalanceResponses = function _TokenDetector_processBalanceResponses(responses, accumulator, chainId, accountId, timestamp) {
|
|
126
|
+
const { detectedAssets, detectedBalances, zeroBalanceAddresses, failedAddresses, } = accumulator;
|
|
127
|
+
for (const response of responses) {
|
|
128
|
+
if (!response.success) {
|
|
129
|
+
failedAddresses.push(response.tokenAddress);
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
const balance = response.balance ?? '0';
|
|
133
|
+
if (balance === '0' || balance === '') {
|
|
134
|
+
zeroBalanceAddresses.push(response.tokenAddress);
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
const tokenMetadata = __classPrivateFieldGet(this, _TokenDetector_instances, "m", _TokenDetector_getTokenMetadata).call(this, chainId, response.tokenAddress);
|
|
138
|
+
const asset = __classPrivateFieldGet(this, _TokenDetector_instances, "m", _TokenDetector_createAsset).call(this, chainId, response.tokenAddress, tokenMetadata);
|
|
139
|
+
detectedAssets.push(asset);
|
|
140
|
+
const decimals = tokenMetadata?.decimals ?? 18;
|
|
141
|
+
const formattedBalance = __classPrivateFieldGet(this, _TokenDetector_instances, "m", _TokenDetector_formatBalance).call(this, balance, decimals);
|
|
142
|
+
detectedBalances.push({
|
|
143
|
+
assetId: asset.assetId,
|
|
144
|
+
accountId,
|
|
145
|
+
chainId,
|
|
146
|
+
balance,
|
|
147
|
+
formattedBalance,
|
|
148
|
+
decimals,
|
|
149
|
+
timestamp,
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
return {
|
|
153
|
+
detectedAssets,
|
|
154
|
+
detectedBalances,
|
|
155
|
+
zeroBalanceAddresses,
|
|
156
|
+
failedAddresses,
|
|
157
|
+
};
|
|
158
|
+
}, _TokenDetector_formatBalance = function _TokenDetector_formatBalance(rawBalance, decimals) {
|
|
159
|
+
try {
|
|
160
|
+
const balanceBigInt = BigInt(rawBalance);
|
|
161
|
+
const divisor = BigInt(10 ** decimals);
|
|
162
|
+
const integerPart = balanceBigInt / divisor;
|
|
163
|
+
const remainder = balanceBigInt % divisor;
|
|
164
|
+
const fractionalStr = remainder.toString().padStart(decimals, '0');
|
|
165
|
+
const trimmedFractional = fractionalStr.replace(/0+$/u, '');
|
|
166
|
+
if (trimmedFractional === '') {
|
|
167
|
+
return integerPart.toString();
|
|
168
|
+
}
|
|
169
|
+
return `${integerPart}.${trimmedFractional}`;
|
|
170
|
+
}
|
|
171
|
+
catch {
|
|
172
|
+
return rawBalance;
|
|
173
|
+
}
|
|
174
|
+
}, _TokenDetector_getTokenMetadata = function _TokenDetector_getTokenMetadata(chainId, tokenAddress) {
|
|
175
|
+
const tokenListState = __classPrivateFieldGet(this, _TokenDetector_messenger, "f").call('TokenListController:getState');
|
|
176
|
+
if (!tokenListState?.tokensChainsCache) {
|
|
177
|
+
return undefined;
|
|
178
|
+
}
|
|
179
|
+
const chainCacheEntry = tokenListState.tokensChainsCache[chainId];
|
|
180
|
+
const chainTokenList = chainCacheEntry?.data;
|
|
181
|
+
if (!chainTokenList) {
|
|
182
|
+
return undefined;
|
|
183
|
+
}
|
|
184
|
+
if (chainTokenList[tokenAddress]) {
|
|
185
|
+
return chainTokenList[tokenAddress];
|
|
186
|
+
}
|
|
187
|
+
const lowerAddress = tokenAddress.toLowerCase();
|
|
188
|
+
for (const [address, metadata] of Object.entries(chainTokenList)) {
|
|
189
|
+
if (address.toLowerCase() === lowerAddress) {
|
|
190
|
+
return metadata;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return undefined;
|
|
194
|
+
}, _TokenDetector_createAsset = function _TokenDetector_createAsset(chainId, tokenAddress, metadata) {
|
|
195
|
+
const chainIdDecimal = parseInt(chainId, 16);
|
|
196
|
+
const assetId = `eip155:${chainIdDecimal}/erc20:${tokenAddress.toLowerCase()}`;
|
|
197
|
+
return {
|
|
198
|
+
assetId,
|
|
199
|
+
chainId,
|
|
200
|
+
address: tokenAddress,
|
|
201
|
+
type: 'erc20',
|
|
202
|
+
symbol: metadata?.symbol,
|
|
203
|
+
name: metadata?.name,
|
|
204
|
+
decimals: metadata?.decimals,
|
|
205
|
+
image: metadata?.iconUrl,
|
|
206
|
+
isNative: false,
|
|
207
|
+
aggregators: metadata?.aggregators,
|
|
208
|
+
};
|
|
209
|
+
};
|
|
210
|
+
//# sourceMappingURL=TokenDetector.mjs.map
|
|
@@ -0,0 +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,eA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AC7C,IAAI,CAAC,cAAc,EAAE,CAAC;QACpB,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,IAAI,cAAc,CAAC,YAAY,CAAC,EAAE,CAAC;QACjC,OAAO,cAAc,CAAC,YAAY,CAAC,CAAC;IACtC,CAAC;IAED,MAAM,YAAY,GAAG,YAAY,CAAC,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"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BalanceFetcher = exports.TokenDetector = void 0;
|
|
4
|
+
var TokenDetector_1 = require("./TokenDetector.cjs");
|
|
5
|
+
Object.defineProperty(exports, "TokenDetector", { enumerable: true, get: function () { return TokenDetector_1.TokenDetector; } });
|
|
6
|
+
var BalanceFetcher_1 = require("./BalanceFetcher.cjs");
|
|
7
|
+
Object.defineProperty(exports, "BalanceFetcher", { enumerable: true, get: function () { return BalanceFetcher_1.BalanceFetcher; } });
|
|
8
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +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"]}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { TokenDetector, type TokenDetectorConfig, type TokenDetectorMessenger, type DetectionPollingInput, type OnDetectionUpdateCallback, } from "./TokenDetector.cjs";
|
|
2
|
+
export { BalanceFetcher, type BalanceFetcherConfig, type BalanceFetcherMessenger, type BalancePollingInput, type OnBalanceUpdateCallback, } from "./BalanceFetcher.cjs";
|
|
3
|
+
//# sourceMappingURL=index.d.cts.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { TokenDetector, type TokenDetectorConfig, type TokenDetectorMessenger, type DetectionPollingInput, type OnDetectionUpdateCallback, } from "./TokenDetector.mjs";
|
|
2
|
+
export { BalanceFetcher, type BalanceFetcherConfig, type BalanceFetcherMessenger, type BalancePollingInput, type OnBalanceUpdateCallback, } from "./BalanceFetcher.mjs";
|
|
3
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +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"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assets.cjs","sourceRoot":"","sources":["../../../../src/data-sources/evm-rpc-services/types/assets.ts"],"names":[],"mappings":"","sourcesContent":["import type { CaipAssetType } from '@metamask/utils';\n\nimport type { AccountId, Address, AssetType, ChainId } from './core';\n\n/**\n * Core asset definition.\n */\nexport type Asset = {\n /** CAIP-19 asset identifier */\n assetId: CaipAssetType;\n /** Chain ID in hex format */\n chainId: ChainId;\n /** Contract address (zero address for native) */\n address: Address;\n /** Asset type */\n type: AssetType;\n /** Token symbol (e.g., \"ETH\", \"USDC\") */\n symbol?: string;\n /** Token name (e.g., \"Ethereum\", \"USD Coin\") */\n name?: string;\n /** Token decimals */\n decimals?: number;\n /** Logo image URL */\n image?: string;\n /** Whether this is the chain's native token */\n isNative: boolean;\n /** Spam detection flag */\n isSpam?: boolean;\n /** Verification status */\n verified?: boolean;\n /** Token list sources */\n aggregators?: string[];\n};\n\n/**\n * Asset balance for a specific account.\n */\nexport type AssetBalance = {\n /** CAIP-19 asset identifier */\n assetId: CaipAssetType;\n /** Account ID (UUID) */\n accountId: AccountId;\n /** Chain ID in hex format */\n chainId: ChainId;\n /** Raw balance as string (wei/smallest unit) */\n balance: string;\n /** Human-readable balance (balance / 10^decimals) */\n formattedBalance: string;\n /** Token decimals used for formatting */\n decimals: number;\n /** Block number when balance was fetched */\n blockNumber?: number;\n /** Timestamp when balance was fetched */\n timestamp: number;\n};\n"]}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { CaipAssetType } from "@metamask/utils";
|
|
2
|
+
import type { AccountId, Address, AssetType, ChainId } from "./core.cjs";
|
|
3
|
+
/**
|
|
4
|
+
* Core asset definition.
|
|
5
|
+
*/
|
|
6
|
+
export type Asset = {
|
|
7
|
+
/** CAIP-19 asset identifier */
|
|
8
|
+
assetId: CaipAssetType;
|
|
9
|
+
/** Chain ID in hex format */
|
|
10
|
+
chainId: ChainId;
|
|
11
|
+
/** Contract address (zero address for native) */
|
|
12
|
+
address: Address;
|
|
13
|
+
/** Asset type */
|
|
14
|
+
type: AssetType;
|
|
15
|
+
/** Token symbol (e.g., "ETH", "USDC") */
|
|
16
|
+
symbol?: string;
|
|
17
|
+
/** Token name (e.g., "Ethereum", "USD Coin") */
|
|
18
|
+
name?: string;
|
|
19
|
+
/** Token decimals */
|
|
20
|
+
decimals?: number;
|
|
21
|
+
/** Logo image URL */
|
|
22
|
+
image?: string;
|
|
23
|
+
/** Whether this is the chain's native token */
|
|
24
|
+
isNative: boolean;
|
|
25
|
+
/** Spam detection flag */
|
|
26
|
+
isSpam?: boolean;
|
|
27
|
+
/** Verification status */
|
|
28
|
+
verified?: boolean;
|
|
29
|
+
/** Token list sources */
|
|
30
|
+
aggregators?: string[];
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Asset balance for a specific account.
|
|
34
|
+
*/
|
|
35
|
+
export type AssetBalance = {
|
|
36
|
+
/** CAIP-19 asset identifier */
|
|
37
|
+
assetId: CaipAssetType;
|
|
38
|
+
/** Account ID (UUID) */
|
|
39
|
+
accountId: AccountId;
|
|
40
|
+
/** Chain ID in hex format */
|
|
41
|
+
chainId: ChainId;
|
|
42
|
+
/** Raw balance as string (wei/smallest unit) */
|
|
43
|
+
balance: string;
|
|
44
|
+
/** Human-readable balance (balance / 10^decimals) */
|
|
45
|
+
formattedBalance: string;
|
|
46
|
+
/** Token decimals used for formatting */
|
|
47
|
+
decimals: number;
|
|
48
|
+
/** Block number when balance was fetched */
|
|
49
|
+
blockNumber?: number;
|
|
50
|
+
/** Timestamp when balance was fetched */
|
|
51
|
+
timestamp: number;
|
|
52
|
+
};
|
|
53
|
+
//# sourceMappingURL=assets.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assets.d.cts","sourceRoot":"","sources":["../../../../src/data-sources/evm-rpc-services/types/assets.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,wBAAwB;AAErD,OAAO,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,mBAAe;AAErE;;GAEG;AACH,MAAM,MAAM,KAAK,GAAG;IAClB,+BAA+B;IAC/B,OAAO,EAAE,aAAa,CAAC;IACvB,6BAA6B;IAC7B,OAAO,EAAE,OAAO,CAAC;IACjB,iDAAiD;IACjD,OAAO,EAAE,OAAO,CAAC;IACjB,iBAAiB;IACjB,IAAI,EAAE,SAAS,CAAC;IAChB,yCAAyC;IACzC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,gDAAgD;IAChD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,qBAAqB;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,qBAAqB;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,+CAA+C;IAC/C,QAAQ,EAAE,OAAO,CAAC;IAClB,0BAA0B;IAC1B,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,0BAA0B;IAC1B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,yBAAyB;IACzB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;CACxB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,+BAA+B;IAC/B,OAAO,EAAE,aAAa,CAAC;IACvB,wBAAwB;IACxB,SAAS,EAAE,SAAS,CAAC;IACrB,6BAA6B;IAC7B,OAAO,EAAE,OAAO,CAAC;IACjB,gDAAgD;IAChD,OAAO,EAAE,MAAM,CAAC;IAChB,qDAAqD;IACrD,gBAAgB,EAAE,MAAM,CAAC;IACzB,yCAAyC;IACzC,QAAQ,EAAE,MAAM,CAAC;IACjB,4CAA4C;IAC5C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,yCAAyC;IACzC,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { CaipAssetType } from "@metamask/utils";
|
|
2
|
+
import type { AccountId, Address, AssetType, ChainId } from "./core.mjs";
|
|
3
|
+
/**
|
|
4
|
+
* Core asset definition.
|
|
5
|
+
*/
|
|
6
|
+
export type Asset = {
|
|
7
|
+
/** CAIP-19 asset identifier */
|
|
8
|
+
assetId: CaipAssetType;
|
|
9
|
+
/** Chain ID in hex format */
|
|
10
|
+
chainId: ChainId;
|
|
11
|
+
/** Contract address (zero address for native) */
|
|
12
|
+
address: Address;
|
|
13
|
+
/** Asset type */
|
|
14
|
+
type: AssetType;
|
|
15
|
+
/** Token symbol (e.g., "ETH", "USDC") */
|
|
16
|
+
symbol?: string;
|
|
17
|
+
/** Token name (e.g., "Ethereum", "USD Coin") */
|
|
18
|
+
name?: string;
|
|
19
|
+
/** Token decimals */
|
|
20
|
+
decimals?: number;
|
|
21
|
+
/** Logo image URL */
|
|
22
|
+
image?: string;
|
|
23
|
+
/** Whether this is the chain's native token */
|
|
24
|
+
isNative: boolean;
|
|
25
|
+
/** Spam detection flag */
|
|
26
|
+
isSpam?: boolean;
|
|
27
|
+
/** Verification status */
|
|
28
|
+
verified?: boolean;
|
|
29
|
+
/** Token list sources */
|
|
30
|
+
aggregators?: string[];
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Asset balance for a specific account.
|
|
34
|
+
*/
|
|
35
|
+
export type AssetBalance = {
|
|
36
|
+
/** CAIP-19 asset identifier */
|
|
37
|
+
assetId: CaipAssetType;
|
|
38
|
+
/** Account ID (UUID) */
|
|
39
|
+
accountId: AccountId;
|
|
40
|
+
/** Chain ID in hex format */
|
|
41
|
+
chainId: ChainId;
|
|
42
|
+
/** Raw balance as string (wei/smallest unit) */
|
|
43
|
+
balance: string;
|
|
44
|
+
/** Human-readable balance (balance / 10^decimals) */
|
|
45
|
+
formattedBalance: string;
|
|
46
|
+
/** Token decimals used for formatting */
|
|
47
|
+
decimals: number;
|
|
48
|
+
/** Block number when balance was fetched */
|
|
49
|
+
blockNumber?: number;
|
|
50
|
+
/** Timestamp when balance was fetched */
|
|
51
|
+
timestamp: number;
|
|
52
|
+
};
|
|
53
|
+
//# sourceMappingURL=assets.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assets.d.mts","sourceRoot":"","sources":["../../../../src/data-sources/evm-rpc-services/types/assets.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,wBAAwB;AAErD,OAAO,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,mBAAe;AAErE;;GAEG;AACH,MAAM,MAAM,KAAK,GAAG;IAClB,+BAA+B;IAC/B,OAAO,EAAE,aAAa,CAAC;IACvB,6BAA6B;IAC7B,OAAO,EAAE,OAAO,CAAC;IACjB,iDAAiD;IACjD,OAAO,EAAE,OAAO,CAAC;IACjB,iBAAiB;IACjB,IAAI,EAAE,SAAS,CAAC;IAChB,yCAAyC;IACzC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,gDAAgD;IAChD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,qBAAqB;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,qBAAqB;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,+CAA+C;IAC/C,QAAQ,EAAE,OAAO,CAAC;IAClB,0BAA0B;IAC1B,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,0BAA0B;IAC1B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,yBAAyB;IACzB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;CACxB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,+BAA+B;IAC/B,OAAO,EAAE,aAAa,CAAC;IACvB,wBAAwB;IACxB,SAAS,EAAE,SAAS,CAAC;IACrB,6BAA6B;IAC7B,OAAO,EAAE,OAAO,CAAC;IACjB,gDAAgD;IAChD,OAAO,EAAE,MAAM,CAAC;IAChB,qDAAqD;IACrD,gBAAgB,EAAE,MAAM,CAAC;IACzB,yCAAyC;IACzC,QAAQ,EAAE,MAAM,CAAC;IACjB,4CAA4C;IAC5C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,yCAAyC;IACzC,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assets.mjs","sourceRoot":"","sources":["../../../../src/data-sources/evm-rpc-services/types/assets.ts"],"names":[],"mappings":"","sourcesContent":["import type { CaipAssetType } from '@metamask/utils';\n\nimport type { AccountId, Address, AssetType, ChainId } from './core';\n\n/**\n * Core asset definition.\n */\nexport type Asset = {\n /** CAIP-19 asset identifier */\n assetId: CaipAssetType;\n /** Chain ID in hex format */\n chainId: ChainId;\n /** Contract address (zero address for native) */\n address: Address;\n /** Asset type */\n type: AssetType;\n /** Token symbol (e.g., \"ETH\", \"USDC\") */\n symbol?: string;\n /** Token name (e.g., \"Ethereum\", \"USD Coin\") */\n name?: string;\n /** Token decimals */\n decimals?: number;\n /** Logo image URL */\n image?: string;\n /** Whether this is the chain's native token */\n isNative: boolean;\n /** Spam detection flag */\n isSpam?: boolean;\n /** Verification status */\n verified?: boolean;\n /** Token list sources */\n aggregators?: string[];\n};\n\n/**\n * Asset balance for a specific account.\n */\nexport type AssetBalance = {\n /** CAIP-19 asset identifier */\n assetId: CaipAssetType;\n /** Account ID (UUID) */\n accountId: AccountId;\n /** Chain ID in hex format */\n chainId: ChainId;\n /** Raw balance as string (wei/smallest unit) */\n balance: string;\n /** Human-readable balance (balance / 10^decimals) */\n formattedBalance: string;\n /** Token decimals used for formatting */\n decimals: number;\n /** Block number when balance was fetched */\n blockNumber?: number;\n /** Timestamp when balance was fetched */\n timestamp: number;\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.cjs","sourceRoot":"","sources":["../../../../src/data-sources/evm-rpc-services/types/config.ts"],"names":[],"mappings":"","sourcesContent":["import type { ChainId } from './core';\n\n/**\n * Minimal provider interface for RPC calls.\n */\nexport type Provider = {\n call(transaction: { to: string; data: string }): Promise<string>;\n getBalance(address: string): Promise<{ toString(): string }>;\n};\n\n/**\n * Function to get provider for a specific chain.\n */\nexport type GetProviderFunction = (chainId: ChainId) => Provider;\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ChainId } from "./core.cjs";
|
|
2
|
+
/**
|
|
3
|
+
* Minimal provider interface for RPC calls.
|
|
4
|
+
*/
|
|
5
|
+
export type Provider = {
|
|
6
|
+
call(transaction: {
|
|
7
|
+
to: string;
|
|
8
|
+
data: string;
|
|
9
|
+
}): Promise<string>;
|
|
10
|
+
getBalance(address: string): Promise<{
|
|
11
|
+
toString(): string;
|
|
12
|
+
}>;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Function to get provider for a specific chain.
|
|
16
|
+
*/
|
|
17
|
+
export type GetProviderFunction = (chainId: ChainId) => Provider;
|
|
18
|
+
//# sourceMappingURL=config.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.cts","sourceRoot":"","sources":["../../../../src/data-sources/evm-rpc-services/types/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,mBAAe;AAEtC;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG;IACrB,IAAI,CAAC,WAAW,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACjE,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,QAAQ,IAAI,MAAM,CAAA;KAAE,CAAC,CAAC;CAC9D,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG,CAAC,OAAO,EAAE,OAAO,KAAK,QAAQ,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ChainId } from "./core.mjs";
|
|
2
|
+
/**
|
|
3
|
+
* Minimal provider interface for RPC calls.
|
|
4
|
+
*/
|
|
5
|
+
export type Provider = {
|
|
6
|
+
call(transaction: {
|
|
7
|
+
to: string;
|
|
8
|
+
data: string;
|
|
9
|
+
}): Promise<string>;
|
|
10
|
+
getBalance(address: string): Promise<{
|
|
11
|
+
toString(): string;
|
|
12
|
+
}>;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Function to get provider for a specific chain.
|
|
16
|
+
*/
|
|
17
|
+
export type GetProviderFunction = (chainId: ChainId) => Provider;
|
|
18
|
+
//# sourceMappingURL=config.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.mts","sourceRoot":"","sources":["../../../../src/data-sources/evm-rpc-services/types/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,mBAAe;AAEtC;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG;IACrB,IAAI,CAAC,WAAW,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACjE,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,QAAQ,IAAI,MAAM,CAAA;KAAE,CAAC,CAAC;CAC9D,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG,CAAC,OAAO,EAAE,OAAO,KAAK,QAAQ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.mjs","sourceRoot":"","sources":["../../../../src/data-sources/evm-rpc-services/types/config.ts"],"names":[],"mappings":"","sourcesContent":["import type { ChainId } from './core';\n\n/**\n * Minimal provider interface for RPC calls.\n */\nexport type Provider = {\n call(transaction: { to: string; data: string }): Promise<string>;\n getBalance(address: string): Promise<{ toString(): string }>;\n};\n\n/**\n * Function to get provider for a specific chain.\n */\nexport type GetProviderFunction = (chainId: ChainId) => Provider;\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core.cjs","sourceRoot":"","sources":["../../../../src/data-sources/evm-rpc-services/types/core.ts"],"names":[],"mappings":"","sourcesContent":["import type { CaipAssetType, Hex } from '@metamask/utils';\n\n// Re-export for convenience\nexport type { CaipAssetType };\n\n/**\n * Account ID - UUID from InternalAccount.id\n */\nexport type AccountId = string;\n\n/**\n * Chain ID in hex format (e.g., \"0x1\" for Ethereum mainnet)\n */\nexport type ChainId = Hex;\n\n/**\n * Token/Contract address in hex format\n */\nexport type Address = Hex;\n\n/**\n * Asset type identifier for categorization.\n */\nexport type AssetType = 'native' | 'erc20' | 'erc721' | 'erc1155';\n"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { CaipAssetType, Hex } from "@metamask/utils";
|
|
2
|
+
export type { CaipAssetType };
|
|
3
|
+
/**
|
|
4
|
+
* Account ID - UUID from InternalAccount.id
|
|
5
|
+
*/
|
|
6
|
+
export type AccountId = string;
|
|
7
|
+
/**
|
|
8
|
+
* Chain ID in hex format (e.g., "0x1" for Ethereum mainnet)
|
|
9
|
+
*/
|
|
10
|
+
export type ChainId = Hex;
|
|
11
|
+
/**
|
|
12
|
+
* Token/Contract address in hex format
|
|
13
|
+
*/
|
|
14
|
+
export type Address = Hex;
|
|
15
|
+
/**
|
|
16
|
+
* Asset type identifier for categorization.
|
|
17
|
+
*/
|
|
18
|
+
export type AssetType = 'native' | 'erc20' | 'erc721' | 'erc1155';
|
|
19
|
+
//# sourceMappingURL=core.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core.d.cts","sourceRoot":"","sources":["../../../../src/data-sources/evm-rpc-services/types/core.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,GAAG,EAAE,wBAAwB;AAG1D,YAAY,EAAE,aAAa,EAAE,CAAC;AAE9B;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC;AAE/B;;GAEG;AACH,MAAM,MAAM,OAAO,GAAG,GAAG,CAAC;AAE1B;;GAEG;AACH,MAAM,MAAM,OAAO,GAAG,GAAG,CAAC;AAE1B;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,QAAQ,GAAG,OAAO,GAAG,QAAQ,GAAG,SAAS,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { CaipAssetType, Hex } from "@metamask/utils";
|
|
2
|
+
export type { CaipAssetType };
|
|
3
|
+
/**
|
|
4
|
+
* Account ID - UUID from InternalAccount.id
|
|
5
|
+
*/
|
|
6
|
+
export type AccountId = string;
|
|
7
|
+
/**
|
|
8
|
+
* Chain ID in hex format (e.g., "0x1" for Ethereum mainnet)
|
|
9
|
+
*/
|
|
10
|
+
export type ChainId = Hex;
|
|
11
|
+
/**
|
|
12
|
+
* Token/Contract address in hex format
|
|
13
|
+
*/
|
|
14
|
+
export type Address = Hex;
|
|
15
|
+
/**
|
|
16
|
+
* Asset type identifier for categorization.
|
|
17
|
+
*/
|
|
18
|
+
export type AssetType = 'native' | 'erc20' | 'erc721' | 'erc1155';
|
|
19
|
+
//# sourceMappingURL=core.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core.d.mts","sourceRoot":"","sources":["../../../../src/data-sources/evm-rpc-services/types/core.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,GAAG,EAAE,wBAAwB;AAG1D,YAAY,EAAE,aAAa,EAAE,CAAC;AAE9B;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC;AAE/B;;GAEG;AACH,MAAM,MAAM,OAAO,GAAG,GAAG,CAAC;AAE1B;;GAEG;AACH,MAAM,MAAM,OAAO,GAAG,GAAG,CAAC;AAE1B;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,QAAQ,GAAG,OAAO,GAAG,QAAQ,GAAG,SAAS,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core.mjs","sourceRoot":"","sources":["../../../../src/data-sources/evm-rpc-services/types/core.ts"],"names":[],"mappings":"","sourcesContent":["import type { CaipAssetType, Hex } from '@metamask/utils';\n\n// Re-export for convenience\nexport type { CaipAssetType };\n\n/**\n * Account ID - UUID from InternalAccount.id\n */\nexport type AccountId = string;\n\n/**\n * Chain ID in hex format (e.g., \"0x1\" for Ethereum mainnet)\n */\nexport type ChainId = Hex;\n\n/**\n * Token/Contract address in hex format\n */\nexport type Address = Hex;\n\n/**\n * Asset type identifier for categorization.\n */\nexport type AssetType = 'native' | 'erc20' | 'erc721' | 'erc1155';\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../../../src/data-sources/evm-rpc-services/types/index.ts"],"names":[],"mappings":"","sourcesContent":["// Core types\nexport type {\n AccountId,\n Address,\n AssetType,\n CaipAssetType,\n ChainId,\n} from './core';\n\n// Asset types\nexport type { Asset, AssetBalance } from './assets';\n\n// State types\nexport type {\n AssetsBalanceState,\n TokenChainsCacheEntry,\n TokenListEntry,\n TokenListState,\n} from './state';\n\n// Config types\nexport type { GetProviderFunction, Provider } from './config';\n\n// Multicall types\nexport type { BalanceOfRequest, BalanceOfResponse } from './multicall';\n\n// Service types\nexport type {\n BalanceFetchOptions,\n BalanceFetchResult,\n TokenDetectionOptions,\n TokenDetectionResult,\n TokenFetchInfo,\n} from './services';\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type { AccountId, Address, AssetType, CaipAssetType, ChainId, } from "./core.cjs";
|
|
2
|
+
export type { Asset, AssetBalance } from "./assets.cjs";
|
|
3
|
+
export type { AssetsBalanceState, TokenChainsCacheEntry, TokenListEntry, TokenListState, } from "./state.cjs";
|
|
4
|
+
export type { GetProviderFunction, Provider } from "./config.cjs";
|
|
5
|
+
export type { BalanceOfRequest, BalanceOfResponse } from "./multicall.cjs";
|
|
6
|
+
export type { BalanceFetchOptions, BalanceFetchResult, TokenDetectionOptions, TokenDetectionResult, TokenFetchInfo, } from "./services.cjs";
|
|
7
|
+
//# sourceMappingURL=index.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../../../src/data-sources/evm-rpc-services/types/index.ts"],"names":[],"mappings":"AACA,YAAY,EACV,SAAS,EACT,OAAO,EACP,SAAS,EACT,aAAa,EACb,OAAO,GACR,mBAAe;AAGhB,YAAY,EAAE,KAAK,EAAE,YAAY,EAAE,qBAAiB;AAGpD,YAAY,EACV,kBAAkB,EAClB,qBAAqB,EACrB,cAAc,EACd,cAAc,GACf,oBAAgB;AAGjB,YAAY,EAAE,mBAAmB,EAAE,QAAQ,EAAE,qBAAiB;AAG9D,YAAY,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,wBAAoB;AAGvE,YAAY,EACV,mBAAmB,EACnB,kBAAkB,EAClB,qBAAqB,EACrB,oBAAoB,EACpB,cAAc,GACf,uBAAmB"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type { AccountId, Address, AssetType, CaipAssetType, ChainId, } from "./core.mjs";
|
|
2
|
+
export type { Asset, AssetBalance } from "./assets.mjs";
|
|
3
|
+
export type { AssetsBalanceState, TokenChainsCacheEntry, TokenListEntry, TokenListState, } from "./state.mjs";
|
|
4
|
+
export type { GetProviderFunction, Provider } from "./config.mjs";
|
|
5
|
+
export type { BalanceOfRequest, BalanceOfResponse } from "./multicall.mjs";
|
|
6
|
+
export type { BalanceFetchOptions, BalanceFetchResult, TokenDetectionOptions, TokenDetectionResult, TokenFetchInfo, } from "./services.mjs";
|
|
7
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../../../src/data-sources/evm-rpc-services/types/index.ts"],"names":[],"mappings":"AACA,YAAY,EACV,SAAS,EACT,OAAO,EACP,SAAS,EACT,aAAa,EACb,OAAO,GACR,mBAAe;AAGhB,YAAY,EAAE,KAAK,EAAE,YAAY,EAAE,qBAAiB;AAGpD,YAAY,EACV,kBAAkB,EAClB,qBAAqB,EACrB,cAAc,EACd,cAAc,GACf,oBAAgB;AAGjB,YAAY,EAAE,mBAAmB,EAAE,QAAQ,EAAE,qBAAiB;AAG9D,YAAY,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,wBAAoB;AAGvE,YAAY,EACV,mBAAmB,EACnB,kBAAkB,EAClB,qBAAqB,EACrB,oBAAoB,EACpB,cAAc,GACf,uBAAmB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../../../src/data-sources/evm-rpc-services/types/index.ts"],"names":[],"mappings":"","sourcesContent":["// Core types\nexport type {\n AccountId,\n Address,\n AssetType,\n CaipAssetType,\n ChainId,\n} from './core';\n\n// Asset types\nexport type { Asset, AssetBalance } from './assets';\n\n// State types\nexport type {\n AssetsBalanceState,\n TokenChainsCacheEntry,\n TokenListEntry,\n TokenListState,\n} from './state';\n\n// Config types\nexport type { GetProviderFunction, Provider } from './config';\n\n// Multicall types\nexport type { BalanceOfRequest, BalanceOfResponse } from './multicall';\n\n// Service types\nexport type {\n BalanceFetchOptions,\n BalanceFetchResult,\n TokenDetectionOptions,\n TokenDetectionResult,\n TokenFetchInfo,\n} from './services';\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multicall.cjs","sourceRoot":"","sources":["../../../../src/data-sources/evm-rpc-services/types/multicall.ts"],"names":[],"mappings":"","sourcesContent":["import type { Address } from './core';\n\n/**\n * Balance request for batch balance fetching.\n */\nexport type BalanceOfRequest = {\n /** Token contract address (zero address for native) */\n tokenAddress: Address;\n /** Account address to check balance for */\n accountAddress: Address;\n};\n\n/**\n * Balance response from batch balance fetching.\n */\nexport type BalanceOfResponse = {\n /** Token contract address */\n tokenAddress: Address;\n /** Account address */\n accountAddress: Address;\n /** Whether the call succeeded */\n success: boolean;\n /** Balance as string (raw value) */\n balance?: string;\n};\n"]}
|