@metamask-previews/network-controller 20.2.0-preview-b5937ee4 → 20.2.0-preview-b59ee0c8

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.
@@ -0,0 +1,1467 @@
1
+ import {
2
+ INFURA_BLOCKED_KEY
3
+ } from "./chunk-2QJYHWIP.mjs";
4
+ import {
5
+ createAutoManagedNetworkClient
6
+ } from "./chunk-TZA3CBEI.mjs";
7
+ import {
8
+ createModuleLogger,
9
+ projectLogger
10
+ } from "./chunk-VTLOAS2R.mjs";
11
+ import {
12
+ __privateAdd,
13
+ __privateGet,
14
+ __privateMethod,
15
+ __privateSet
16
+ } from "./chunk-XUI43LEZ.mjs";
17
+
18
+ // src/NetworkController.ts
19
+ import { BaseController } from "@metamask/base-controller";
20
+ import {
21
+ InfuraNetworkType,
22
+ NetworkType,
23
+ isSafeChainId,
24
+ isInfuraNetworkType,
25
+ ChainId,
26
+ NetworksTicker,
27
+ NetworkNickname
28
+ } from "@metamask/controller-utils";
29
+ import EthQuery from "@metamask/eth-query";
30
+ import { errorCodes } from "@metamask/rpc-errors";
31
+ import { createEventEmitterProxy } from "@metamask/swappable-obj-proxy";
32
+ import { isStrictHexString, hasProperty, isPlainObject } from "@metamask/utils";
33
+ import { strict as assert } from "assert";
34
+ import * as URI from "uri-js";
35
+ import { inspect } from "util";
36
+ import { v4 as uuidV4 } from "uuid";
37
+ var debugLog = createModuleLogger(projectLogger, "NetworkController");
38
+ var INFURA_URL_REGEX = /^https:\/\/(?<networkName>[^.]+)\.infura\.io\/v\d+\/(?<apiKey>.+)$/u;
39
+ var RpcEndpointType = /* @__PURE__ */ ((RpcEndpointType2) => {
40
+ RpcEndpointType2["Custom"] = "custom";
41
+ RpcEndpointType2["Infura"] = "infura";
42
+ return RpcEndpointType2;
43
+ })(RpcEndpointType || {});
44
+ function knownKeysOf(object) {
45
+ return Object.keys(object);
46
+ }
47
+ function isErrorWithCode(error) {
48
+ return typeof error === "object" && error !== null && "code" in error;
49
+ }
50
+ var controllerName = "NetworkController";
51
+ function getDefaultNetworkConfigurationsByChainId() {
52
+ return Object.values(InfuraNetworkType).reduce((obj, infuraNetworkType) => {
53
+ const chainId = ChainId[infuraNetworkType];
54
+ const rpcEndpointUrl = (
55
+ // False negative - this is a string.
56
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
57
+ `https://${infuraNetworkType}.infura.io/v3/{infuraProjectId}`
58
+ );
59
+ const networkConfiguration = {
60
+ blockExplorerUrls: [],
61
+ chainId,
62
+ defaultRpcEndpointIndex: 0,
63
+ name: NetworkNickname[infuraNetworkType],
64
+ nativeCurrency: NetworksTicker[infuraNetworkType],
65
+ rpcEndpoints: [
66
+ {
67
+ networkClientId: infuraNetworkType,
68
+ type: "infura" /* Infura */,
69
+ url: rpcEndpointUrl
70
+ }
71
+ ]
72
+ };
73
+ return { ...obj, [chainId]: networkConfiguration };
74
+ }, {});
75
+ }
76
+ function getDefaultNetworkControllerState() {
77
+ const networksMetadata = {};
78
+ const networkConfigurationsByChainId = getDefaultNetworkConfigurationsByChainId();
79
+ return {
80
+ selectedNetworkClientId: InfuraNetworkType.mainnet,
81
+ networksMetadata,
82
+ networkConfigurationsByChainId
83
+ };
84
+ }
85
+ function isValidUrl(url) {
86
+ const uri = URI.parse(url);
87
+ return uri.error === void 0 && (uri.scheme === "http" || uri.scheme === "https");
88
+ }
89
+ function deriveInfuraNetworkNameFromRpcEndpointUrl(rpcEndpointUrl) {
90
+ const match = INFURA_URL_REGEX.exec(rpcEndpointUrl);
91
+ if (match?.groups) {
92
+ if (isInfuraNetworkType(match.groups.networkName)) {
93
+ return match.groups.networkName;
94
+ }
95
+ throw new Error(`Unknown Infura network '${match.groups.networkName}'`);
96
+ }
97
+ throw new Error("Could not derive Infura network from RPC endpoint URL");
98
+ }
99
+ function validateNetworkControllerState(state) {
100
+ const networkConfigurationEntries = Object.entries(
101
+ state.networkConfigurationsByChainId
102
+ );
103
+ const networkClientIds = Object.values(
104
+ state.networkConfigurationsByChainId
105
+ ).flatMap(
106
+ (networkConfiguration) => networkConfiguration.rpcEndpoints.map(
107
+ (rpcEndpoint) => rpcEndpoint.networkClientId
108
+ )
109
+ );
110
+ if (networkConfigurationEntries.length === 0) {
111
+ throw new Error(
112
+ "NetworkController state is invalid: `networkConfigurationsByChainId` cannot be empty"
113
+ );
114
+ }
115
+ for (const [chainId, networkConfiguration] of networkConfigurationEntries) {
116
+ if (chainId !== networkConfiguration.chainId) {
117
+ throw new Error(
118
+ `NetworkController state has invalid \`networkConfigurationsByChainId\`: Network configuration '${networkConfiguration.name}' is filed under '${chainId}' which does not match its \`chainId\` of '${networkConfiguration.chainId}'`
119
+ );
120
+ }
121
+ const isInvalidDefaultBlockExplorerUrlIndex = networkConfiguration.blockExplorerUrls.length > 0 ? networkConfiguration.defaultBlockExplorerUrlIndex === void 0 || networkConfiguration.blockExplorerUrls[networkConfiguration.defaultBlockExplorerUrlIndex] === void 0 : networkConfiguration.defaultBlockExplorerUrlIndex !== void 0;
122
+ if (isInvalidDefaultBlockExplorerUrlIndex) {
123
+ throw new Error(
124
+ `NetworkController state has invalid \`networkConfigurationsByChainId\`: Network configuration '${networkConfiguration.name}' has a \`defaultBlockExplorerUrlIndex\` that does not refer to an entry in \`blockExplorerUrls\``
125
+ );
126
+ }
127
+ if (networkConfiguration.rpcEndpoints[networkConfiguration.defaultRpcEndpointIndex] === void 0) {
128
+ throw new Error(
129
+ `NetworkController state has invalid \`networkConfigurationsByChainId\`: Network configuration '${networkConfiguration.name}' has a \`defaultRpcEndpointIndex\` that does not refer to an entry in \`rpcEndpoints\``
130
+ );
131
+ }
132
+ }
133
+ if ([...new Set(networkClientIds)].length < networkClientIds.length) {
134
+ throw new Error(
135
+ "NetworkController state has invalid `networkConfigurationsByChainId`: Every RPC endpoint across all network configurations must have a unique `networkClientId`"
136
+ );
137
+ }
138
+ if (!networkClientIds.includes(state.selectedNetworkClientId)) {
139
+ throw new Error(
140
+ `NetworkController state is invalid: \`selectedNetworkClientId\` ${inspect(
141
+ state.selectedNetworkClientId
142
+ )} does not refer to an RPC endpoint within a network configuration`
143
+ );
144
+ }
145
+ }
146
+ function buildNetworkConfigurationsByNetworkClientId(networkConfigurationsByChainId) {
147
+ return new Map(
148
+ Object.values(networkConfigurationsByChainId).flatMap(
149
+ (networkConfiguration) => {
150
+ return networkConfiguration.rpcEndpoints.map((rpcEndpoint) => {
151
+ return [rpcEndpoint.networkClientId, networkConfiguration];
152
+ });
153
+ }
154
+ )
155
+ );
156
+ }
157
+ var _ethQuery, _infuraProjectId, _previouslySelectedNetworkClientId, _providerProxy, _blockTrackerProxy, _autoManagedNetworkClientRegistry, _autoManagedNetworkClient, _log, _networkConfigurationsByNetworkClientId, _refreshNetwork, refreshNetwork_fn, _getLatestBlock, getLatestBlock_fn, _determineEIP1559Compatibility, determineEIP1559Compatibility_fn, _validateNetworkFields, validateNetworkFields_fn, _determineNetworkConfigurationToPersist, determineNetworkConfigurationToPersist_fn, _registerNetworkClientsAsNeeded, registerNetworkClientsAsNeeded_fn, _unregisterNetworkClientsAsNeeded, unregisterNetworkClientsAsNeeded_fn, _updateNetworkConfigurations, updateNetworkConfigurations_fn, _ensureAutoManagedNetworkClientRegistryPopulated, ensureAutoManagedNetworkClientRegistryPopulated_fn, _createAutoManagedNetworkClientRegistry, createAutoManagedNetworkClientRegistry_fn, _applyNetworkSelection, applyNetworkSelection_fn;
158
+ var NetworkController = class extends BaseController {
159
+ constructor({
160
+ messenger,
161
+ state,
162
+ infuraProjectId,
163
+ log
164
+ }) {
165
+ const initialState = { ...getDefaultNetworkControllerState(), ...state };
166
+ validateNetworkControllerState(initialState);
167
+ if (!infuraProjectId || typeof infuraProjectId !== "string") {
168
+ throw new Error("Invalid Infura project ID");
169
+ }
170
+ super({
171
+ name: controllerName,
172
+ metadata: {
173
+ selectedNetworkClientId: {
174
+ persist: true,
175
+ anonymous: false
176
+ },
177
+ networksMetadata: {
178
+ persist: true,
179
+ anonymous: false
180
+ },
181
+ networkConfigurationsByChainId: {
182
+ persist: true,
183
+ anonymous: false
184
+ }
185
+ },
186
+ messenger,
187
+ state: initialState
188
+ });
189
+ /**
190
+ * Executes a series of steps to switch the network:
191
+ *
192
+ * 1. Notifies subscribers via the messenger that the network is about to be
193
+ * switched (and, really, that the global provider and block tracker proxies
194
+ * will be re-pointed to a new network).
195
+ * 2. Looks up a known and preinitialized network client matching the given
196
+ * ID and uses it to re-point the aforementioned provider and block tracker
197
+ * proxies.
198
+ * 3. Notifies subscribers via the messenger that the network has switched.
199
+ * 4. Captures metadata for the newly switched network in state.
200
+ *
201
+ * @param networkClientId - The ID of a network client that requests will be
202
+ * routed through (either the name of an Infura network or the ID of a custom
203
+ * network configuration).
204
+ * @param options - Options for this method.
205
+ * @param options.updateState - Allows for updating state.
206
+ */
207
+ __privateAdd(this, _refreshNetwork);
208
+ /**
209
+ * Fetches the latest block for the network.
210
+ *
211
+ * @param networkClientId - The networkClientId to fetch the correct provider against which to check the latest block. Defaults to the selectedNetworkClientId.
212
+ * @returns A promise that either resolves to the block header or null if
213
+ * there is no latest block, or rejects with an error.
214
+ */
215
+ __privateAdd(this, _getLatestBlock);
216
+ /**
217
+ * Retrieves and checks the latest block from the currently selected
218
+ * network; if the block has a `baseFeePerGas` property, then we know
219
+ * that the network supports EIP-1559; otherwise it doesn't.
220
+ *
221
+ * @param networkClientId - The networkClientId to fetch the correct provider against which to check 1559 compatibility
222
+ * @returns A promise that resolves to `true` if the network supports EIP-1559,
223
+ * `false` otherwise, or `undefined` if unable to retrieve the last block.
224
+ */
225
+ __privateAdd(this, _determineEIP1559Compatibility);
226
+ /**
227
+ * Ensure that the given fields which will be used to either add or update a
228
+ * network are valid.
229
+ *
230
+ * @param args - The arguments.
231
+ */
232
+ __privateAdd(this, _validateNetworkFields);
233
+ /**
234
+ * Constructs a network configuration that will be persisted to state when
235
+ * adding or updating a network.
236
+ *
237
+ * @param args - The arguments to this function.
238
+ * @param args.networkFields - The fields used to add or update a network.
239
+ * @param args.networkClientOperations - Operations which were calculated for
240
+ * updating the network client registry but which also map back to RPC
241
+ * endpoints (and so can be used to save those RPC endpoints).
242
+ * @returns The network configuration to persist.
243
+ */
244
+ __privateAdd(this, _determineNetworkConfigurationToPersist);
245
+ /**
246
+ * Creates and registers network clients using the given operations calculated
247
+ * as a part of adding or updating a network.
248
+ *
249
+ * @param args - The arguments to this function.
250
+ * @param args.networkFields - The fields used to add or update a network.
251
+ * @param args.networkClientOperations - Dictate which network clients need to
252
+ * be created.
253
+ * @param args.autoManagedNetworkClientRegistry - The network client registry
254
+ * to update.
255
+ */
256
+ __privateAdd(this, _registerNetworkClientsAsNeeded);
257
+ /**
258
+ * Destroys and removes network clients using the given operations calculated
259
+ * as a part of updating or removing a network.
260
+ *
261
+ * @param args - The arguments to this function.
262
+ * @param args.networkClientOperations - Dictate which network clients to
263
+ * remove.
264
+ * @param args.autoManagedNetworkClientRegistry - The network client registry
265
+ * to update.
266
+ */
267
+ __privateAdd(this, _unregisterNetworkClientsAsNeeded);
268
+ /**
269
+ * Updates `networkConfigurationsByChainId` in state depending on whether a
270
+ * network is being added, updated, or removed.
271
+ *
272
+ * - The existing network configuration will be removed when a network is
273
+ * being filed under a different chain or removed.
274
+ * - A network configuration will be stored when a network is being added or
275
+ * when a network is being updated.
276
+ *
277
+ * @param args - The arguments to this function.
278
+ */
279
+ __privateAdd(this, _updateNetworkConfigurations);
280
+ /**
281
+ * Before accessing or switching the network, the registry of network clients
282
+ * needs to be populated. Otherwise, `#applyNetworkSelection` and
283
+ * `getNetworkClientRegistry` will throw an error. This method checks to see if the
284
+ * population step has happened yet, and if not, makes it happen.
285
+ *
286
+ * @returns The populated network client registry.
287
+ */
288
+ __privateAdd(this, _ensureAutoManagedNetworkClientRegistryPopulated);
289
+ /**
290
+ * Constructs the registry of network clients based on the set of default
291
+ * and custom networks in state.
292
+ *
293
+ * @returns The network clients keyed by ID.
294
+ */
295
+ __privateAdd(this, _createAutoManagedNetworkClientRegistry);
296
+ /**
297
+ * Updates the global provider and block tracker proxies (accessible via
298
+ * {@link getSelectedNetworkClient}) to point to the same ones within the
299
+ * given network client, thereby magically switching any consumers using these
300
+ * proxies to use the new network.
301
+ *
302
+ * Also refreshes the EthQuery instance accessible via the `getEthQuery`
303
+ * action to wrap the provider from the new network client. Note that this is
304
+ * not a proxy, so consumers will need to call `getEthQuery` again after the
305
+ * network switch.
306
+ *
307
+ * @param networkClientId - The ID of a network client that requests will be
308
+ * routed through (either the name of an Infura network or the ID of a custom
309
+ * network configuration).
310
+ * @param options - Options for this method.
311
+ * @param options.updateState - Allows for updating state.
312
+ * @throws if no network client could be found matching the given ID.
313
+ */
314
+ __privateAdd(this, _applyNetworkSelection);
315
+ __privateAdd(this, _ethQuery, void 0);
316
+ __privateAdd(this, _infuraProjectId, void 0);
317
+ __privateAdd(this, _previouslySelectedNetworkClientId, void 0);
318
+ __privateAdd(this, _providerProxy, void 0);
319
+ __privateAdd(this, _blockTrackerProxy, void 0);
320
+ __privateAdd(this, _autoManagedNetworkClientRegistry, void 0);
321
+ __privateAdd(this, _autoManagedNetworkClient, void 0);
322
+ __privateAdd(this, _log, void 0);
323
+ __privateAdd(this, _networkConfigurationsByNetworkClientId, void 0);
324
+ __privateSet(this, _infuraProjectId, infuraProjectId);
325
+ __privateSet(this, _log, log);
326
+ __privateSet(this, _previouslySelectedNetworkClientId, this.state.selectedNetworkClientId);
327
+ __privateSet(this, _networkConfigurationsByNetworkClientId, buildNetworkConfigurationsByNetworkClientId(
328
+ this.state.networkConfigurationsByChainId
329
+ ));
330
+ this.messagingSystem.registerActionHandler(
331
+ // TODO: Either fix this lint violation or explain why it's necessary to ignore.
332
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
333
+ `${this.name}:getEthQuery`,
334
+ () => {
335
+ return __privateGet(this, _ethQuery);
336
+ }
337
+ );
338
+ this.messagingSystem.registerActionHandler(
339
+ // TODO: Either fix this lint violation or explain why it's necessary to ignore.
340
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
341
+ `${this.name}:getNetworkClientById`,
342
+ this.getNetworkClientById.bind(this)
343
+ );
344
+ this.messagingSystem.registerActionHandler(
345
+ // TODO: Either fix this lint violation or explain why it's necessary to ignore.
346
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
347
+ `${this.name}:getEIP1559Compatibility`,
348
+ this.getEIP1559Compatibility.bind(this)
349
+ );
350
+ this.messagingSystem.registerActionHandler(
351
+ // TODO: Either fix this lint violation or explain why it's necessary to ignore.
352
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
353
+ `${this.name}:setActiveNetwork`,
354
+ this.setActiveNetwork.bind(this)
355
+ );
356
+ this.messagingSystem.registerActionHandler(
357
+ // TODO: Either fix this lint violation or explain why it's necessary to ignore.
358
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
359
+ `${this.name}:setProviderType`,
360
+ this.setProviderType.bind(this)
361
+ );
362
+ this.messagingSystem.registerActionHandler(
363
+ // TODO: Either fix this lint violation or explain why it's necessary to ignore.
364
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
365
+ `${this.name}:findNetworkClientIdByChainId`,
366
+ this.findNetworkClientIdByChainId.bind(this)
367
+ );
368
+ this.messagingSystem.registerActionHandler(
369
+ // TODO: Either fix this lint violation or explain why it's necessary to ignore.
370
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
371
+ `${this.name}:getNetworkConfigurationByChainId`,
372
+ this.getNetworkConfigurationByChainId.bind(this)
373
+ );
374
+ this.messagingSystem.registerActionHandler(
375
+ // ESLint is mistaken here; `name` is a string.
376
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
377
+ `${this.name}:getNetworkConfigurationByNetworkClientId`,
378
+ this.getNetworkConfigurationByNetworkClientId.bind(this)
379
+ );
380
+ this.messagingSystem.registerActionHandler(
381
+ // TODO: Either fix this lint violation or explain why it's necessary to ignore.
382
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
383
+ `${this.name}:getSelectedNetworkClient`,
384
+ this.getSelectedNetworkClient.bind(this)
385
+ );
386
+ }
387
+ /**
388
+ * Accesses the provider and block tracker for the currently selected network.
389
+ * @returns The proxy and block tracker proxies.
390
+ * @deprecated This method has been replaced by `getSelectedNetworkClient` (which has a more easily used return type) and will be removed in a future release.
391
+ */
392
+ getProviderAndBlockTracker() {
393
+ return {
394
+ provider: __privateGet(this, _providerProxy),
395
+ blockTracker: __privateGet(this, _blockTrackerProxy)
396
+ };
397
+ }
398
+ /**
399
+ * Accesses the provider and block tracker for the currently selected network.
400
+ *
401
+ * @returns an object with the provider and block tracker proxies for the currently selected network.
402
+ */
403
+ getSelectedNetworkClient() {
404
+ if (__privateGet(this, _providerProxy) && __privateGet(this, _blockTrackerProxy)) {
405
+ return {
406
+ provider: __privateGet(this, _providerProxy),
407
+ blockTracker: __privateGet(this, _blockTrackerProxy)
408
+ };
409
+ }
410
+ return void 0;
411
+ }
412
+ /**
413
+ * Internally, the Infura and custom network clients are categorized by type
414
+ * so that when accessing either kind of network client, TypeScript knows
415
+ * which type to assign to the network client. For some cases it's more useful
416
+ * to be able to access network clients by ID instead of by type and then ID,
417
+ * so this function makes that possible.
418
+ *
419
+ * @returns The network clients registered so far, keyed by ID.
420
+ */
421
+ getNetworkClientRegistry() {
422
+ const autoManagedNetworkClientRegistry = __privateMethod(this, _ensureAutoManagedNetworkClientRegistryPopulated, ensureAutoManagedNetworkClientRegistryPopulated_fn).call(this);
423
+ return Object.assign(
424
+ {},
425
+ autoManagedNetworkClientRegistry["infura" /* Infura */],
426
+ autoManagedNetworkClientRegistry["custom" /* Custom */]
427
+ );
428
+ }
429
+ getNetworkClientById(networkClientId) {
430
+ if (!networkClientId) {
431
+ throw new Error("No network client ID was provided.");
432
+ }
433
+ const autoManagedNetworkClientRegistry = __privateMethod(this, _ensureAutoManagedNetworkClientRegistryPopulated, ensureAutoManagedNetworkClientRegistryPopulated_fn).call(this);
434
+ if (isInfuraNetworkType(networkClientId)) {
435
+ const infuraNetworkClient = autoManagedNetworkClientRegistry["infura" /* Infura */][networkClientId];
436
+ if (!infuraNetworkClient) {
437
+ throw new Error(
438
+ // TODO: Either fix this lint violation or explain why it's necessary to ignore.
439
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
440
+ `No Infura network client was found with the ID "${networkClientId}".`
441
+ );
442
+ }
443
+ return infuraNetworkClient;
444
+ }
445
+ const customNetworkClient = autoManagedNetworkClientRegistry["custom" /* Custom */][networkClientId];
446
+ if (!customNetworkClient) {
447
+ throw new Error(
448
+ // TODO: Either fix this lint violation or explain why it's necessary to ignore.
449
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
450
+ `No custom network client was found with the ID "${networkClientId}".`
451
+ );
452
+ }
453
+ return customNetworkClient;
454
+ }
455
+ /**
456
+ * Ensures that network clients for Infura and custom RPC endpoints have been
457
+ * created. Then, consulting state, initializes and establishes the currently
458
+ * selected network client.
459
+ */
460
+ async initializeProvider() {
461
+ __privateMethod(this, _applyNetworkSelection, applyNetworkSelection_fn).call(this, this.state.selectedNetworkClientId);
462
+ await this.lookupNetwork();
463
+ }
464
+ /**
465
+ * Refreshes the network meta with EIP-1559 support and the network status
466
+ * based on the given network client ID.
467
+ *
468
+ * @param networkClientId - The ID of the network client to update.
469
+ */
470
+ async lookupNetworkByClientId(networkClientId) {
471
+ const isInfura = isInfuraNetworkType(networkClientId);
472
+ let updatedNetworkStatus;
473
+ let updatedIsEIP1559Compatible;
474
+ try {
475
+ updatedIsEIP1559Compatible = await __privateMethod(this, _determineEIP1559Compatibility, determineEIP1559Compatibility_fn).call(this, networkClientId);
476
+ updatedNetworkStatus = "available" /* Available */;
477
+ } catch (error) {
478
+ debugLog("NetworkController: lookupNetworkByClientId: ", error);
479
+ if (isErrorWithCode(error)) {
480
+ let responseBody;
481
+ if (isInfura && hasProperty(error, "message") && typeof error.message === "string") {
482
+ try {
483
+ responseBody = JSON.parse(error.message);
484
+ } catch {
485
+ __privateGet(this, _log)?.warn(
486
+ "NetworkController: lookupNetworkByClientId: json parse error: ",
487
+ error
488
+ );
489
+ }
490
+ }
491
+ if (isPlainObject(responseBody) && responseBody.error === INFURA_BLOCKED_KEY) {
492
+ updatedNetworkStatus = "blocked" /* Blocked */;
493
+ } else if (error.code === errorCodes.rpc.internal) {
494
+ updatedNetworkStatus = "unknown" /* Unknown */;
495
+ __privateGet(this, _log)?.warn(
496
+ "NetworkController: lookupNetworkByClientId: rpc internal error: ",
497
+ error
498
+ );
499
+ } else {
500
+ updatedNetworkStatus = "unavailable" /* Unavailable */;
501
+ __privateGet(this, _log)?.warn(
502
+ "NetworkController: lookupNetworkByClientId: ",
503
+ error
504
+ );
505
+ }
506
+ } else if (typeof Error !== "undefined" && hasProperty(error, "message") && typeof error.message === "string" && error.message.includes(
507
+ "No custom network client was found with the ID"
508
+ )) {
509
+ throw error;
510
+ } else {
511
+ debugLog(
512
+ "NetworkController - could not determine network status",
513
+ error
514
+ );
515
+ updatedNetworkStatus = "unknown" /* Unknown */;
516
+ __privateGet(this, _log)?.warn("NetworkController: lookupNetworkByClientId: ", error);
517
+ }
518
+ }
519
+ this.update((state) => {
520
+ if (state.networksMetadata[networkClientId] === void 0) {
521
+ state.networksMetadata[networkClientId] = {
522
+ status: "unknown" /* Unknown */,
523
+ EIPS: {}
524
+ };
525
+ }
526
+ const meta = state.networksMetadata[networkClientId];
527
+ meta.status = updatedNetworkStatus;
528
+ if (updatedIsEIP1559Compatible === void 0) {
529
+ delete meta.EIPS[1559];
530
+ } else {
531
+ meta.EIPS[1559] = updatedIsEIP1559Compatible;
532
+ }
533
+ });
534
+ }
535
+ /**
536
+ * Persists the following metadata about the given or selected network to
537
+ * state:
538
+ *
539
+ * - The status of the network, namely, whether it is available, geo-blocked
540
+ * (Infura only), or unavailable, or whether the status is unknown
541
+ * - Whether the network supports EIP-1559, or whether it is unknown
542
+ *
543
+ * Note that it is possible for the network to be switched while this data is
544
+ * being collected. If that is the case, no metadata for the (now previously)
545
+ * selected network will be updated.
546
+ *
547
+ * @param networkClientId - The ID of the network client to update.
548
+ * If no ID is provided, uses the currently selected network.
549
+ */
550
+ async lookupNetwork(networkClientId) {
551
+ if (networkClientId) {
552
+ await this.lookupNetworkByClientId(networkClientId);
553
+ return;
554
+ }
555
+ if (!__privateGet(this, _ethQuery)) {
556
+ return;
557
+ }
558
+ const isInfura = __privateGet(this, _autoManagedNetworkClient)?.configuration.type === "infura" /* Infura */;
559
+ let networkChanged = false;
560
+ const listener = () => {
561
+ networkChanged = true;
562
+ this.messagingSystem.unsubscribe(
563
+ "NetworkController:networkDidChange",
564
+ listener
565
+ );
566
+ };
567
+ this.messagingSystem.subscribe(
568
+ "NetworkController:networkDidChange",
569
+ listener
570
+ );
571
+ let updatedNetworkStatus;
572
+ let updatedIsEIP1559Compatible;
573
+ try {
574
+ const isEIP1559Compatible = await __privateMethod(this, _determineEIP1559Compatibility, determineEIP1559Compatibility_fn).call(this, this.state.selectedNetworkClientId);
575
+ updatedNetworkStatus = "available" /* Available */;
576
+ updatedIsEIP1559Compatible = isEIP1559Compatible;
577
+ } catch (error) {
578
+ if (isErrorWithCode(error)) {
579
+ let responseBody;
580
+ if (isInfura && hasProperty(error, "message") && typeof error.message === "string") {
581
+ try {
582
+ responseBody = JSON.parse(error.message);
583
+ } catch (parseError) {
584
+ __privateGet(this, _log)?.warn(
585
+ "NetworkController: lookupNetwork: json parse error",
586
+ parseError
587
+ );
588
+ }
589
+ }
590
+ if (isPlainObject(responseBody) && responseBody.error === INFURA_BLOCKED_KEY) {
591
+ updatedNetworkStatus = "blocked" /* Blocked */;
592
+ } else if (error.code === errorCodes.rpc.internal) {
593
+ updatedNetworkStatus = "unknown" /* Unknown */;
594
+ __privateGet(this, _log)?.warn(
595
+ "NetworkController: lookupNetwork: rpc internal error",
596
+ error
597
+ );
598
+ } else {
599
+ updatedNetworkStatus = "unavailable" /* Unavailable */;
600
+ __privateGet(this, _log)?.warn("NetworkController: lookupNetwork: ", error);
601
+ }
602
+ } else {
603
+ debugLog(
604
+ "NetworkController - could not determine network status",
605
+ error
606
+ );
607
+ updatedNetworkStatus = "unknown" /* Unknown */;
608
+ __privateGet(this, _log)?.warn("NetworkController: lookupNetwork: ", error);
609
+ }
610
+ }
611
+ if (networkChanged) {
612
+ return;
613
+ }
614
+ this.messagingSystem.unsubscribe(
615
+ "NetworkController:networkDidChange",
616
+ listener
617
+ );
618
+ this.update((state) => {
619
+ const meta = state.networksMetadata[state.selectedNetworkClientId];
620
+ meta.status = updatedNetworkStatus;
621
+ if (updatedIsEIP1559Compatible === void 0) {
622
+ delete meta.EIPS[1559];
623
+ } else {
624
+ meta.EIPS[1559] = updatedIsEIP1559Compatible;
625
+ }
626
+ });
627
+ if (isInfura) {
628
+ if (updatedNetworkStatus === "available" /* Available */) {
629
+ this.messagingSystem.publish("NetworkController:infuraIsUnblocked");
630
+ } else if (updatedNetworkStatus === "blocked" /* Blocked */) {
631
+ this.messagingSystem.publish("NetworkController:infuraIsBlocked");
632
+ }
633
+ } else {
634
+ this.messagingSystem.publish("NetworkController:infuraIsUnblocked");
635
+ }
636
+ }
637
+ /**
638
+ * Convenience method to update provider network type settings.
639
+ *
640
+ * @param type - Human readable network name.
641
+ * @deprecated This has been replaced by `setActiveNetwork`, and will be
642
+ * removed in a future release
643
+ */
644
+ async setProviderType(type) {
645
+ assert.notStrictEqual(
646
+ type,
647
+ NetworkType.rpc,
648
+ // TODO: Either fix this lint violation or explain why it's necessary to ignore.
649
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
650
+ `NetworkController - cannot call "setProviderType" with type "${NetworkType.rpc}". Use "setActiveNetwork"`
651
+ );
652
+ assert.ok(
653
+ isInfuraNetworkType(type),
654
+ // TODO: Either fix this lint violation or explain why it's necessary to ignore.
655
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
656
+ `Unknown Infura provider type "${type}".`
657
+ );
658
+ await this.setActiveNetwork(type);
659
+ }
660
+ /**
661
+ * Changes the selected network.
662
+ *
663
+ * @param networkClientId - The ID of a network client that will be used to
664
+ * make requests.
665
+ * @param options - Options for this method.
666
+ * @param options.updateState - Allows for updating state.
667
+ * @throws if no network client is associated with the given
668
+ * network client ID.
669
+ */
670
+ async setActiveNetwork(networkClientId, options = {}) {
671
+ __privateSet(this, _previouslySelectedNetworkClientId, this.state.selectedNetworkClientId);
672
+ await __privateMethod(this, _refreshNetwork, refreshNetwork_fn).call(this, networkClientId, options);
673
+ }
674
+ /**
675
+ * Determines whether the network supports EIP-1559 by checking whether the
676
+ * latest block has a `baseFeePerGas` property, then updates state
677
+ * appropriately.
678
+ *
679
+ * @param networkClientId - The networkClientId to fetch the correct provider against which to check 1559 compatibility.
680
+ * @returns A promise that resolves to true if the network supports EIP-1559
681
+ * , false otherwise, or `undefined` if unable to determine the compatibility.
682
+ */
683
+ async getEIP1559Compatibility(networkClientId) {
684
+ if (networkClientId) {
685
+ return this.get1559CompatibilityWithNetworkClientId(networkClientId);
686
+ }
687
+ if (!__privateGet(this, _ethQuery)) {
688
+ return false;
689
+ }
690
+ const { EIPS } = this.state.networksMetadata[this.state.selectedNetworkClientId];
691
+ if (EIPS[1559] !== void 0) {
692
+ return EIPS[1559];
693
+ }
694
+ const isEIP1559Compatible = await __privateMethod(this, _determineEIP1559Compatibility, determineEIP1559Compatibility_fn).call(this, this.state.selectedNetworkClientId);
695
+ this.update((state) => {
696
+ if (isEIP1559Compatible !== void 0) {
697
+ state.networksMetadata[state.selectedNetworkClientId].EIPS[1559] = isEIP1559Compatible;
698
+ }
699
+ });
700
+ return isEIP1559Compatible;
701
+ }
702
+ async get1559CompatibilityWithNetworkClientId(networkClientId) {
703
+ let metadata = this.state.networksMetadata[networkClientId];
704
+ if (metadata === void 0) {
705
+ await this.lookupNetwork(networkClientId);
706
+ metadata = this.state.networksMetadata[networkClientId];
707
+ }
708
+ const { EIPS } = metadata;
709
+ return EIPS[1559];
710
+ }
711
+ /**
712
+ * Ensures that the provider and block tracker proxies are pointed to the
713
+ * currently selected network and refreshes the metadata for the
714
+ */
715
+ async resetConnection() {
716
+ await __privateMethod(this, _refreshNetwork, refreshNetwork_fn).call(this, this.state.selectedNetworkClientId);
717
+ }
718
+ /**
719
+ * Returns the network configuration that has been filed under the given chain
720
+ * ID.
721
+ *
722
+ * @param chainId - The chain ID to use as a key.
723
+ * @returns The network configuration if one exists, or undefined.
724
+ */
725
+ getNetworkConfigurationByChainId(chainId) {
726
+ return this.state.networkConfigurationsByChainId[chainId];
727
+ }
728
+ /**
729
+ * Returns the network configuration that contains an RPC endpoint with the
730
+ * given network client ID.
731
+ *
732
+ * @param networkClientId - The network client ID to use as a key.
733
+ * @returns The network configuration if one exists, or undefined.
734
+ */
735
+ getNetworkConfigurationByNetworkClientId(networkClientId) {
736
+ return __privateGet(this, _networkConfigurationsByNetworkClientId).get(networkClientId);
737
+ }
738
+ /**
739
+ * Creates and registers network clients for the collection of Infura and
740
+ * custom RPC endpoints that can be used to make requests for a particular
741
+ * chain, storing the given configuration object in state for later reference.
742
+ *
743
+ * @param fields - The object that describes the new network/chain and lists
744
+ * the RPC endpoints which front that chain.
745
+ * @returns The newly added network configuration.
746
+ * @throws if any part of `fields` would produce invalid state.
747
+ * @see {@link NetworkConfiguration}
748
+ */
749
+ addNetwork(fields) {
750
+ const { rpcEndpoints: setOfRpcEndpointFields } = fields;
751
+ const autoManagedNetworkClientRegistry = __privateMethod(this, _ensureAutoManagedNetworkClientRegistryPopulated, ensureAutoManagedNetworkClientRegistryPopulated_fn).call(this);
752
+ __privateMethod(this, _validateNetworkFields, validateNetworkFields_fn).call(this, {
753
+ mode: "add",
754
+ networkFields: fields,
755
+ autoManagedNetworkClientRegistry
756
+ });
757
+ const networkClientOperations = setOfRpcEndpointFields.map(
758
+ (defaultOrCustomRpcEndpointFields) => {
759
+ const rpcEndpoint = defaultOrCustomRpcEndpointFields.type === "custom" /* Custom */ ? {
760
+ ...defaultOrCustomRpcEndpointFields,
761
+ networkClientId: uuidV4()
762
+ } : defaultOrCustomRpcEndpointFields;
763
+ return {
764
+ type: "add",
765
+ rpcEndpoint
766
+ };
767
+ }
768
+ );
769
+ const newNetworkConfiguration = __privateMethod(this, _determineNetworkConfigurationToPersist, determineNetworkConfigurationToPersist_fn).call(this, {
770
+ networkFields: fields,
771
+ networkClientOperations
772
+ });
773
+ __privateMethod(this, _registerNetworkClientsAsNeeded, registerNetworkClientsAsNeeded_fn).call(this, {
774
+ networkFields: fields,
775
+ networkClientOperations,
776
+ autoManagedNetworkClientRegistry
777
+ });
778
+ this.update((state) => {
779
+ __privateMethod(this, _updateNetworkConfigurations, updateNetworkConfigurations_fn).call(this, {
780
+ state,
781
+ mode: "add",
782
+ networkFields: fields,
783
+ networkConfigurationToPersist: newNetworkConfiguration
784
+ });
785
+ });
786
+ this.messagingSystem.publish(
787
+ `${controllerName}:networkAdded`,
788
+ newNetworkConfiguration
789
+ );
790
+ return newNetworkConfiguration;
791
+ }
792
+ /**
793
+ * Updates the configuration for a previously stored network filed under the
794
+ * given chain ID, creating + registering new network clients to represent RPC
795
+ * endpoints that have been added and destroying + unregistering existing
796
+ * network clients for RPC endpoints that have been removed.
797
+ *
798
+ * Note that if `chainId` is changed, then all network clients associated with
799
+ * that chain will be removed and re-added, even if none of the RPC endpoints
800
+ * have changed.
801
+ *
802
+ * @param chainId - The chain ID associated with an existing network.
803
+ * @param fields - The object that describes the updates to the network/chain,
804
+ * including the new set of RPC endpoints which should front that chain.
805
+ * @param options - Options to provide.
806
+ * @param options.replacementSelectedRpcEndpointIndex - Usually you cannot
807
+ * remove an RPC endpoint that is being represented by the currently selected
808
+ * network client. This option allows you to specify another RPC endpoint
809
+ * (either an existing one or a new one) that should be used to select a new
810
+ * network instead.
811
+ * @returns The updated network configuration.
812
+ * @throws if `chainId` does not refer to an existing network configuration,
813
+ * if any part of `fields` would produce invalid state, etc.
814
+ * @see {@link NetworkConfiguration}
815
+ */
816
+ async updateNetwork(chainId, fields, {
817
+ replacementSelectedRpcEndpointIndex
818
+ } = {}) {
819
+ const existingNetworkConfiguration = this.state.networkConfigurationsByChainId[chainId];
820
+ if (existingNetworkConfiguration === void 0) {
821
+ throw new Error(
822
+ `Could not update network: Cannot find network configuration for chain ${inspect(
823
+ chainId
824
+ )}`
825
+ );
826
+ }
827
+ const existingChainId = chainId;
828
+ const { chainId: newChainId, rpcEndpoints: setOfNewRpcEndpointFields } = fields;
829
+ const autoManagedNetworkClientRegistry = __privateMethod(this, _ensureAutoManagedNetworkClientRegistryPopulated, ensureAutoManagedNetworkClientRegistryPopulated_fn).call(this);
830
+ __privateMethod(this, _validateNetworkFields, validateNetworkFields_fn).call(this, {
831
+ mode: "update",
832
+ networkFields: fields,
833
+ existingNetworkConfiguration,
834
+ autoManagedNetworkClientRegistry
835
+ });
836
+ const networkClientOperations = [];
837
+ for (const newRpcEndpointFields of setOfNewRpcEndpointFields) {
838
+ const existingRpcEndpointForNoop = existingNetworkConfiguration.rpcEndpoints.find((rpcEndpoint) => {
839
+ return rpcEndpoint.type === newRpcEndpointFields.type && rpcEndpoint.url === newRpcEndpointFields.url && (rpcEndpoint.networkClientId === newRpcEndpointFields.networkClientId || newRpcEndpointFields.networkClientId === void 0);
840
+ });
841
+ const existingRpcEndpointForReplaceWhenChainChanged = existingNetworkConfiguration.rpcEndpoints.find((rpcEndpoint) => {
842
+ return rpcEndpoint.type === "infura" /* Infura */ && newRpcEndpointFields.type === "infura" /* Infura */ || rpcEndpoint.type === newRpcEndpointFields.type && rpcEndpoint.networkClientId === newRpcEndpointFields.networkClientId && rpcEndpoint.url === newRpcEndpointFields.url;
843
+ });
844
+ const existingRpcEndpointForReplaceWhenChainNotChanged = existingNetworkConfiguration.rpcEndpoints.find((rpcEndpoint) => {
845
+ return rpcEndpoint.type === newRpcEndpointFields.type && (rpcEndpoint.url === newRpcEndpointFields.url || rpcEndpoint.networkClientId === newRpcEndpointFields.networkClientId);
846
+ });
847
+ if (newChainId !== existingChainId && existingRpcEndpointForReplaceWhenChainChanged !== void 0) {
848
+ const newRpcEndpoint = newRpcEndpointFields.type === "infura" /* Infura */ ? newRpcEndpointFields : { ...newRpcEndpointFields, networkClientId: uuidV4() };
849
+ networkClientOperations.push({
850
+ type: "replace",
851
+ oldRpcEndpoint: existingRpcEndpointForReplaceWhenChainChanged,
852
+ newRpcEndpoint
853
+ });
854
+ } else if (existingRpcEndpointForNoop !== void 0) {
855
+ let newRpcEndpoint;
856
+ if (existingRpcEndpointForNoop.type === "infura" /* Infura */) {
857
+ newRpcEndpoint = existingRpcEndpointForNoop;
858
+ } else {
859
+ newRpcEndpoint = Object.assign({}, newRpcEndpointFields, {
860
+ networkClientId: existingRpcEndpointForNoop.networkClientId
861
+ });
862
+ }
863
+ networkClientOperations.push({
864
+ type: "noop",
865
+ rpcEndpoint: newRpcEndpoint
866
+ });
867
+ } else if (existingRpcEndpointForReplaceWhenChainNotChanged !== void 0) {
868
+ let newRpcEndpoint;
869
+ if (newRpcEndpointFields.type === "infura" /* Infura */) {
870
+ newRpcEndpoint = newRpcEndpointFields;
871
+ } else {
872
+ newRpcEndpoint = {
873
+ ...newRpcEndpointFields,
874
+ networkClientId: uuidV4()
875
+ };
876
+ }
877
+ networkClientOperations.push({
878
+ type: "replace",
879
+ oldRpcEndpoint: existingRpcEndpointForReplaceWhenChainNotChanged,
880
+ newRpcEndpoint
881
+ });
882
+ } else {
883
+ const newRpcEndpoint = newRpcEndpointFields.type === "infura" /* Infura */ ? newRpcEndpointFields : { ...newRpcEndpointFields, networkClientId: uuidV4() };
884
+ const networkClientOperation = {
885
+ type: "add",
886
+ rpcEndpoint: newRpcEndpoint
887
+ };
888
+ networkClientOperations.push(networkClientOperation);
889
+ }
890
+ }
891
+ for (const existingRpcEndpoint of existingNetworkConfiguration.rpcEndpoints) {
892
+ if (!networkClientOperations.some((networkClientOperation) => {
893
+ const otherRpcEndpoint = networkClientOperation.type === "replace" ? networkClientOperation.oldRpcEndpoint : networkClientOperation.rpcEndpoint;
894
+ return otherRpcEndpoint.type === existingRpcEndpoint.type && otherRpcEndpoint.networkClientId === existingRpcEndpoint.networkClientId && otherRpcEndpoint.url === existingRpcEndpoint.url;
895
+ })) {
896
+ const networkClientOperation = {
897
+ type: "remove",
898
+ rpcEndpoint: existingRpcEndpoint
899
+ };
900
+ networkClientOperations.push(networkClientOperation);
901
+ }
902
+ }
903
+ const updatedNetworkConfiguration = __privateMethod(this, _determineNetworkConfigurationToPersist, determineNetworkConfigurationToPersist_fn).call(this, {
904
+ networkFields: fields,
905
+ networkClientOperations
906
+ });
907
+ if (replacementSelectedRpcEndpointIndex === void 0 && networkClientOperations.some((networkClientOperation) => {
908
+ return networkClientOperation.type === "remove" && networkClientOperation.rpcEndpoint.networkClientId === this.state.selectedNetworkClientId;
909
+ }) && !networkClientOperations.some((networkClientOperation) => {
910
+ return networkClientOperation.type === "replace" && networkClientOperation.oldRpcEndpoint.networkClientId === this.state.selectedNetworkClientId;
911
+ })) {
912
+ throw new Error(
913
+ // False negative - this is a string.
914
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
915
+ `Could not update network: Cannot update RPC endpoints in such a way that the selected network '${this.state.selectedNetworkClientId}' would be removed without a replacement. Choose a different RPC endpoint as the selected network via the \`replacementSelectedRpcEndpointIndex\` option.`
916
+ );
917
+ }
918
+ __privateMethod(this, _registerNetworkClientsAsNeeded, registerNetworkClientsAsNeeded_fn).call(this, {
919
+ networkFields: fields,
920
+ networkClientOperations,
921
+ autoManagedNetworkClientRegistry
922
+ });
923
+ const replacementSelectedRpcEndpointWithIndex = networkClientOperations.map(
924
+ (networkClientOperation, index) => [networkClientOperation, index]
925
+ ).find(([networkClientOperation, _index]) => {
926
+ return networkClientOperation.type === "replace" && networkClientOperation.oldRpcEndpoint.networkClientId === this.state.selectedNetworkClientId;
927
+ });
928
+ const correctedReplacementSelectedRpcEndpointIndex = replacementSelectedRpcEndpointIndex ?? replacementSelectedRpcEndpointWithIndex?.[1];
929
+ let rpcEndpointToSelect;
930
+ if (correctedReplacementSelectedRpcEndpointIndex !== void 0) {
931
+ rpcEndpointToSelect = updatedNetworkConfiguration.rpcEndpoints[correctedReplacementSelectedRpcEndpointIndex];
932
+ if (rpcEndpointToSelect === void 0) {
933
+ throw new Error(
934
+ `Could not update network: \`replacementSelectedRpcEndpointIndex\` ${correctedReplacementSelectedRpcEndpointIndex} does not refer to an entry in \`rpcEndpoints\``
935
+ );
936
+ }
937
+ }
938
+ if (rpcEndpointToSelect && rpcEndpointToSelect.networkClientId !== this.state.selectedNetworkClientId) {
939
+ await this.setActiveNetwork(rpcEndpointToSelect.networkClientId, {
940
+ updateState: (state) => {
941
+ __privateMethod(this, _updateNetworkConfigurations, updateNetworkConfigurations_fn).call(this, {
942
+ state,
943
+ mode: "update",
944
+ networkFields: fields,
945
+ networkConfigurationToPersist: updatedNetworkConfiguration,
946
+ existingNetworkConfiguration
947
+ });
948
+ }
949
+ });
950
+ } else {
951
+ this.update((state) => {
952
+ __privateMethod(this, _updateNetworkConfigurations, updateNetworkConfigurations_fn).call(this, {
953
+ state,
954
+ mode: "update",
955
+ networkFields: fields,
956
+ networkConfigurationToPersist: updatedNetworkConfiguration,
957
+ existingNetworkConfiguration
958
+ });
959
+ });
960
+ }
961
+ __privateMethod(this, _unregisterNetworkClientsAsNeeded, unregisterNetworkClientsAsNeeded_fn).call(this, {
962
+ networkClientOperations,
963
+ autoManagedNetworkClientRegistry
964
+ });
965
+ return updatedNetworkConfiguration;
966
+ }
967
+ /**
968
+ * Destroys and unregisters the network identified by the given chain ID, also
969
+ * removing the associated network configuration from state.
970
+ *
971
+ * @param chainId - The chain ID associated with an existing network.
972
+ * @throws if `chainId` does not refer to an existing network configuration,
973
+ * or if the currently selected network is being removed.
974
+ * @see {@link NetworkConfiguration}
975
+ */
976
+ removeNetwork(chainId) {
977
+ const existingNetworkConfiguration = this.state.networkConfigurationsByChainId[chainId];
978
+ if (existingNetworkConfiguration === void 0) {
979
+ throw new Error(
980
+ `Cannot find network configuration for chain ${inspect(chainId)}`
981
+ );
982
+ }
983
+ if (existingNetworkConfiguration.rpcEndpoints.some(
984
+ (rpcEndpoint) => rpcEndpoint.networkClientId === this.state.selectedNetworkClientId
985
+ )) {
986
+ throw new Error(`Cannot remove the currently selected network`);
987
+ }
988
+ const autoManagedNetworkClientRegistry = __privateMethod(this, _ensureAutoManagedNetworkClientRegistryPopulated, ensureAutoManagedNetworkClientRegistryPopulated_fn).call(this);
989
+ const networkClientOperations = existingNetworkConfiguration.rpcEndpoints.map((rpcEndpoint) => {
990
+ return {
991
+ type: "remove",
992
+ rpcEndpoint
993
+ };
994
+ });
995
+ __privateMethod(this, _unregisterNetworkClientsAsNeeded, unregisterNetworkClientsAsNeeded_fn).call(this, {
996
+ networkClientOperations,
997
+ autoManagedNetworkClientRegistry
998
+ });
999
+ this.update((state) => {
1000
+ __privateMethod(this, _updateNetworkConfigurations, updateNetworkConfigurations_fn).call(this, {
1001
+ state,
1002
+ mode: "remove",
1003
+ existingNetworkConfiguration
1004
+ });
1005
+ });
1006
+ }
1007
+ /**
1008
+ * Assuming that the network has been previously switched, switches to this
1009
+ * new network.
1010
+ *
1011
+ * If the network has not been previously switched, this method is equivalent
1012
+ * to {@link resetConnection}.
1013
+ */
1014
+ async rollbackToPreviousProvider() {
1015
+ await __privateMethod(this, _refreshNetwork, refreshNetwork_fn).call(this, __privateGet(this, _previouslySelectedNetworkClientId));
1016
+ }
1017
+ /**
1018
+ * Deactivates the controller, stopping any ongoing polling.
1019
+ *
1020
+ * In-progress requests will not be aborted.
1021
+ */
1022
+ async destroy() {
1023
+ await __privateGet(this, _blockTrackerProxy)?.destroy();
1024
+ }
1025
+ /**
1026
+ * Merges the given backup data into controller state.
1027
+ *
1028
+ * @param backup - The data that has been backed up.
1029
+ * @param backup.networkConfigurationsByChainId - Network configurations,
1030
+ * keyed by chain ID.
1031
+ */
1032
+ loadBackup({
1033
+ networkConfigurationsByChainId
1034
+ }) {
1035
+ this.update((state) => {
1036
+ state.networkConfigurationsByChainId = {
1037
+ ...state.networkConfigurationsByChainId,
1038
+ ...networkConfigurationsByChainId
1039
+ };
1040
+ });
1041
+ }
1042
+ /**
1043
+ * Searches for a network configuration ID with the given ChainID and returns it.
1044
+ *
1045
+ * @param chainId - ChainId to search for
1046
+ * @returns networkClientId of the network configuration with the given chainId
1047
+ */
1048
+ findNetworkClientIdByChainId(chainId) {
1049
+ const networkClients = this.getNetworkClientRegistry();
1050
+ const networkClientEntry = Object.entries(networkClients).find(
1051
+ ([_, networkClient]) => networkClient.configuration.chainId === chainId
1052
+ );
1053
+ if (networkClientEntry === void 0) {
1054
+ throw new Error("Couldn't find networkClientId for chainId");
1055
+ }
1056
+ return networkClientEntry[0];
1057
+ }
1058
+ };
1059
+ _ethQuery = new WeakMap();
1060
+ _infuraProjectId = new WeakMap();
1061
+ _previouslySelectedNetworkClientId = new WeakMap();
1062
+ _providerProxy = new WeakMap();
1063
+ _blockTrackerProxy = new WeakMap();
1064
+ _autoManagedNetworkClientRegistry = new WeakMap();
1065
+ _autoManagedNetworkClient = new WeakMap();
1066
+ _log = new WeakMap();
1067
+ _networkConfigurationsByNetworkClientId = new WeakMap();
1068
+ _refreshNetwork = new WeakSet();
1069
+ refreshNetwork_fn = async function(networkClientId, options = {}) {
1070
+ this.messagingSystem.publish(
1071
+ "NetworkController:networkWillChange",
1072
+ this.state
1073
+ );
1074
+ __privateMethod(this, _applyNetworkSelection, applyNetworkSelection_fn).call(this, networkClientId, options);
1075
+ this.messagingSystem.publish(
1076
+ "NetworkController:networkDidChange",
1077
+ this.state
1078
+ );
1079
+ await this.lookupNetwork();
1080
+ };
1081
+ _getLatestBlock = new WeakSet();
1082
+ getLatestBlock_fn = function(networkClientId) {
1083
+ if (networkClientId === void 0) {
1084
+ networkClientId = this.state.selectedNetworkClientId;
1085
+ }
1086
+ const networkClient = this.getNetworkClientById(networkClientId);
1087
+ const ethQuery = new EthQuery(networkClient.provider);
1088
+ return new Promise((resolve, reject) => {
1089
+ ethQuery.sendAsync(
1090
+ { method: "eth_getBlockByNumber", params: ["latest", false] },
1091
+ (error, block) => {
1092
+ if (error) {
1093
+ reject(error);
1094
+ } else {
1095
+ resolve(block);
1096
+ }
1097
+ }
1098
+ );
1099
+ });
1100
+ };
1101
+ _determineEIP1559Compatibility = new WeakSet();
1102
+ determineEIP1559Compatibility_fn = async function(networkClientId) {
1103
+ const latestBlock = await __privateMethod(this, _getLatestBlock, getLatestBlock_fn).call(this, networkClientId);
1104
+ if (!latestBlock) {
1105
+ return void 0;
1106
+ }
1107
+ return latestBlock.baseFeePerGas !== void 0;
1108
+ };
1109
+ _validateNetworkFields = new WeakSet();
1110
+ validateNetworkFields_fn = function(args) {
1111
+ const { mode, networkFields, autoManagedNetworkClientRegistry } = args;
1112
+ const existingNetworkConfiguration = "existingNetworkConfiguration" in args ? args.existingNetworkConfiguration : null;
1113
+ const errorMessagePrefix = mode === "update" ? "Could not update network" : "Could not add network";
1114
+ if (!isStrictHexString(networkFields.chainId) || !isSafeChainId(networkFields.chainId)) {
1115
+ throw new Error(
1116
+ `${errorMessagePrefix}: Invalid \`chainId\` ${inspect(
1117
+ networkFields.chainId
1118
+ )} (must start with "0x" and not exceed the maximum)`
1119
+ );
1120
+ }
1121
+ if (existingNetworkConfiguration === null || networkFields.chainId !== existingNetworkConfiguration.chainId) {
1122
+ const existingNetworkConfigurationViaChainId = this.state.networkConfigurationsByChainId[networkFields.chainId];
1123
+ if (existingNetworkConfigurationViaChainId !== void 0) {
1124
+ if (existingNetworkConfiguration === null) {
1125
+ throw new Error(
1126
+ // False negative - these are strings.
1127
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
1128
+ `Could not add network for chain ${args.networkFields.chainId} as another network for that chain already exists ('${existingNetworkConfigurationViaChainId.name}')`
1129
+ );
1130
+ } else {
1131
+ throw new Error(
1132
+ // False negative - these are strings.
1133
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
1134
+ `Cannot move network from chain ${existingNetworkConfiguration.chainId} to ${networkFields.chainId} as another network for that chain already exists ('${existingNetworkConfigurationViaChainId.name}')`
1135
+ );
1136
+ }
1137
+ }
1138
+ }
1139
+ const isInvalidDefaultBlockExplorerUrlIndex = networkFields.blockExplorerUrls.length > 0 ? networkFields.defaultBlockExplorerUrlIndex === void 0 || networkFields.blockExplorerUrls[networkFields.defaultBlockExplorerUrlIndex] === void 0 : networkFields.defaultBlockExplorerUrlIndex !== void 0;
1140
+ if (isInvalidDefaultBlockExplorerUrlIndex) {
1141
+ throw new Error(
1142
+ `${errorMessagePrefix}: \`defaultBlockExplorerUrlIndex\` must refer to an entry in \`blockExplorerUrls\``
1143
+ );
1144
+ }
1145
+ if (networkFields.rpcEndpoints.length === 0) {
1146
+ throw new Error(
1147
+ `${errorMessagePrefix}: \`rpcEndpoints\` must be a non-empty array`
1148
+ );
1149
+ }
1150
+ for (const rpcEndpointFields of networkFields.rpcEndpoints) {
1151
+ if (!isValidUrl(rpcEndpointFields.url)) {
1152
+ throw new Error(
1153
+ `${errorMessagePrefix}: An entry in \`rpcEndpoints\` has invalid URL ${inspect(
1154
+ rpcEndpointFields.url
1155
+ )}`
1156
+ );
1157
+ }
1158
+ const networkClientId = "networkClientId" in rpcEndpointFields ? rpcEndpointFields.networkClientId : void 0;
1159
+ if (rpcEndpointFields.type === "custom" /* Custom */ && networkClientId !== void 0 && isInfuraNetworkType(networkClientId)) {
1160
+ throw new Error(
1161
+ // This is a string.
1162
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
1163
+ `${errorMessagePrefix}: Custom RPC endpoint '${rpcEndpointFields.url}' has invalid network client ID '${networkClientId}'`
1164
+ );
1165
+ }
1166
+ if (mode === "update" && networkClientId !== void 0 && rpcEndpointFields.type === "custom" /* Custom */ && !Object.values(autoManagedNetworkClientRegistry).some(
1167
+ (networkClientsById) => networkClientId in networkClientsById
1168
+ )) {
1169
+ throw new Error(
1170
+ `${errorMessagePrefix}: RPC endpoint '${// This is a string.
1171
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
1172
+ rpcEndpointFields.url}' refers to network client ${inspect(
1173
+ networkClientId
1174
+ )} that does not exist`
1175
+ );
1176
+ }
1177
+ if (networkFields.rpcEndpoints.some(
1178
+ (otherRpcEndpointFields) => otherRpcEndpointFields !== rpcEndpointFields && URI.equal(otherRpcEndpointFields.url, rpcEndpointFields.url)
1179
+ )) {
1180
+ throw new Error(
1181
+ `${errorMessagePrefix}: Each entry in rpcEndpoints must have a unique URL`
1182
+ );
1183
+ }
1184
+ const networkConfigurationsForOtherChains = Object.values(
1185
+ this.state.networkConfigurationsByChainId
1186
+ ).filter(
1187
+ (networkConfiguration) => existingNetworkConfiguration ? networkConfiguration.chainId !== existingNetworkConfiguration.chainId : true
1188
+ );
1189
+ for (const networkConfiguration of networkConfigurationsForOtherChains) {
1190
+ const rpcEndpoint = networkConfiguration.rpcEndpoints.find(
1191
+ (existingRpcEndpoint) => URI.equal(rpcEndpointFields.url, existingRpcEndpoint.url)
1192
+ );
1193
+ if (rpcEndpoint) {
1194
+ throw new Error(
1195
+ mode === "update" ? (
1196
+ // False negative - these are strings.
1197
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
1198
+ `Could not update network to point to same RPC endpoint as existing network for chain ${networkConfiguration.chainId} ('${networkConfiguration.name}')`
1199
+ ) : (
1200
+ // False negative - these are strings.
1201
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
1202
+ `Could not add network that points to same RPC endpoint as existing network for chain ${networkConfiguration.chainId} ('${networkConfiguration.name}')`
1203
+ )
1204
+ );
1205
+ }
1206
+ }
1207
+ }
1208
+ if ([...new Set(networkFields.rpcEndpoints)].length < networkFields.rpcEndpoints.length) {
1209
+ throw new Error(
1210
+ `${errorMessagePrefix}: Each entry in rpcEndpoints must be unique`
1211
+ );
1212
+ }
1213
+ const networkClientIds = networkFields.rpcEndpoints.map(
1214
+ (rpcEndpoint) => "networkClientId" in rpcEndpoint ? rpcEndpoint.networkClientId : void 0
1215
+ ).filter(
1216
+ (networkClientId) => networkClientId !== void 0
1217
+ );
1218
+ if ([...new Set(networkClientIds)].length < networkClientIds.length) {
1219
+ throw new Error(
1220
+ `${errorMessagePrefix}: Each entry in rpcEndpoints must have a unique networkClientId`
1221
+ );
1222
+ }
1223
+ const infuraRpcEndpoints = networkFields.rpcEndpoints.filter(
1224
+ (rpcEndpointFields) => rpcEndpointFields.type === "infura" /* Infura */
1225
+ );
1226
+ if (infuraRpcEndpoints.length > 1) {
1227
+ throw new Error(
1228
+ `${errorMessagePrefix}: There cannot be more than one Infura RPC endpoint`
1229
+ );
1230
+ }
1231
+ const soleInfuraRpcEndpoint = infuraRpcEndpoints[0];
1232
+ if (soleInfuraRpcEndpoint) {
1233
+ const infuraNetworkName = deriveInfuraNetworkNameFromRpcEndpointUrl(
1234
+ soleInfuraRpcEndpoint.url
1235
+ );
1236
+ const infuraNetworkNickname = NetworkNickname[infuraNetworkName];
1237
+ const infuraChainId = ChainId[infuraNetworkName];
1238
+ if (networkFields.chainId !== infuraChainId) {
1239
+ throw new Error(
1240
+ mode === "add" ? (
1241
+ // This is a string.
1242
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
1243
+ `Could not add network with chain ID ${networkFields.chainId} and Infura RPC endpoint for '${infuraNetworkNickname}' which represents ${infuraChainId}, as the two conflict`
1244
+ ) : (
1245
+ // This is a string.
1246
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
1247
+ `Could not update network with chain ID ${networkFields.chainId} and Infura RPC endpoint for '${infuraNetworkNickname}' which represents ${infuraChainId}, as the two conflict`
1248
+ )
1249
+ );
1250
+ }
1251
+ }
1252
+ if (networkFields.rpcEndpoints[networkFields.defaultRpcEndpointIndex] === void 0) {
1253
+ throw new Error(
1254
+ `${errorMessagePrefix}: \`defaultRpcEndpointIndex\` must refer to an entry in \`rpcEndpoints\``
1255
+ );
1256
+ }
1257
+ };
1258
+ _determineNetworkConfigurationToPersist = new WeakSet();
1259
+ determineNetworkConfigurationToPersist_fn = function({
1260
+ networkFields,
1261
+ networkClientOperations
1262
+ }) {
1263
+ const rpcEndpointsToPersist = networkClientOperations.filter(
1264
+ (networkClientOperation) => {
1265
+ return networkClientOperation.type === "add" || networkClientOperation.type === "noop";
1266
+ }
1267
+ ).map((networkClientOperation) => networkClientOperation.rpcEndpoint).concat(
1268
+ networkClientOperations.filter(
1269
+ (networkClientOperation) => {
1270
+ return networkClientOperation.type === "replace";
1271
+ }
1272
+ ).map(
1273
+ (networkClientOperation) => networkClientOperation.newRpcEndpoint
1274
+ )
1275
+ );
1276
+ return { ...networkFields, rpcEndpoints: rpcEndpointsToPersist };
1277
+ };
1278
+ _registerNetworkClientsAsNeeded = new WeakSet();
1279
+ registerNetworkClientsAsNeeded_fn = function({
1280
+ networkFields,
1281
+ networkClientOperations,
1282
+ autoManagedNetworkClientRegistry
1283
+ }) {
1284
+ const addedRpcEndpoints = networkClientOperations.filter(
1285
+ (networkClientOperation) => {
1286
+ return networkClientOperation.type === "add";
1287
+ }
1288
+ ).map((networkClientOperation) => networkClientOperation.rpcEndpoint).concat(
1289
+ networkClientOperations.filter(
1290
+ (networkClientOperation) => {
1291
+ return networkClientOperation.type === "replace";
1292
+ }
1293
+ ).map(
1294
+ (networkClientOperation) => networkClientOperation.newRpcEndpoint
1295
+ )
1296
+ );
1297
+ for (const addedRpcEndpoint of addedRpcEndpoints) {
1298
+ if (addedRpcEndpoint.type === "infura" /* Infura */) {
1299
+ autoManagedNetworkClientRegistry["infura" /* Infura */][addedRpcEndpoint.networkClientId] = createAutoManagedNetworkClient({
1300
+ type: "infura" /* Infura */,
1301
+ chainId: networkFields.chainId,
1302
+ network: addedRpcEndpoint.networkClientId,
1303
+ infuraProjectId: __privateGet(this, _infuraProjectId),
1304
+ ticker: networkFields.nativeCurrency
1305
+ });
1306
+ } else {
1307
+ autoManagedNetworkClientRegistry["custom" /* Custom */][addedRpcEndpoint.networkClientId] = createAutoManagedNetworkClient({
1308
+ type: "custom" /* Custom */,
1309
+ chainId: networkFields.chainId,
1310
+ rpcUrl: addedRpcEndpoint.url,
1311
+ ticker: networkFields.nativeCurrency
1312
+ });
1313
+ }
1314
+ }
1315
+ };
1316
+ _unregisterNetworkClientsAsNeeded = new WeakSet();
1317
+ unregisterNetworkClientsAsNeeded_fn = function({
1318
+ networkClientOperations,
1319
+ autoManagedNetworkClientRegistry
1320
+ }) {
1321
+ const removedRpcEndpoints = networkClientOperations.filter(
1322
+ (networkClientOperation) => {
1323
+ return networkClientOperation.type === "remove";
1324
+ }
1325
+ ).map((networkClientOperation) => networkClientOperation.rpcEndpoint).concat(
1326
+ networkClientOperations.filter(
1327
+ (networkClientOperation) => {
1328
+ return networkClientOperation.type === "replace";
1329
+ }
1330
+ ).map(
1331
+ (networkClientOperation) => networkClientOperation.oldRpcEndpoint
1332
+ )
1333
+ );
1334
+ for (const rpcEndpoint of removedRpcEndpoints) {
1335
+ const networkClient = this.getNetworkClientById(
1336
+ rpcEndpoint.networkClientId
1337
+ );
1338
+ networkClient.destroy();
1339
+ delete autoManagedNetworkClientRegistry[networkClient.configuration.type][rpcEndpoint.networkClientId];
1340
+ }
1341
+ };
1342
+ _updateNetworkConfigurations = new WeakSet();
1343
+ updateNetworkConfigurations_fn = function(args) {
1344
+ const { state, mode } = args;
1345
+ if (mode === "remove" || mode === "update" && args.networkFields.chainId !== args.existingNetworkConfiguration.chainId) {
1346
+ delete state.networkConfigurationsByChainId[args.existingNetworkConfiguration.chainId];
1347
+ }
1348
+ if (mode === "add" || mode === "update") {
1349
+ state.networkConfigurationsByChainId[args.networkFields.chainId] = args.networkConfigurationToPersist;
1350
+ }
1351
+ __privateSet(this, _networkConfigurationsByNetworkClientId, buildNetworkConfigurationsByNetworkClientId(
1352
+ state.networkConfigurationsByChainId
1353
+ ));
1354
+ };
1355
+ _ensureAutoManagedNetworkClientRegistryPopulated = new WeakSet();
1356
+ ensureAutoManagedNetworkClientRegistryPopulated_fn = function() {
1357
+ return __privateGet(this, _autoManagedNetworkClientRegistry) ?? __privateSet(this, _autoManagedNetworkClientRegistry, __privateMethod(this, _createAutoManagedNetworkClientRegistry, createAutoManagedNetworkClientRegistry_fn).call(this));
1358
+ };
1359
+ _createAutoManagedNetworkClientRegistry = new WeakSet();
1360
+ createAutoManagedNetworkClientRegistry_fn = function() {
1361
+ const chainIds = knownKeysOf(this.state.networkConfigurationsByChainId);
1362
+ const networkClientsWithIds = chainIds.flatMap((chainId) => {
1363
+ const networkConfiguration = this.state.networkConfigurationsByChainId[chainId];
1364
+ return networkConfiguration.rpcEndpoints.map((rpcEndpoint) => {
1365
+ if (rpcEndpoint.type === "infura" /* Infura */) {
1366
+ const infuraNetworkName = deriveInfuraNetworkNameFromRpcEndpointUrl(
1367
+ rpcEndpoint.url
1368
+ );
1369
+ return [
1370
+ rpcEndpoint.networkClientId,
1371
+ createAutoManagedNetworkClient({
1372
+ type: "infura" /* Infura */,
1373
+ network: infuraNetworkName,
1374
+ infuraProjectId: __privateGet(this, _infuraProjectId),
1375
+ chainId: networkConfiguration.chainId,
1376
+ ticker: networkConfiguration.nativeCurrency
1377
+ })
1378
+ ];
1379
+ }
1380
+ return [
1381
+ rpcEndpoint.networkClientId,
1382
+ createAutoManagedNetworkClient({
1383
+ type: "custom" /* Custom */,
1384
+ chainId: networkConfiguration.chainId,
1385
+ rpcUrl: rpcEndpoint.url,
1386
+ ticker: networkConfiguration.nativeCurrency
1387
+ })
1388
+ ];
1389
+ });
1390
+ });
1391
+ return networkClientsWithIds.reduce(
1392
+ (obj, [networkClientId, networkClient]) => {
1393
+ return {
1394
+ ...obj,
1395
+ [networkClient.configuration.type]: {
1396
+ ...obj[networkClient.configuration.type],
1397
+ [networkClientId]: networkClient
1398
+ }
1399
+ };
1400
+ },
1401
+ {
1402
+ ["custom" /* Custom */]: {},
1403
+ ["infura" /* Infura */]: {}
1404
+ }
1405
+ );
1406
+ };
1407
+ _applyNetworkSelection = new WeakSet();
1408
+ applyNetworkSelection_fn = function(networkClientId, {
1409
+ updateState
1410
+ } = {}) {
1411
+ const autoManagedNetworkClientRegistry = __privateMethod(this, _ensureAutoManagedNetworkClientRegistryPopulated, ensureAutoManagedNetworkClientRegistryPopulated_fn).call(this);
1412
+ let autoManagedNetworkClient;
1413
+ if (isInfuraNetworkType(networkClientId)) {
1414
+ const possibleAutoManagedNetworkClient = autoManagedNetworkClientRegistry["infura" /* Infura */][networkClientId];
1415
+ if (!possibleAutoManagedNetworkClient) {
1416
+ throw new Error(
1417
+ `No Infura network client found with ID ${inspect(networkClientId)}`
1418
+ );
1419
+ }
1420
+ autoManagedNetworkClient = possibleAutoManagedNetworkClient;
1421
+ } else {
1422
+ const possibleAutoManagedNetworkClient = autoManagedNetworkClientRegistry["custom" /* Custom */][networkClientId];
1423
+ if (!possibleAutoManagedNetworkClient) {
1424
+ throw new Error(
1425
+ `No network client found with ID ${inspect(networkClientId)}`
1426
+ );
1427
+ }
1428
+ autoManagedNetworkClient = possibleAutoManagedNetworkClient;
1429
+ }
1430
+ __privateSet(this, _autoManagedNetworkClient, autoManagedNetworkClient);
1431
+ this.update((state) => {
1432
+ state.selectedNetworkClientId = networkClientId;
1433
+ if (state.networksMetadata[networkClientId] === void 0) {
1434
+ state.networksMetadata[networkClientId] = {
1435
+ status: "unknown" /* Unknown */,
1436
+ EIPS: {}
1437
+ };
1438
+ }
1439
+ updateState?.(state);
1440
+ });
1441
+ if (__privateGet(this, _providerProxy)) {
1442
+ __privateGet(this, _providerProxy).setTarget(__privateGet(this, _autoManagedNetworkClient).provider);
1443
+ } else {
1444
+ __privateSet(this, _providerProxy, createEventEmitterProxy(
1445
+ __privateGet(this, _autoManagedNetworkClient).provider
1446
+ ));
1447
+ }
1448
+ if (__privateGet(this, _blockTrackerProxy)) {
1449
+ __privateGet(this, _blockTrackerProxy).setTarget(
1450
+ __privateGet(this, _autoManagedNetworkClient).blockTracker
1451
+ );
1452
+ } else {
1453
+ __privateSet(this, _blockTrackerProxy, createEventEmitterProxy(
1454
+ __privateGet(this, _autoManagedNetworkClient).blockTracker,
1455
+ { eventFilter: "skipInternal" }
1456
+ ));
1457
+ }
1458
+ __privateSet(this, _ethQuery, new EthQuery(__privateGet(this, _providerProxy)));
1459
+ };
1460
+
1461
+ export {
1462
+ RpcEndpointType,
1463
+ knownKeysOf,
1464
+ getDefaultNetworkControllerState,
1465
+ NetworkController
1466
+ };
1467
+ //# sourceMappingURL=chunk-YJXBTFAE.mjs.map