@metamask-previews/multichain-network-controller 3.2.4-preview-4f4c98e → 3.2.4-preview-5b293ee50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +0 -4
- package/dist/MultichainNetworkController/MultichainNetworkController-method-action-types.cjs +7 -0
- package/dist/MultichainNetworkController/MultichainNetworkController-method-action-types.cjs.map +1 -0
- package/dist/MultichainNetworkController/{MultichainNetworkController-method-action-types.d.ts → MultichainNetworkController-method-action-types.d.cts} +2 -2
- package/dist/MultichainNetworkController/MultichainNetworkController-method-action-types.d.cts.map +1 -0
- package/dist/MultichainNetworkController/MultichainNetworkController-method-action-types.d.mts +30 -0
- package/dist/MultichainNetworkController/MultichainNetworkController-method-action-types.d.mts.map +1 -0
- package/dist/MultichainNetworkController/{MultichainNetworkController-method-action-types.js → MultichainNetworkController-method-action-types.mjs} +1 -1
- package/dist/MultichainNetworkController/MultichainNetworkController-method-action-types.mjs.map +1 -0
- package/dist/MultichainNetworkController/MultichainNetworkController.cjs +208 -0
- package/dist/MultichainNetworkController/MultichainNetworkController.cjs.map +1 -0
- package/dist/MultichainNetworkController/{MultichainNetworkController.d.ts → MultichainNetworkController.d.cts} +8 -8
- package/dist/MultichainNetworkController/MultichainNetworkController.d.cts.map +1 -0
- package/dist/MultichainNetworkController/MultichainNetworkController.d.mts +42 -0
- package/dist/MultichainNetworkController/MultichainNetworkController.d.mts.map +1 -0
- package/dist/MultichainNetworkController/{MultichainNetworkController.js → MultichainNetworkController.mjs} +8 -8
- package/dist/MultichainNetworkController/MultichainNetworkController.mjs.map +1 -0
- package/dist/MultichainNetworkService/AbstractMultichainNetworkService.cjs +3 -0
- package/dist/MultichainNetworkService/AbstractMultichainNetworkService.cjs.map +1 -0
- package/dist/MultichainNetworkService/AbstractMultichainNetworkService.d.cts +7 -0
- package/dist/MultichainNetworkService/AbstractMultichainNetworkService.d.cts.map +1 -0
- package/dist/MultichainNetworkService/AbstractMultichainNetworkService.d.mts +7 -0
- package/dist/MultichainNetworkService/AbstractMultichainNetworkService.d.mts.map +1 -0
- package/dist/MultichainNetworkService/AbstractMultichainNetworkService.mjs +2 -0
- package/dist/MultichainNetworkService/AbstractMultichainNetworkService.mjs.map +1 -0
- package/dist/MultichainNetworkService/MultichainNetworkService.cjs +89 -0
- package/dist/MultichainNetworkService/MultichainNetworkService.cjs.map +1 -0
- package/dist/MultichainNetworkService/{MultichainNetworkService.d.ts → MultichainNetworkService.d.cts} +3 -3
- package/dist/MultichainNetworkService/MultichainNetworkService.d.cts.map +1 -0
- package/dist/MultichainNetworkService/MultichainNetworkService.d.mts +22 -0
- package/dist/MultichainNetworkService/MultichainNetworkService.d.mts.map +1 -0
- package/dist/MultichainNetworkService/{MultichainNetworkService.js → MultichainNetworkService.mjs} +5 -4
- package/dist/MultichainNetworkService/MultichainNetworkService.mjs.map +1 -0
- package/dist/api/accounts-api.cjs +90 -0
- package/dist/api/accounts-api.cjs.map +1 -0
- package/dist/api/{accounts-api.d.ts → accounts-api.d.cts} +4 -4
- package/dist/api/accounts-api.d.cts.map +1 -0
- package/dist/api/accounts-api.d.mts +55 -0
- package/dist/api/accounts-api.d.mts.map +1 -0
- package/dist/api/{accounts-api.js → accounts-api.mjs} +4 -4
- package/dist/api/accounts-api.mjs.map +1 -0
- package/dist/constants.cjs +222 -0
- package/dist/constants.cjs.map +1 -0
- package/dist/{constants.d.ts → constants.d.cts} +3 -3
- package/dist/constants.d.cts.map +1 -0
- package/dist/constants.d.mts +79 -0
- package/dist/constants.d.mts.map +1 -0
- package/dist/{constants.js → constants.mjs} +3 -3
- package/dist/constants.mjs.map +1 -0
- package/dist/index.cjs +19 -0
- package/dist/index.cjs.map +1 -0
- package/dist/{index.d.ts → index.d.cts} +8 -8
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +8 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +5 -0
- package/dist/index.mjs.map +1 -0
- package/dist/types.cjs +5 -0
- package/dist/types.cjs.map +1 -0
- package/dist/{types.d.ts → types.d.cts} +9 -9
- package/dist/types.d.cts.map +1 -0
- package/dist/types.d.mts +118 -0
- package/dist/types.d.mts.map +1 -0
- package/dist/{types.js → types.mjs} +1 -1
- package/dist/types.mjs.map +1 -0
- package/dist/utils.cjs +106 -0
- package/dist/utils.cjs.map +1 -0
- package/dist/{utils.d.ts → utils.d.cts} +5 -5
- package/dist/utils.d.cts.map +1 -0
- package/dist/utils.d.mts +63 -0
- package/dist/utils.d.mts.map +1 -0
- package/dist/{utils.js → utils.mjs} +3 -3
- package/dist/utils.mjs.map +1 -0
- package/package.json +18 -14
- package/dist/MultichainNetworkController/MultichainNetworkController-method-action-types.d.ts.map +0 -1
- package/dist/MultichainNetworkController/MultichainNetworkController-method-action-types.js.map +0 -1
- package/dist/MultichainNetworkController/MultichainNetworkController.d.ts.map +0 -1
- package/dist/MultichainNetworkController/MultichainNetworkController.js.map +0 -1
- package/dist/MultichainNetworkService/AbstractMultichainNetworkService.d.ts +0 -7
- package/dist/MultichainNetworkService/AbstractMultichainNetworkService.d.ts.map +0 -1
- package/dist/MultichainNetworkService/AbstractMultichainNetworkService.js +0 -2
- package/dist/MultichainNetworkService/AbstractMultichainNetworkService.js.map +0 -1
- package/dist/MultichainNetworkService/MultichainNetworkService.d.ts.map +0 -1
- package/dist/MultichainNetworkService/MultichainNetworkService.js.map +0 -1
- package/dist/api/accounts-api.d.ts.map +0 -1
- package/dist/api/accounts-api.js.map +0 -1
- package/dist/constants.d.ts.map +0 -1
- package/dist/constants.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -5
- package/dist/index.js.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js.map +0 -1
- package/dist/utils.d.ts.map +0 -1
- package/dist/utils.js.map +0 -1
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
+
};
|
|
8
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
+
};
|
|
13
|
+
var _MultichainNetworkService_instances, _MultichainNetworkService_fetch, _MultichainNetworkService_batchSize, _MultichainNetworkService_fetchNetworkActivityBatch;
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.MultichainNetworkService = void 0;
|
|
16
|
+
const superstruct_1 = require("@metamask/superstruct");
|
|
17
|
+
const lodash_1 = require("lodash");
|
|
18
|
+
const accounts_api_js_1 = require("../api/accounts-api.cjs");
|
|
19
|
+
/**
|
|
20
|
+
* Service responsible for fetching network activity data from the API.
|
|
21
|
+
*/
|
|
22
|
+
class MultichainNetworkService {
|
|
23
|
+
constructor({ fetch: fetchFunction, batchSize, }) {
|
|
24
|
+
_MultichainNetworkService_instances.add(this);
|
|
25
|
+
_MultichainNetworkService_fetch.set(this, void 0);
|
|
26
|
+
_MultichainNetworkService_batchSize.set(this, void 0);
|
|
27
|
+
__classPrivateFieldSet(this, _MultichainNetworkService_fetch, fetchFunction, "f");
|
|
28
|
+
__classPrivateFieldSet(this, _MultichainNetworkService_batchSize, batchSize ?? 20, "f");
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Fetches active networks for the given account IDs.
|
|
32
|
+
* Automatically handles batching requests to comply with URL length limitations.
|
|
33
|
+
*
|
|
34
|
+
* @param accountIds - Array of CAIP-10 account IDs to fetch activity for.
|
|
35
|
+
* @returns Promise resolving to the combined active networks response.
|
|
36
|
+
* @throws Error if the response format is invalid or the request fails.
|
|
37
|
+
*/
|
|
38
|
+
async fetchNetworkActivity(accountIds) {
|
|
39
|
+
if (accountIds.length === 0) {
|
|
40
|
+
return { activeNetworks: [] };
|
|
41
|
+
}
|
|
42
|
+
if (accountIds.length <= __classPrivateFieldGet(this, _MultichainNetworkService_batchSize, "f")) {
|
|
43
|
+
return __classPrivateFieldGet(this, _MultichainNetworkService_instances, "m", _MultichainNetworkService_fetchNetworkActivityBatch).call(this, accountIds);
|
|
44
|
+
}
|
|
45
|
+
const batches = (0, lodash_1.chunk)(accountIds, __classPrivateFieldGet(this, _MultichainNetworkService_batchSize, "f"));
|
|
46
|
+
const batchResults = await Promise.all(batches.map((batch) => __classPrivateFieldGet(this, _MultichainNetworkService_instances, "m", _MultichainNetworkService_fetchNetworkActivityBatch).call(this, batch)));
|
|
47
|
+
const combinedResponse = {
|
|
48
|
+
activeNetworks: batchResults.flatMap((response) => response.activeNetworks),
|
|
49
|
+
};
|
|
50
|
+
return combinedResponse;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.MultichainNetworkService = MultichainNetworkService;
|
|
54
|
+
_MultichainNetworkService_fetch = new WeakMap(), _MultichainNetworkService_batchSize = new WeakMap(), _MultichainNetworkService_instances = new WeakSet(), _MultichainNetworkService_fetchNetworkActivityBatch =
|
|
55
|
+
/**
|
|
56
|
+
* Internal method to fetch a single batch of account IDs.
|
|
57
|
+
*
|
|
58
|
+
* @param accountIds - Batch of account IDs to fetch
|
|
59
|
+
* @returns Promise resolving to the active networks response for this batch
|
|
60
|
+
* @throws Error if the response format is invalid or the request fails
|
|
61
|
+
*/
|
|
62
|
+
async function _MultichainNetworkService_fetchNetworkActivityBatch(accountIds) {
|
|
63
|
+
try {
|
|
64
|
+
const url = (0, accounts_api_js_1.buildActiveNetworksUrl)(accountIds);
|
|
65
|
+
const response = await __classPrivateFieldGet(this, _MultichainNetworkService_fetch, "f").call(this, url.toString(), {
|
|
66
|
+
method: 'GET',
|
|
67
|
+
headers: {
|
|
68
|
+
[accounts_api_js_1.MULTICHAIN_ACCOUNTS_CLIENT_HEADER]: accounts_api_js_1.MULTICHAIN_ACCOUNTS_CLIENT_ID,
|
|
69
|
+
Accept: 'application/json',
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
if (!response.ok) {
|
|
73
|
+
throw new Error(`HTTP error! status: ${response.status}`);
|
|
74
|
+
}
|
|
75
|
+
const data = await response.json();
|
|
76
|
+
(0, superstruct_1.assert)(data, accounts_api_js_1.ActiveNetworksResponseStruct);
|
|
77
|
+
return data;
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
if (error instanceof Error) {
|
|
81
|
+
if (error.name === 'AbortError') {
|
|
82
|
+
throw new Error('Request timeout: Failed to fetch active networks');
|
|
83
|
+
}
|
|
84
|
+
throw error;
|
|
85
|
+
}
|
|
86
|
+
throw new Error(`Failed to fetch active networks: ${String(error)}`);
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
//# sourceMappingURL=MultichainNetworkService.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MultichainNetworkService.cjs","sourceRoot":"","sources":["../../src/MultichainNetworkService/MultichainNetworkService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,uDAA+C;AAE/C,mCAA+B;AAE/B,6DAKgC;AAGhC;;GAEG;AACH,MAAa,wBAAwB;IAKnC,YAAY,EACV,KAAK,EAAE,aAAa,EACpB,SAAS,GAIV;;QAVQ,kDAAqB;QAErB,sDAAmB;QAS1B,uBAAA,IAAI,mCAAU,aAAa,MAAA,CAAC;QAC5B,uB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,QAAQ,CAAC,EAAE,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CAAC,uBAAuB,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;QAC5D,CAAC;QAED,MAAM,IAAI,GAAY,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;QAE5C,IAAA,oBAAM,EAAC,IAAI,EAAE,8CAA4B,CAAC,CAAC;QAC3C,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;YAC3B,IAAI,KAAK,CAAC,IAAI,KAAK,YAAY,EAAE,CAAC;gBAChC,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;YACtE,CAAC;YACD,MAAM,KAAK,CAAC;QACd,CAAC;QAED,MAAM,IAAI,KAAK,CAAC,oCAAoC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IACvE,CAAC;AACH,CAAC","sourcesContent":["import { assert } from '@metamask/superstruct';\nimport type { CaipAccountId } from '@metamask/utils';\nimport { chunk } from 'lodash';\n\nimport {\n ActiveNetworksResponseStruct,\n buildActiveNetworksUrl,\n MULTICHAIN_ACCOUNTS_CLIENT_HEADER,\n MULTICHAIN_ACCOUNTS_CLIENT_ID,\n} from '../api/accounts-api.js';\nimport type { ActiveNetworksResponse } from '../api/accounts-api.js';\n\n/**\n * Service responsible for fetching network activity data from the API.\n */\nexport class MultichainNetworkService {\n readonly #fetch: typeof fetch;\n\n readonly #batchSize: number;\n\n constructor({\n fetch: fetchFunction,\n batchSize,\n }: {\n fetch: typeof fetch;\n batchSize?: number;\n }) {\n this.#fetch = fetchFunction;\n this.#batchSize = batchSize ?? 20;\n }\n\n /**\n * Fetches active networks for the given account IDs.\n * Automatically handles batching requests to comply with URL length limitations.\n *\n * @param accountIds - Array of CAIP-10 account IDs to fetch activity for.\n * @returns Promise resolving to the combined active networks response.\n * @throws Error if the response format is invalid or the request fails.\n */\n async fetchNetworkActivity(\n accountIds: CaipAccountId[],\n ): Promise<ActiveNetworksResponse> {\n if (accountIds.length === 0) {\n return { activeNetworks: [] };\n }\n\n if (accountIds.length <= this.#batchSize) {\n return this.#fetchNetworkActivityBatch(accountIds);\n }\n\n const batches = chunk(accountIds, this.#batchSize);\n const batchResults = await Promise.all(\n batches.map((batch) => this.#fetchNetworkActivityBatch(batch)),\n );\n\n const combinedResponse: ActiveNetworksResponse = {\n activeNetworks: batchResults.flatMap(\n (response) => response.activeNetworks,\n ),\n };\n\n return combinedResponse;\n }\n\n /**\n * Internal method to fetch a single batch of account IDs.\n *\n * @param accountIds - Batch of account IDs to fetch\n * @returns Promise resolving to the active networks response for this batch\n * @throws Error if the response format is invalid or the request fails\n */\n async #fetchNetworkActivityBatch(\n accountIds: CaipAccountId[],\n ): Promise<ActiveNetworksResponse> {\n try {\n const url = buildActiveNetworksUrl(accountIds);\n\n const response = await this.#fetch(url.toString(), {\n method: 'GET',\n headers: {\n [MULTICHAIN_ACCOUNTS_CLIENT_HEADER]: MULTICHAIN_ACCOUNTS_CLIENT_ID,\n Accept: 'application/json',\n },\n });\n\n if (!response.ok) {\n throw new Error(`HTTP error! status: ${response.status}`);\n }\n\n const data: unknown = await response.json();\n\n assert(data, ActiveNetworksResponseStruct);\n return data;\n } catch (error) {\n if (error instanceof Error) {\n if (error.name === 'AbortError') {\n throw new Error('Request timeout: Failed to fetch active networks');\n }\n throw error;\n }\n\n throw new Error(`Failed to fetch active networks: ${String(error)}`);\n }\n }\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { CaipAccountId } from
|
|
2
|
-
import type { ActiveNetworksResponse } from
|
|
1
|
+
import type { CaipAccountId } from "@metamask/utils";
|
|
2
|
+
import type { ActiveNetworksResponse } from "../api/accounts-api.cjs";
|
|
3
3
|
/**
|
|
4
4
|
* Service responsible for fetching network activity data from the API.
|
|
5
5
|
*/
|
|
@@ -19,4 +19,4 @@ export declare class MultichainNetworkService {
|
|
|
19
19
|
*/
|
|
20
20
|
fetchNetworkActivity(accountIds: CaipAccountId[]): Promise<ActiveNetworksResponse>;
|
|
21
21
|
}
|
|
22
|
-
//# sourceMappingURL=MultichainNetworkService.d.
|
|
22
|
+
//# sourceMappingURL=MultichainNetworkService.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MultichainNetworkService.d.cts","sourceRoot":"","sources":["../../src/MultichainNetworkService/MultichainNetworkService.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,wBAAwB;AASrD,OAAO,KAAK,EAAE,sBAAsB,EAAE,gCAA+B;AAErE;;GAEG;AACH,qBAAa,wBAAwB;;gBAKvB,EACV,KAAK,EAAE,aAAa,EACpB,SAAS,GACV,EAAE;QACD,KAAK,EAAE,OAAO,KAAK,CAAC;QACpB,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB;IAKD;;;;;;;OAOG;IACG,oBAAoB,CACxB,UAAU,EAAE,aAAa,EAAE,GAC1B,OAAO,CAAC,sBAAsB,CAAC;CA+DnC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { CaipAccountId } from "@metamask/utils";
|
|
2
|
+
import type { ActiveNetworksResponse } from "../api/accounts-api.mjs";
|
|
3
|
+
/**
|
|
4
|
+
* Service responsible for fetching network activity data from the API.
|
|
5
|
+
*/
|
|
6
|
+
export declare class MultichainNetworkService {
|
|
7
|
+
#private;
|
|
8
|
+
constructor({ fetch: fetchFunction, batchSize, }: {
|
|
9
|
+
fetch: typeof fetch;
|
|
10
|
+
batchSize?: number;
|
|
11
|
+
});
|
|
12
|
+
/**
|
|
13
|
+
* Fetches active networks for the given account IDs.
|
|
14
|
+
* Automatically handles batching requests to comply with URL length limitations.
|
|
15
|
+
*
|
|
16
|
+
* @param accountIds - Array of CAIP-10 account IDs to fetch activity for.
|
|
17
|
+
* @returns Promise resolving to the combined active networks response.
|
|
18
|
+
* @throws Error if the response format is invalid or the request fails.
|
|
19
|
+
*/
|
|
20
|
+
fetchNetworkActivity(accountIds: CaipAccountId[]): Promise<ActiveNetworksResponse>;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=MultichainNetworkService.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MultichainNetworkService.d.mts","sourceRoot":"","sources":["../../src/MultichainNetworkService/MultichainNetworkService.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,wBAAwB;AASrD,OAAO,KAAK,EAAE,sBAAsB,EAAE,gCAA+B;AAErE;;GAEG;AACH,qBAAa,wBAAwB;;gBAKvB,EACV,KAAK,EAAE,aAAa,EACpB,SAAS,GACV,EAAE;QACD,KAAK,EAAE,OAAO,KAAK,CAAC;QACpB,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB;IAKD;;;;;;;OAOG;IACG,oBAAoB,CACxB,UAAU,EAAE,aAAa,EAAE,GAC1B,OAAO,CAAC,sBAAsB,CAAC;CA+DnC"}
|
package/dist/MultichainNetworkService/{MultichainNetworkService.js → MultichainNetworkService.mjs}
RENAMED
|
@@ -10,9 +10,10 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
12
|
var _MultichainNetworkService_instances, _MultichainNetworkService_fetch, _MultichainNetworkService_batchSize, _MultichainNetworkService_fetchNetworkActivityBatch;
|
|
13
|
-
import { assert } from
|
|
14
|
-
import
|
|
15
|
-
|
|
13
|
+
import { assert } from "@metamask/superstruct";
|
|
14
|
+
import $lodash from "lodash";
|
|
15
|
+
const { chunk } = $lodash;
|
|
16
|
+
import { ActiveNetworksResponseStruct, buildActiveNetworksUrl, MULTICHAIN_ACCOUNTS_CLIENT_HEADER, MULTICHAIN_ACCOUNTS_CLIENT_ID } from "../api/accounts-api.mjs";
|
|
16
17
|
/**
|
|
17
18
|
* Service responsible for fetching network activity data from the API.
|
|
18
19
|
*/
|
|
@@ -82,4 +83,4 @@ async function _MultichainNetworkService_fetchNetworkActivityBatch(accountIds) {
|
|
|
82
83
|
throw new Error(`Failed to fetch active networks: ${String(error)}`);
|
|
83
84
|
}
|
|
84
85
|
};
|
|
85
|
-
//# sourceMappingURL=MultichainNetworkService.
|
|
86
|
+
//# sourceMappingURL=MultichainNetworkService.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MultichainNetworkService.mjs","sourceRoot":"","sources":["../../src/MultichainNetworkService/MultichainNetworkService.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,8BAA8B;;;AAI/C,OAAO,EACL,4BAA4B,EAC5B,sBAAsB,EACtB,iCAAiC,EACjC,6BAA6B,EAC9B,gCAA+B;AAGhC;;GAEG;AACH,MAAM,OAAO,wBAAwB;IAKnC,YAAY,EACV,KAAK,EAAE,aAAa,EACpB,SAAS,GAIV;;QAVQ,kDAAqB;QAErB,sDAAmB;QAS1B,uBAAA,IAAI,mCAAU,aAAa,MAAA,CAAC;QAC5B,uBAAA,IAAI,uCAAc,SAAS,IAAI,EAAE,MAAA,CAAC;IACpC,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,oBAAoB,CACxB,UAA2B;QAE3B,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC5B,OAAO,EAAE,cAAc,EAAE,EAAE,EAAE,CAAC;QAChC,CAAC;QAED,IAAI,UAAU,CAAC,MAAM,IAAI,uBAAA,IAAI,2CAAW,EAAE,CAAC;YACzC,OAAO,uBAAA,IAAI,gGAA2B,MAA/B,IAAI,EAA4B,UAAU,CAAC,CAAC;QACrD,CAAC;QAED,MAAM,OAAO,GAAG,KAAK,CAAC,UAAU,EAAE,uBAAA,IAAI,2CAAW,CAAC,CAAC;QACnD,MAAM,YAAY,GAAG,MAAM,OAAO,CAAC,GAAG,CACpC,O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,CAAC,EAAE,CAAC,CAAC;IACvE,CAAC;AACH,CAAC","sourcesContent":["import { assert } from '@metamask/superstruct';\nimport type { CaipAccountId } from '@metamask/utils';\nimport { chunk } from 'lodash';\n\nimport {\n ActiveNetworksResponseStruct,\n buildActiveNetworksUrl,\n MULTICHAIN_ACCOUNTS_CLIENT_HEADER,\n MULTICHAIN_ACCOUNTS_CLIENT_ID,\n} from '../api/accounts-api.js';\nimport type { ActiveNetworksResponse } from '../api/accounts-api.js';\n\n/**\n * Service responsible for fetching network activity data from the API.\n */\nexport class MultichainNetworkService {\n readonly #fetch: typeof fetch;\n\n readonly #batchSize: number;\n\n constructor({\n fetch: fetchFunction,\n batchSize,\n }: {\n fetch: typeof fetch;\n batchSize?: number;\n }) {\n this.#fetch = fetchFunction;\n this.#batchSize = batchSize ?? 20;\n }\n\n /**\n * Fetches active networks for the given account IDs.\n * Automatically handles batching requests to comply with URL length limitations.\n *\n * @param accountIds - Array of CAIP-10 account IDs to fetch activity for.\n * @returns Promise resolving to the combined active networks response.\n * @throws Error if the response format is invalid or the request fails.\n */\n async fetchNetworkActivity(\n accountIds: CaipAccountId[],\n ): Promise<ActiveNetworksResponse> {\n if (accountIds.length === 0) {\n return { activeNetworks: [] };\n }\n\n if (accountIds.length <= this.#batchSize) {\n return this.#fetchNetworkActivityBatch(accountIds);\n }\n\n const batches = chunk(accountIds, this.#batchSize);\n const batchResults = await Promise.all(\n batches.map((batch) => this.#fetchNetworkActivityBatch(batch)),\n );\n\n const combinedResponse: ActiveNetworksResponse = {\n activeNetworks: batchResults.flatMap(\n (response) => response.activeNetworks,\n ),\n };\n\n return combinedResponse;\n }\n\n /**\n * Internal method to fetch a single batch of account IDs.\n *\n * @param accountIds - Batch of account IDs to fetch\n * @returns Promise resolving to the active networks response for this batch\n * @throws Error if the response format is invalid or the request fails\n */\n async #fetchNetworkActivityBatch(\n accountIds: CaipAccountId[],\n ): Promise<ActiveNetworksResponse> {\n try {\n const url = buildActiveNetworksUrl(accountIds);\n\n const response = await this.#fetch(url.toString(), {\n method: 'GET',\n headers: {\n [MULTICHAIN_ACCOUNTS_CLIENT_HEADER]: MULTICHAIN_ACCOUNTS_CLIENT_ID,\n Accept: 'application/json',\n },\n });\n\n if (!response.ok) {\n throw new Error(`HTTP error! status: ${response.status}`);\n }\n\n const data: unknown = await response.json();\n\n assert(data, ActiveNetworksResponseStruct);\n return data;\n } catch (error) {\n if (error instanceof Error) {\n if (error.name === 'AbortError') {\n throw new Error('Request timeout: Failed to fetch active networks');\n }\n throw error;\n }\n\n throw new Error(`Failed to fetch active networks: ${String(error)}`);\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildActiveNetworksUrl = exports.toActiveNetworksByAddress = exports.toAllowedCaipAccountIds = exports.MULTICHAIN_ALLOWED_ACTIVE_NETWORK_SCOPES = exports.MULTICHAIN_ACCOUNTS_CLIENT_ID = exports.MULTICHAIN_ACCOUNTS_CLIENT_HEADER = exports.MULTICHAIN_ACCOUNTS_BASE_URL = exports.ActiveNetworksResponseStruct = void 0;
|
|
4
|
+
const keyring_api_1 = require("@metamask/keyring-api");
|
|
5
|
+
const superstruct_1 = require("@metamask/superstruct");
|
|
6
|
+
const utils_1 = require("@metamask/utils");
|
|
7
|
+
exports.ActiveNetworksResponseStruct = (0, superstruct_1.object)({
|
|
8
|
+
activeNetworks: (0, superstruct_1.array)(utils_1.CaipAccountIdStruct),
|
|
9
|
+
});
|
|
10
|
+
/**
|
|
11
|
+
* The domain for multichain accounts API.
|
|
12
|
+
*/
|
|
13
|
+
exports.MULTICHAIN_ACCOUNTS_BASE_URL = 'https://accounts.api.cx.metamask.io';
|
|
14
|
+
/**
|
|
15
|
+
* The client header for the multichain accounts API.
|
|
16
|
+
*/
|
|
17
|
+
exports.MULTICHAIN_ACCOUNTS_CLIENT_HEADER = 'x-metamask-clientproduct';
|
|
18
|
+
/**
|
|
19
|
+
* The client ID for the multichain accounts API.
|
|
20
|
+
*/
|
|
21
|
+
exports.MULTICHAIN_ACCOUNTS_CLIENT_ID = 'metamask-multichain-network-controller';
|
|
22
|
+
/**
|
|
23
|
+
* The allowed active network scopes for the multichain network controller.
|
|
24
|
+
*/
|
|
25
|
+
exports.MULTICHAIN_ALLOWED_ACTIVE_NETWORK_SCOPES = [
|
|
26
|
+
String(keyring_api_1.BtcScope.Mainnet),
|
|
27
|
+
String(keyring_api_1.BtcScope.Testnet),
|
|
28
|
+
String(keyring_api_1.BtcScope.Testnet4),
|
|
29
|
+
String(keyring_api_1.BtcScope.Signet),
|
|
30
|
+
String(keyring_api_1.BtcScope.Regtest),
|
|
31
|
+
String(keyring_api_1.SolScope.Mainnet),
|
|
32
|
+
String(keyring_api_1.SolScope.Devnet),
|
|
33
|
+
String(keyring_api_1.EthScope.Mainnet),
|
|
34
|
+
String(keyring_api_1.EthScope.Testnet),
|
|
35
|
+
String(keyring_api_1.EthScope.Eoa),
|
|
36
|
+
String(keyring_api_1.TrxScope.Mainnet),
|
|
37
|
+
String(keyring_api_1.TrxScope.Nile),
|
|
38
|
+
String(keyring_api_1.TrxScope.Shasta),
|
|
39
|
+
];
|
|
40
|
+
/**
|
|
41
|
+
* Converts an internal account to an array of CAIP-10 account IDs.
|
|
42
|
+
*
|
|
43
|
+
* @param account - The internal account to convert
|
|
44
|
+
* @returns The CAIP-10 account IDs
|
|
45
|
+
*/
|
|
46
|
+
function toAllowedCaipAccountIds(account) {
|
|
47
|
+
const formattedAccounts = [];
|
|
48
|
+
for (const scope of account.scopes) {
|
|
49
|
+
if (exports.MULTICHAIN_ALLOWED_ACTIVE_NETWORK_SCOPES.includes(scope)) {
|
|
50
|
+
formattedAccounts.push(`${scope}:${account.address}`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return formattedAccounts;
|
|
54
|
+
}
|
|
55
|
+
exports.toAllowedCaipAccountIds = toAllowedCaipAccountIds;
|
|
56
|
+
/**
|
|
57
|
+
* Formats the API response into our state structure.
|
|
58
|
+
* Example input: ["eip155:1:0x123...", "eip155:137:0x123...", "solana:1:0xabc..."]
|
|
59
|
+
*
|
|
60
|
+
* @param response - The raw API response
|
|
61
|
+
* @returns Formatted networks by address
|
|
62
|
+
*/
|
|
63
|
+
function toActiveNetworksByAddress(response) {
|
|
64
|
+
const networksByAddress = {};
|
|
65
|
+
response.activeNetworks.forEach((network) => {
|
|
66
|
+
const { address, chain: { namespace, reference }, } = (0, utils_1.parseCaipAccountId)(network);
|
|
67
|
+
if (!networksByAddress[address]) {
|
|
68
|
+
networksByAddress[address] = {
|
|
69
|
+
namespace,
|
|
70
|
+
activeChains: [],
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
networksByAddress[address].activeChains.push(reference);
|
|
74
|
+
});
|
|
75
|
+
return networksByAddress;
|
|
76
|
+
}
|
|
77
|
+
exports.toActiveNetworksByAddress = toActiveNetworksByAddress;
|
|
78
|
+
/**
|
|
79
|
+
* Constructs the URL for the active networks API endpoint.
|
|
80
|
+
*
|
|
81
|
+
* @param accountIds - Array of account IDs
|
|
82
|
+
* @returns URL object for the API endpoint
|
|
83
|
+
*/
|
|
84
|
+
function buildActiveNetworksUrl(accountIds) {
|
|
85
|
+
const url = new URL(`${exports.MULTICHAIN_ACCOUNTS_BASE_URL}/v2/activeNetworks`);
|
|
86
|
+
url.searchParams.append('accountIds', accountIds.join(','));
|
|
87
|
+
return url;
|
|
88
|
+
}
|
|
89
|
+
exports.buildActiveNetworksUrl = buildActiveNetworksUrl;
|
|
90
|
+
//# sourceMappingURL=accounts-api.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accounts-api.cjs","sourceRoot":"","sources":["../../src/api/accounts-api.ts"],"names":[],"mappings":";;;AAAA,uDAA+E;AAE/E,uDAAsD;AAEtD,2CAA0E;AAQ7D,QAAA,4BAA4B,GAAG,IAAA,oBAAM,EAAC;IACjD,cAA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AAED;;;;;;GAMG;AACH,SAAgB,yBAAyB,CACvC,QAAgC;IAEhC,MAAM,iBAAiB,GAA4B,EAAE,CAAC;IAEtD,QAAQ,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC1C,MAAM,EACJ,OAAO,EACP,KAAK,EAAE,EAAE,SAAS,EAAE,SAAS,EAAE,GAChC,GAAG,IAAA,0BAAkB,EAAC,OAAO,CAAC,CAAC;QAEhC,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAC,EAAE,CAAC;YAChC,iBAAiB,CAAC,OAAO,CAAC,GAAG;gBAC3B,SAAS;gBACT,YAAY,EAAE,EAAE;aACjB,CAAC;QACJ,CAAC;QACD,iBAAiB,CAAC,OAAO,CAAC,CAAC,YAAY,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IAC1D,CAAC,CAAC,CAAC;IAEH,OAAO,iBAAiB,CAAC;AAC3B,CAAC;AArBD,8DAqBC;AAED;;;;;GAKG;AACH,SAAgB,sBAAsB,CAAC,UAA2B;IAChE,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,GAAG,oCAA4B,oBAAoB,CAAC,CAAC;IACzE,GAAG,CAAC,YAAY,CAAC,MAAM,CAAC,YAAY,EAAE,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IAC5D,OAAO,GAAG,CAAC;AACb,CAAC;AAJD,wDAIC","sourcesContent":["import { BtcScope, SolScope, EthScope, TrxScope } from '@metamask/keyring-api';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport { array, object } from '@metamask/superstruct';\nimport type { Infer } from '@metamask/superstruct';\nimport { CaipAccountIdStruct, parseCaipAccountId } from '@metamask/utils';\nimport type {\n CaipAccountAddress,\n CaipAccountId,\n CaipNamespace,\n CaipReference,\n} from '@metamask/utils';\n\nexport const ActiveNetworksResponseStruct = object({\n activeNetworks: array(CaipAccountIdStruct),\n});\n\nexport type ActiveNetworksResponse = Infer<typeof ActiveNetworksResponseStruct>;\n\n/**\n * The active networks for the currently selected account.\n */\nexport type ActiveNetworksByAddress = Record<\n CaipAccountAddress,\n {\n // CAIP-2 namespace of the network.\n namespace: CaipNamespace;\n // Active chain IDs (CAIP-2 references) on that network (primarily used for EVM networks).\n activeChains: CaipReference[];\n }\n>;\n\n/**\n * The domain for multichain accounts API.\n */\nexport const MULTICHAIN_ACCOUNTS_BASE_URL =\n 'https://accounts.api.cx.metamask.io';\n\n/**\n * The client header for the multichain accounts API.\n */\nexport const MULTICHAIN_ACCOUNTS_CLIENT_HEADER = 'x-metamask-clientproduct';\n\n/**\n * The client ID for the multichain accounts API.\n */\nexport const MULTICHAIN_ACCOUNTS_CLIENT_ID =\n 'metamask-multichain-network-controller';\n\n/**\n * The allowed active network scopes for the multichain network controller.\n */\nexport const MULTICHAIN_ALLOWED_ACTIVE_NETWORK_SCOPES = [\n String(BtcScope.Mainnet),\n String(BtcScope.Testnet),\n String(BtcScope.Testnet4),\n String(BtcScope.Signet),\n String(BtcScope.Regtest),\n String(SolScope.Mainnet),\n String(SolScope.Devnet),\n String(EthScope.Mainnet),\n String(EthScope.Testnet),\n String(EthScope.Eoa),\n String(TrxScope.Mainnet),\n String(TrxScope.Nile),\n String(TrxScope.Shasta),\n];\n\n/**\n * Converts an internal account to an array of CAIP-10 account IDs.\n *\n * @param account - The internal account to convert\n * @returns The CAIP-10 account IDs\n */\nexport function toAllowedCaipAccountIds(\n account: InternalAccount,\n): CaipAccountId[] {\n const formattedAccounts: CaipAccountId[] = [];\n for (const scope of account.scopes) {\n if (MULTICHAIN_ALLOWED_ACTIVE_NETWORK_SCOPES.includes(scope)) {\n formattedAccounts.push(`${scope}:${account.address}`);\n }\n }\n\n return formattedAccounts;\n}\n\n/**\n * Formats the API response into our state structure.\n * Example input: [\"eip155:1:0x123...\", \"eip155:137:0x123...\", \"solana:1:0xabc...\"]\n *\n * @param response - The raw API response\n * @returns Formatted networks by address\n */\nexport function toActiveNetworksByAddress(\n response: ActiveNetworksResponse,\n): ActiveNetworksByAddress {\n const networksByAddress: ActiveNetworksByAddress = {};\n\n response.activeNetworks.forEach((network) => {\n const {\n address,\n chain: { namespace, reference },\n } = parseCaipAccountId(network);\n\n if (!networksByAddress[address]) {\n networksByAddress[address] = {\n namespace,\n activeChains: [],\n };\n }\n networksByAddress[address].activeChains.push(reference);\n });\n\n return networksByAddress;\n}\n\n/**\n * Constructs the URL for the active networks API endpoint.\n *\n * @param accountIds - Array of account IDs\n * @returns URL object for the API endpoint\n */\nexport function buildActiveNetworksUrl(accountIds: CaipAccountId[]): URL {\n const url = new URL(`${MULTICHAIN_ACCOUNTS_BASE_URL}/v2/activeNetworks`);\n url.searchParams.append('accountIds', accountIds.join(','));\n return url;\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { InternalAccount } from
|
|
2
|
-
import type { Infer } from
|
|
3
|
-
import type { CaipAccountAddress, CaipAccountId, CaipNamespace, CaipReference } from
|
|
1
|
+
import type { InternalAccount } from "@metamask/keyring-internal-api";
|
|
2
|
+
import type { Infer } from "@metamask/superstruct";
|
|
3
|
+
import type { CaipAccountAddress, CaipAccountId, CaipNamespace, CaipReference } from "@metamask/utils";
|
|
4
4
|
export declare const ActiveNetworksResponseStruct: import("@metamask/superstruct").Struct<{
|
|
5
5
|
activeNetworks: `${string}:${string}:${string}`[];
|
|
6
6
|
}, {
|
|
@@ -52,4 +52,4 @@ export declare function toActiveNetworksByAddress(response: ActiveNetworksRespon
|
|
|
52
52
|
* @returns URL object for the API endpoint
|
|
53
53
|
*/
|
|
54
54
|
export declare function buildActiveNetworksUrl(accountIds: CaipAccountId[]): URL;
|
|
55
|
-
//# sourceMappingURL=accounts-api.d.
|
|
55
|
+
//# sourceMappingURL=accounts-api.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accounts-api.d.cts","sourceRoot":"","sources":["../../src/api/accounts-api.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AAEtE,OAAO,KAAK,EAAE,KAAK,EAAE,8BAA8B;AAEnD,OAAO,KAAK,EACV,kBAAkB,EAClB,aAAa,EACb,aAAa,EACb,aAAa,EACd,wBAAwB;AAEzB,eAAO,MAAM,4BAA4B;;;;EAEvC,CAAC;AAEH,MAAM,MAAM,sBAAsB,GAAG,KAAK,CAAC,OAAO,4BAA4B,CAAC,CAAC;AAEhF;;GAEG;AACH,MAAM,MAAM,uBAAuB,GAAG,MAAM,CAC1C,kBAAkB,EAClB;IAEE,SAAS,EAAE,aAAa,CAAC;IAEzB,YAAY,EAAE,aAAa,EAAE,CAAC;CAC/B,CACF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,4BAA4B,wCACF,CAAC;AAExC;;GAEG;AACH,eAAO,MAAM,iCAAiC,6BAA6B,CAAC;AAE5E;;GAEG;AACH,eAAO,MAAM,6BAA6B,2CACA,CAAC;AAE3C;;GAEG;AACH,eAAO,MAAM,wCAAwC,UAcpD,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,eAAe,GACvB,aAAa,EAAE,CASjB;AAED;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CACvC,QAAQ,EAAE,sBAAsB,GAC/B,uBAAuB,CAmBzB;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,UAAU,EAAE,aAAa,EAAE,GAAG,GAAG,CAIvE"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { InternalAccount } from "@metamask/keyring-internal-api";
|
|
2
|
+
import type { Infer } from "@metamask/superstruct";
|
|
3
|
+
import type { CaipAccountAddress, CaipAccountId, CaipNamespace, CaipReference } from "@metamask/utils";
|
|
4
|
+
export declare const ActiveNetworksResponseStruct: import("@metamask/superstruct").Struct<{
|
|
5
|
+
activeNetworks: `${string}:${string}:${string}`[];
|
|
6
|
+
}, {
|
|
7
|
+
activeNetworks: import("@metamask/superstruct").Struct<`${string}:${string}:${string}`[], import("@metamask/superstruct").Struct<`${string}:${string}:${string}`, null>>;
|
|
8
|
+
}>;
|
|
9
|
+
export type ActiveNetworksResponse = Infer<typeof ActiveNetworksResponseStruct>;
|
|
10
|
+
/**
|
|
11
|
+
* The active networks for the currently selected account.
|
|
12
|
+
*/
|
|
13
|
+
export type ActiveNetworksByAddress = Record<CaipAccountAddress, {
|
|
14
|
+
namespace: CaipNamespace;
|
|
15
|
+
activeChains: CaipReference[];
|
|
16
|
+
}>;
|
|
17
|
+
/**
|
|
18
|
+
* The domain for multichain accounts API.
|
|
19
|
+
*/
|
|
20
|
+
export declare const MULTICHAIN_ACCOUNTS_BASE_URL = "https://accounts.api.cx.metamask.io";
|
|
21
|
+
/**
|
|
22
|
+
* The client header for the multichain accounts API.
|
|
23
|
+
*/
|
|
24
|
+
export declare const MULTICHAIN_ACCOUNTS_CLIENT_HEADER = "x-metamask-clientproduct";
|
|
25
|
+
/**
|
|
26
|
+
* The client ID for the multichain accounts API.
|
|
27
|
+
*/
|
|
28
|
+
export declare const MULTICHAIN_ACCOUNTS_CLIENT_ID = "metamask-multichain-network-controller";
|
|
29
|
+
/**
|
|
30
|
+
* The allowed active network scopes for the multichain network controller.
|
|
31
|
+
*/
|
|
32
|
+
export declare const MULTICHAIN_ALLOWED_ACTIVE_NETWORK_SCOPES: string[];
|
|
33
|
+
/**
|
|
34
|
+
* Converts an internal account to an array of CAIP-10 account IDs.
|
|
35
|
+
*
|
|
36
|
+
* @param account - The internal account to convert
|
|
37
|
+
* @returns The CAIP-10 account IDs
|
|
38
|
+
*/
|
|
39
|
+
export declare function toAllowedCaipAccountIds(account: InternalAccount): CaipAccountId[];
|
|
40
|
+
/**
|
|
41
|
+
* Formats the API response into our state structure.
|
|
42
|
+
* Example input: ["eip155:1:0x123...", "eip155:137:0x123...", "solana:1:0xabc..."]
|
|
43
|
+
*
|
|
44
|
+
* @param response - The raw API response
|
|
45
|
+
* @returns Formatted networks by address
|
|
46
|
+
*/
|
|
47
|
+
export declare function toActiveNetworksByAddress(response: ActiveNetworksResponse): ActiveNetworksByAddress;
|
|
48
|
+
/**
|
|
49
|
+
* Constructs the URL for the active networks API endpoint.
|
|
50
|
+
*
|
|
51
|
+
* @param accountIds - Array of account IDs
|
|
52
|
+
* @returns URL object for the API endpoint
|
|
53
|
+
*/
|
|
54
|
+
export declare function buildActiveNetworksUrl(accountIds: CaipAccountId[]): URL;
|
|
55
|
+
//# sourceMappingURL=accounts-api.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accounts-api.d.mts","sourceRoot":"","sources":["../../src/api/accounts-api.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AAEtE,OAAO,KAAK,EAAE,KAAK,EAAE,8BAA8B;AAEnD,OAAO,KAAK,EACV,kBAAkB,EAClB,aAAa,EACb,aAAa,EACb,aAAa,EACd,wBAAwB;AAEzB,eAAO,MAAM,4BAA4B;;;;EAEvC,CAAC;AAEH,MAAM,MAAM,sBAAsB,GAAG,KAAK,CAAC,OAAO,4BAA4B,CAAC,CAAC;AAEhF;;GAEG;AACH,MAAM,MAAM,uBAAuB,GAAG,MAAM,CAC1C,kBAAkB,EAClB;IAEE,SAAS,EAAE,aAAa,CAAC;IAEzB,YAAY,EAAE,aAAa,EAAE,CAAC;CAC/B,CACF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,4BAA4B,wCACF,CAAC;AAExC;;GAEG;AACH,eAAO,MAAM,iCAAiC,6BAA6B,CAAC;AAE5E;;GAEG;AACH,eAAO,MAAM,6BAA6B,2CACA,CAAC;AAE3C;;GAEG;AACH,eAAO,MAAM,wCAAwC,UAcpD,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,eAAe,GACvB,aAAa,EAAE,CASjB;AAED;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CACvC,QAAQ,EAAE,sBAAsB,GAC/B,uBAAuB,CAmBzB;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,UAAU,EAAE,aAAa,EAAE,GAAG,GAAG,CAIvE"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { BtcScope, SolScope, EthScope, TrxScope } from
|
|
2
|
-
import { array, object } from
|
|
3
|
-
import { CaipAccountIdStruct, parseCaipAccountId } from
|
|
1
|
+
import { BtcScope, SolScope, EthScope, TrxScope } from "@metamask/keyring-api";
|
|
2
|
+
import { array, object } from "@metamask/superstruct";
|
|
3
|
+
import { CaipAccountIdStruct, parseCaipAccountId } from "@metamask/utils";
|
|
4
4
|
export const ActiveNetworksResponseStruct = object({
|
|
5
5
|
activeNetworks: array(CaipAccountIdStruct),
|
|
6
6
|
});
|
|
@@ -81,4 +81,4 @@ export function buildActiveNetworksUrl(accountIds) {
|
|
|
81
81
|
url.searchParams.append('accountIds', accountIds.join(','));
|
|
82
82
|
return url;
|
|
83
83
|
}
|
|
84
|
-
//# sourceMappingURL=accounts-api.
|
|
84
|
+
//# sourceMappingURL=accounts-api.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accounts-api.mjs","sourceRoot":"","sources":["../../src/api/accounts-api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,8BAA8B;AAE/E,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,8BAA8B;AAEtD,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,wBAAwB;AAQ1E,MAAM,CAAC,MAAM,4BAA4B,GAAG,MAAM,CAAC;IACjD,cAAc,EAAE,KAAK,CAAC,mBAAmB,CAAC;CAC3C,CAAC,CAAC;AAiBH;;GAEG;AACH,MAAM,CAAC,MAAM,4BAA4B,GACvC,qCAAqC,CAAC;AAExC;;GAEG;AACH,MAAM,CAAC,MAAM,iCAAiC,GAAG,0BAA0B,CAAC;AAE5E;;GAEG;AACH,MAAM,CAA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AK,EAAE,EAAE,SAAS,EAAE,SAAS,EAAE,GAChC,GAAG,kBAAkB,CAAC,OAAO,CAAC,CAAC;QAEhC,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAC,EAAE,CAAC;YAChC,iBAAiB,CAAC,OAAO,CAAC,GAAG;gBAC3B,SAAS;gBACT,YAAY,EAAE,EAAE;aACjB,CAAC;QACJ,CAAC;QACD,iBAAiB,CAAC,OAAO,CAAC,CAAC,YAAY,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IAC1D,CAAC,CAAC,CAAC;IAEH,OAAO,iBAAiB,CAAC;AAC3B,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,sBAAsB,CAAC,UAA2B;IAChE,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,GAAG,4BAA4B,oBAAoB,CAAC,CAAC;IACzE,GAAG,CAAC,YAAY,CAAC,MAAM,CAAC,YAAY,EAAE,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IAC5D,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["import { BtcScope, SolScope, EthScope, TrxScope } from '@metamask/keyring-api';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport { array, object } from '@metamask/superstruct';\nimport type { Infer } from '@metamask/superstruct';\nimport { CaipAccountIdStruct, parseCaipAccountId } from '@metamask/utils';\nimport type {\n CaipAccountAddress,\n CaipAccountId,\n CaipNamespace,\n CaipReference,\n} from '@metamask/utils';\n\nexport const ActiveNetworksResponseStruct = object({\n activeNetworks: array(CaipAccountIdStruct),\n});\n\nexport type ActiveNetworksResponse = Infer<typeof ActiveNetworksResponseStruct>;\n\n/**\n * The active networks for the currently selected account.\n */\nexport type ActiveNetworksByAddress = Record<\n CaipAccountAddress,\n {\n // CAIP-2 namespace of the network.\n namespace: CaipNamespace;\n // Active chain IDs (CAIP-2 references) on that network (primarily used for EVM networks).\n activeChains: CaipReference[];\n }\n>;\n\n/**\n * The domain for multichain accounts API.\n */\nexport const MULTICHAIN_ACCOUNTS_BASE_URL =\n 'https://accounts.api.cx.metamask.io';\n\n/**\n * The client header for the multichain accounts API.\n */\nexport const MULTICHAIN_ACCOUNTS_CLIENT_HEADER = 'x-metamask-clientproduct';\n\n/**\n * The client ID for the multichain accounts API.\n */\nexport const MULTICHAIN_ACCOUNTS_CLIENT_ID =\n 'metamask-multichain-network-controller';\n\n/**\n * The allowed active network scopes for the multichain network controller.\n */\nexport const MULTICHAIN_ALLOWED_ACTIVE_NETWORK_SCOPES = [\n String(BtcScope.Mainnet),\n String(BtcScope.Testnet),\n String(BtcScope.Testnet4),\n String(BtcScope.Signet),\n String(BtcScope.Regtest),\n String(SolScope.Mainnet),\n String(SolScope.Devnet),\n String(EthScope.Mainnet),\n String(EthScope.Testnet),\n String(EthScope.Eoa),\n String(TrxScope.Mainnet),\n String(TrxScope.Nile),\n String(TrxScope.Shasta),\n];\n\n/**\n * Converts an internal account to an array of CAIP-10 account IDs.\n *\n * @param account - The internal account to convert\n * @returns The CAIP-10 account IDs\n */\nexport function toAllowedCaipAccountIds(\n account: InternalAccount,\n): CaipAccountId[] {\n const formattedAccounts: CaipAccountId[] = [];\n for (const scope of account.scopes) {\n if (MULTICHAIN_ALLOWED_ACTIVE_NETWORK_SCOPES.includes(scope)) {\n formattedAccounts.push(`${scope}:${account.address}`);\n }\n }\n\n return formattedAccounts;\n}\n\n/**\n * Formats the API response into our state structure.\n * Example input: [\"eip155:1:0x123...\", \"eip155:137:0x123...\", \"solana:1:0xabc...\"]\n *\n * @param response - The raw API response\n * @returns Formatted networks by address\n */\nexport function toActiveNetworksByAddress(\n response: ActiveNetworksResponse,\n): ActiveNetworksByAddress {\n const networksByAddress: ActiveNetworksByAddress = {};\n\n response.activeNetworks.forEach((network) => {\n const {\n address,\n chain: { namespace, reference },\n } = parseCaipAccountId(network);\n\n if (!networksByAddress[address]) {\n networksByAddress[address] = {\n namespace,\n activeChains: [],\n };\n }\n networksByAddress[address].activeChains.push(reference);\n });\n\n return networksByAddress;\n}\n\n/**\n * Constructs the URL for the active networks API endpoint.\n *\n * @param accountIds - Array of account IDs\n * @returns URL object for the API endpoint\n */\nexport function buildActiveNetworksUrl(accountIds: CaipAccountId[]): URL {\n const url = new URL(`${MULTICHAIN_ACCOUNTS_BASE_URL}/v2/activeNetworks`);\n url.searchParams.append('accountIds', accountIds.join(','));\n return url;\n}\n"]}
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MULTICHAIN_NETWORK_DECIMAL_PLACES = exports.MULTICHAIN_NETWORK_TICKER = exports.MULTICHAIN_NETWORK_CONTROLLER_METADATA = exports.getDefaultMultichainNetworkControllerState = exports.NETWORKS_METADATA = exports.NON_EVM_TESTNET_IDS = exports.AVAILABLE_MULTICHAIN_NETWORK_CONFIGURATIONS = exports.XLM_TESTNET_NATIVE_ASSET = exports.XLM_NATIVE_ASSET = exports.TRX_SHASTA_NATIVE_ASSET = exports.TRX_NILE_NATIVE_ASSET = exports.TRX_NATIVE_ASSET = exports.SOL_DEVNET_NATIVE_ASSET = exports.SOL_TESTNET_NATIVE_ASSET = exports.SOL_NATIVE_ASSET = exports.BTC_REGTEST_NATIVE_ASSET = exports.BTC_SIGNET_NATIVE_ASSET = exports.BTC_TESTNET4_NATIVE_ASSET = exports.BTC_TESTNET_NATIVE_ASSET = exports.BTC_NATIVE_ASSET = void 0;
|
|
4
|
+
const keyring_api_1 = require("@metamask/keyring-api");
|
|
5
|
+
const network_controller_1 = require("@metamask/network-controller");
|
|
6
|
+
exports.BTC_NATIVE_ASSET = `${keyring_api_1.BtcScope.Mainnet}/slip44:0`;
|
|
7
|
+
exports.BTC_TESTNET_NATIVE_ASSET = `${keyring_api_1.BtcScope.Testnet}/slip44:0`;
|
|
8
|
+
exports.BTC_TESTNET4_NATIVE_ASSET = `${keyring_api_1.BtcScope.Testnet4}/slip44:0`;
|
|
9
|
+
exports.BTC_SIGNET_NATIVE_ASSET = `${keyring_api_1.BtcScope.Signet}/slip44:0`;
|
|
10
|
+
exports.BTC_REGTEST_NATIVE_ASSET = `${keyring_api_1.BtcScope.Regtest}/slip44:0`;
|
|
11
|
+
exports.SOL_NATIVE_ASSET = `${keyring_api_1.SolScope.Mainnet}/slip44:501`;
|
|
12
|
+
exports.SOL_TESTNET_NATIVE_ASSET = `${keyring_api_1.SolScope.Testnet}/slip44:501`;
|
|
13
|
+
exports.SOL_DEVNET_NATIVE_ASSET = `${keyring_api_1.SolScope.Devnet}/slip44:501`;
|
|
14
|
+
exports.TRX_NATIVE_ASSET = `${keyring_api_1.TrxScope.Mainnet}/slip44:195`;
|
|
15
|
+
exports.TRX_NILE_NATIVE_ASSET = `${keyring_api_1.TrxScope.Nile}/slip44:195`;
|
|
16
|
+
exports.TRX_SHASTA_NATIVE_ASSET = `${keyring_api_1.TrxScope.Shasta}/slip44:195`;
|
|
17
|
+
exports.XLM_NATIVE_ASSET = `${keyring_api_1.XlmScope.Pubnet}/slip44:148`;
|
|
18
|
+
exports.XLM_TESTNET_NATIVE_ASSET = `${keyring_api_1.XlmScope.Testnet}/slip44:148`;
|
|
19
|
+
/**
|
|
20
|
+
* Supported networks by the MultichainNetworkController
|
|
21
|
+
*/
|
|
22
|
+
exports.AVAILABLE_MULTICHAIN_NETWORK_CONFIGURATIONS = {
|
|
23
|
+
[keyring_api_1.BtcScope.Mainnet]: {
|
|
24
|
+
chainId: keyring_api_1.BtcScope.Mainnet,
|
|
25
|
+
name: 'Bitcoin',
|
|
26
|
+
nativeCurrency: exports.BTC_NATIVE_ASSET,
|
|
27
|
+
isEvm: false,
|
|
28
|
+
},
|
|
29
|
+
[keyring_api_1.BtcScope.Testnet]: {
|
|
30
|
+
chainId: keyring_api_1.BtcScope.Testnet,
|
|
31
|
+
name: 'Bitcoin Testnet',
|
|
32
|
+
nativeCurrency: exports.BTC_TESTNET_NATIVE_ASSET,
|
|
33
|
+
isEvm: false,
|
|
34
|
+
},
|
|
35
|
+
[keyring_api_1.BtcScope.Testnet4]: {
|
|
36
|
+
chainId: keyring_api_1.BtcScope.Testnet4,
|
|
37
|
+
name: 'Bitcoin Testnet4',
|
|
38
|
+
nativeCurrency: exports.BTC_TESTNET4_NATIVE_ASSET,
|
|
39
|
+
isEvm: false,
|
|
40
|
+
},
|
|
41
|
+
[keyring_api_1.BtcScope.Signet]: {
|
|
42
|
+
chainId: keyring_api_1.BtcScope.Signet,
|
|
43
|
+
name: 'Bitcoin Mutinynet',
|
|
44
|
+
nativeCurrency: exports.BTC_SIGNET_NATIVE_ASSET,
|
|
45
|
+
isEvm: false,
|
|
46
|
+
},
|
|
47
|
+
[keyring_api_1.BtcScope.Regtest]: {
|
|
48
|
+
chainId: keyring_api_1.BtcScope.Regtest,
|
|
49
|
+
name: 'Bitcoin Regtest',
|
|
50
|
+
nativeCurrency: exports.BTC_REGTEST_NATIVE_ASSET,
|
|
51
|
+
isEvm: false,
|
|
52
|
+
},
|
|
53
|
+
[keyring_api_1.SolScope.Mainnet]: {
|
|
54
|
+
chainId: keyring_api_1.SolScope.Mainnet,
|
|
55
|
+
name: 'Solana',
|
|
56
|
+
nativeCurrency: exports.SOL_NATIVE_ASSET,
|
|
57
|
+
isEvm: false,
|
|
58
|
+
},
|
|
59
|
+
[keyring_api_1.SolScope.Testnet]: {
|
|
60
|
+
chainId: keyring_api_1.SolScope.Testnet,
|
|
61
|
+
name: 'Solana Testnet',
|
|
62
|
+
nativeCurrency: exports.SOL_TESTNET_NATIVE_ASSET,
|
|
63
|
+
isEvm: false,
|
|
64
|
+
},
|
|
65
|
+
[keyring_api_1.SolScope.Devnet]: {
|
|
66
|
+
chainId: keyring_api_1.SolScope.Devnet,
|
|
67
|
+
name: 'Solana Devnet',
|
|
68
|
+
nativeCurrency: exports.SOL_DEVNET_NATIVE_ASSET,
|
|
69
|
+
isEvm: false,
|
|
70
|
+
},
|
|
71
|
+
[keyring_api_1.TrxScope.Mainnet]: {
|
|
72
|
+
chainId: keyring_api_1.TrxScope.Mainnet,
|
|
73
|
+
name: 'Tron',
|
|
74
|
+
nativeCurrency: exports.TRX_NATIVE_ASSET,
|
|
75
|
+
isEvm: false,
|
|
76
|
+
},
|
|
77
|
+
[keyring_api_1.TrxScope.Nile]: {
|
|
78
|
+
chainId: keyring_api_1.TrxScope.Nile,
|
|
79
|
+
name: 'Tron Nile',
|
|
80
|
+
nativeCurrency: exports.TRX_NILE_NATIVE_ASSET,
|
|
81
|
+
isEvm: false,
|
|
82
|
+
},
|
|
83
|
+
[keyring_api_1.TrxScope.Shasta]: {
|
|
84
|
+
chainId: keyring_api_1.TrxScope.Shasta,
|
|
85
|
+
name: 'Tron Shasta',
|
|
86
|
+
nativeCurrency: exports.TRX_SHASTA_NATIVE_ASSET,
|
|
87
|
+
isEvm: false,
|
|
88
|
+
},
|
|
89
|
+
[keyring_api_1.XlmScope.Pubnet]: {
|
|
90
|
+
chainId: keyring_api_1.XlmScope.Pubnet,
|
|
91
|
+
name: 'Stellar',
|
|
92
|
+
nativeCurrency: exports.XLM_NATIVE_ASSET,
|
|
93
|
+
isEvm: false,
|
|
94
|
+
},
|
|
95
|
+
[keyring_api_1.XlmScope.Testnet]: {
|
|
96
|
+
chainId: keyring_api_1.XlmScope.Testnet,
|
|
97
|
+
name: 'Stellar Testnet',
|
|
98
|
+
nativeCurrency: exports.XLM_TESTNET_NATIVE_ASSET,
|
|
99
|
+
isEvm: false,
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* Array of all the Non-EVM chain IDs.
|
|
104
|
+
* This is a temporary mention until we develop
|
|
105
|
+
* a more robust solution to identify testnet networks.
|
|
106
|
+
*/
|
|
107
|
+
exports.NON_EVM_TESTNET_IDS = [
|
|
108
|
+
keyring_api_1.BtcScope.Testnet,
|
|
109
|
+
keyring_api_1.BtcScope.Testnet4,
|
|
110
|
+
keyring_api_1.BtcScope.Signet,
|
|
111
|
+
keyring_api_1.BtcScope.Regtest,
|
|
112
|
+
keyring_api_1.SolScope.Testnet,
|
|
113
|
+
keyring_api_1.SolScope.Devnet,
|
|
114
|
+
keyring_api_1.TrxScope.Nile,
|
|
115
|
+
keyring_api_1.TrxScope.Shasta,
|
|
116
|
+
keyring_api_1.XlmScope.Testnet,
|
|
117
|
+
];
|
|
118
|
+
/**
|
|
119
|
+
* Metadata for the supported networks.
|
|
120
|
+
*/
|
|
121
|
+
exports.NETWORKS_METADATA = {
|
|
122
|
+
[keyring_api_1.BtcScope.Mainnet]: {
|
|
123
|
+
features: [],
|
|
124
|
+
status: network_controller_1.NetworkStatus.Available,
|
|
125
|
+
},
|
|
126
|
+
[keyring_api_1.SolScope.Mainnet]: {
|
|
127
|
+
features: [],
|
|
128
|
+
status: network_controller_1.NetworkStatus.Available,
|
|
129
|
+
},
|
|
130
|
+
[keyring_api_1.TrxScope.Mainnet]: {
|
|
131
|
+
features: [],
|
|
132
|
+
status: network_controller_1.NetworkStatus.Available,
|
|
133
|
+
},
|
|
134
|
+
[keyring_api_1.XlmScope.Pubnet]: {
|
|
135
|
+
features: [],
|
|
136
|
+
status: network_controller_1.NetworkStatus.Available,
|
|
137
|
+
},
|
|
138
|
+
};
|
|
139
|
+
/**
|
|
140
|
+
* Default state of the {@link MultichainNetworkController}.
|
|
141
|
+
*
|
|
142
|
+
* @returns The default state of the {@link MultichainNetworkController}.
|
|
143
|
+
*/
|
|
144
|
+
const getDefaultMultichainNetworkControllerState = () => ({
|
|
145
|
+
multichainNetworkConfigurationsByChainId: exports.AVAILABLE_MULTICHAIN_NETWORK_CONFIGURATIONS,
|
|
146
|
+
selectedMultichainNetworkChainId: keyring_api_1.SolScope.Mainnet,
|
|
147
|
+
isEvmSelected: true,
|
|
148
|
+
networksWithTransactionActivity: {},
|
|
149
|
+
});
|
|
150
|
+
exports.getDefaultMultichainNetworkControllerState = getDefaultMultichainNetworkControllerState;
|
|
151
|
+
/**
|
|
152
|
+
* {@link MultichainNetworkController}'s metadata.
|
|
153
|
+
*
|
|
154
|
+
* This allows us to choose if fields of the state should be persisted or not
|
|
155
|
+
* using the `persist` flag; and if they can be sent to Sentry or not, using
|
|
156
|
+
* the `anonymous` flag.
|
|
157
|
+
*/
|
|
158
|
+
exports.MULTICHAIN_NETWORK_CONTROLLER_METADATA = {
|
|
159
|
+
multichainNetworkConfigurationsByChainId: {
|
|
160
|
+
includeInStateLogs: true,
|
|
161
|
+
persist: true,
|
|
162
|
+
includeInDebugSnapshot: true,
|
|
163
|
+
usedInUi: true,
|
|
164
|
+
},
|
|
165
|
+
selectedMultichainNetworkChainId: {
|
|
166
|
+
includeInStateLogs: true,
|
|
167
|
+
persist: true,
|
|
168
|
+
includeInDebugSnapshot: true,
|
|
169
|
+
usedInUi: true,
|
|
170
|
+
},
|
|
171
|
+
isEvmSelected: {
|
|
172
|
+
includeInStateLogs: true,
|
|
173
|
+
persist: true,
|
|
174
|
+
includeInDebugSnapshot: true,
|
|
175
|
+
usedInUi: true,
|
|
176
|
+
},
|
|
177
|
+
networksWithTransactionActivity: {
|
|
178
|
+
includeInStateLogs: true,
|
|
179
|
+
persist: true,
|
|
180
|
+
includeInDebugSnapshot: true,
|
|
181
|
+
usedInUi: true,
|
|
182
|
+
},
|
|
183
|
+
};
|
|
184
|
+
/**
|
|
185
|
+
* Multichain network ticker for the supported networks.
|
|
186
|
+
* TODO: This should be part of the assets-controllers or the snap itself.
|
|
187
|
+
*/
|
|
188
|
+
exports.MULTICHAIN_NETWORK_TICKER = {
|
|
189
|
+
[keyring_api_1.BtcScope.Mainnet]: 'BTC',
|
|
190
|
+
[keyring_api_1.BtcScope.Testnet]: 'tBTC',
|
|
191
|
+
[keyring_api_1.BtcScope.Testnet4]: 'tBTC',
|
|
192
|
+
[keyring_api_1.BtcScope.Signet]: 'sBTC',
|
|
193
|
+
[keyring_api_1.BtcScope.Regtest]: 'rBTC',
|
|
194
|
+
[keyring_api_1.SolScope.Mainnet]: 'SOL',
|
|
195
|
+
[keyring_api_1.SolScope.Testnet]: 'tSOL',
|
|
196
|
+
[keyring_api_1.SolScope.Devnet]: 'dSOL',
|
|
197
|
+
[keyring_api_1.TrxScope.Mainnet]: 'TRX',
|
|
198
|
+
[keyring_api_1.TrxScope.Nile]: 'tTRX',
|
|
199
|
+
[keyring_api_1.TrxScope.Shasta]: 'sTRX',
|
|
200
|
+
[keyring_api_1.XlmScope.Pubnet]: 'XLM',
|
|
201
|
+
[keyring_api_1.XlmScope.Testnet]: 'tXLM',
|
|
202
|
+
};
|
|
203
|
+
/**
|
|
204
|
+
* Multichain network asset decimals for the supported networks.
|
|
205
|
+
* TODO: This should be part of the assets-controllers or the snap itself.
|
|
206
|
+
*/
|
|
207
|
+
exports.MULTICHAIN_NETWORK_DECIMAL_PLACES = {
|
|
208
|
+
[keyring_api_1.BtcScope.Mainnet]: 8,
|
|
209
|
+
[keyring_api_1.BtcScope.Testnet]: 8,
|
|
210
|
+
[keyring_api_1.BtcScope.Testnet4]: 8,
|
|
211
|
+
[keyring_api_1.BtcScope.Signet]: 8,
|
|
212
|
+
[keyring_api_1.BtcScope.Regtest]: 8,
|
|
213
|
+
[keyring_api_1.SolScope.Mainnet]: 5,
|
|
214
|
+
[keyring_api_1.SolScope.Testnet]: 5,
|
|
215
|
+
[keyring_api_1.SolScope.Devnet]: 5,
|
|
216
|
+
[keyring_api_1.TrxScope.Mainnet]: 6,
|
|
217
|
+
[keyring_api_1.TrxScope.Nile]: 6,
|
|
218
|
+
[keyring_api_1.TrxScope.Shasta]: 6,
|
|
219
|
+
[keyring_api_1.XlmScope.Pubnet]: 7,
|
|
220
|
+
[keyring_api_1.XlmScope.Testnet]: 7,
|
|
221
|
+
};
|
|
222
|
+
//# sourceMappingURL=constants.cjs.map
|