@metamask-previews/network-controller 36.0.0-preview-8bfa290fb → 37.0.0-preview-0a30e47
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 +24 -3
- package/dist/{NetworkController-method-action-types.d.mts → NetworkController-method-action-types.d.ts} +2 -2
- package/dist/NetworkController-method-action-types.d.ts.map +1 -0
- package/dist/{NetworkController-method-action-types.mjs → NetworkController-method-action-types.js} +1 -1
- package/dist/NetworkController-method-action-types.js.map +1 -0
- package/dist/{NetworkController.d.cts → NetworkController.d.ts} +37 -29
- package/dist/NetworkController.d.ts.map +1 -0
- package/dist/{NetworkController.mjs → NetworkController.js} +717 -615
- package/dist/NetworkController.js.map +1 -0
- package/dist/{constants.d.cts → constants.d.ts} +1 -1
- package/dist/constants.d.ts.map +1 -0
- package/dist/{constants.mjs → constants.js} +1 -1
- package/dist/constants.js.map +1 -0
- package/dist/{create-auto-managed-network-client.d.cts → create-auto-managed-network-client.d.ts} +7 -7
- package/dist/create-auto-managed-network-client.d.ts.map +1 -0
- package/dist/{create-auto-managed-network-client.mjs → create-auto-managed-network-client.js} +4 -4
- package/dist/create-auto-managed-network-client.js.map +1 -0
- package/dist/{create-network-client.d.cts → create-network-client.d.ts} +7 -7
- package/dist/create-network-client.d.ts.map +1 -0
- package/dist/{create-network-client.mjs → create-network-client.js} +17 -14
- package/dist/create-network-client.js.map +1 -0
- package/dist/{index.d.cts → index.d.ts} +16 -16
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/logger.d.ts +4 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +4 -0
- package/dist/logger.js.map +1 -0
- package/dist/rpc-service/{abstract-rpc-service.d.cts → abstract-rpc-service.d.ts} +2 -2
- package/dist/rpc-service/abstract-rpc-service.d.ts.map +1 -0
- package/dist/rpc-service/abstract-rpc-service.js +2 -0
- package/dist/rpc-service/abstract-rpc-service.js.map +1 -0
- package/dist/rpc-service/{rpc-service-chain.d.cts → rpc-service-chain.d.ts} +6 -6
- package/dist/rpc-service/rpc-service-chain.d.ts.map +1 -0
- package/dist/rpc-service/{rpc-service-chain.mjs → rpc-service-chain.js} +57 -70
- package/dist/rpc-service/rpc-service-chain.js.map +1 -0
- package/dist/rpc-service/{rpc-service-requestable.d.cts → rpc-service-requestable.d.ts} +4 -4
- package/dist/rpc-service/rpc-service-requestable.d.ts.map +1 -0
- package/dist/rpc-service/rpc-service-requestable.js +2 -0
- package/dist/rpc-service/rpc-service-requestable.js.map +1 -0
- package/dist/rpc-service/{rpc-service.d.mts → rpc-service.d.ts} +6 -6
- package/dist/rpc-service/rpc-service.d.ts.map +1 -0
- package/dist/rpc-service/{rpc-service.mjs → rpc-service.js} +206 -197
- package/dist/rpc-service/rpc-service.js.map +1 -0
- package/dist/rpc-service/{shared.d.cts → shared.d.ts} +2 -2
- package/dist/rpc-service/shared.d.ts.map +1 -0
- package/dist/rpc-service/shared.js +2 -0
- package/dist/rpc-service/shared.js.map +1 -0
- package/dist/{rpc-service-analytics.d.mts → rpc-service-analytics.d.ts} +3 -3
- package/dist/rpc-service-analytics.d.ts.map +1 -0
- package/dist/{rpc-service-analytics.mjs → rpc-service-analytics.js} +4 -4
- package/dist/rpc-service-analytics.js.map +1 -0
- package/dist/{selectors.d.mts → selectors.d.ts} +2 -2
- package/dist/selectors.d.ts.map +1 -0
- package/dist/{selectors.mjs → selectors.js} +1 -1
- package/dist/selectors.js.map +1 -0
- package/dist/{types.d.cts → types.d.ts} +5 -5
- package/dist/types.d.ts.map +1 -0
- package/dist/{types.mjs → types.js} +1 -1
- package/dist/types.js.map +1 -0
- package/package.json +26 -30
- package/dist/NetworkController-method-action-types.cjs +0 -7
- package/dist/NetworkController-method-action-types.cjs.map +0 -1
- package/dist/NetworkController-method-action-types.d.cts +0 -268
- package/dist/NetworkController-method-action-types.d.cts.map +0 -1
- package/dist/NetworkController-method-action-types.d.mts.map +0 -1
- package/dist/NetworkController-method-action-types.mjs.map +0 -1
- package/dist/NetworkController.cjs +0 -1599
- package/dist/NetworkController.cjs.map +0 -1
- package/dist/NetworkController.d.cts.map +0 -1
- package/dist/NetworkController.d.mts +0 -956
- package/dist/NetworkController.d.mts.map +0 -1
- package/dist/NetworkController.mjs.map +0 -1
- package/dist/constants.cjs +0 -46
- package/dist/constants.cjs.map +0 -1
- package/dist/constants.d.cts.map +0 -1
- package/dist/constants.d.mts +0 -42
- package/dist/constants.d.mts.map +0 -1
- package/dist/constants.mjs.map +0 -1
- package/dist/create-auto-managed-network-client.cjs +0 -149
- package/dist/create-auto-managed-network-client.cjs.map +0 -1
- package/dist/create-auto-managed-network-client.d.cts.map +0 -1
- package/dist/create-auto-managed-network-client.d.mts +0 -74
- package/dist/create-auto-managed-network-client.d.mts.map +0 -1
- package/dist/create-auto-managed-network-client.mjs.map +0 -1
- package/dist/create-network-client.cjs +0 -439
- package/dist/create-network-client.cjs.map +0 -1
- package/dist/create-network-client.d.cts.map +0 -1
- package/dist/create-network-client.d.mts +0 -60
- package/dist/create-network-client.d.mts.map +0 -1
- package/dist/create-network-client.mjs.map +0 -1
- package/dist/index.cjs +0 -31
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts.map +0 -1
- package/dist/index.d.mts +0 -16
- package/dist/index.d.mts.map +0 -1
- package/dist/index.mjs +0 -6
- package/dist/index.mjs.map +0 -1
- package/dist/logger.cjs +0 -7
- package/dist/logger.cjs.map +0 -1
- package/dist/logger.d.cts +0 -5
- package/dist/logger.d.cts.map +0 -1
- package/dist/logger.d.mts +0 -5
- package/dist/logger.d.mts.map +0 -1
- package/dist/logger.mjs +0 -4
- package/dist/logger.mjs.map +0 -1
- package/dist/rpc-service/abstract-rpc-service.cjs +0 -3
- package/dist/rpc-service/abstract-rpc-service.cjs.map +0 -1
- package/dist/rpc-service/abstract-rpc-service.d.cts.map +0 -1
- package/dist/rpc-service/abstract-rpc-service.d.mts +0 -17
- package/dist/rpc-service/abstract-rpc-service.d.mts.map +0 -1
- package/dist/rpc-service/abstract-rpc-service.mjs +0 -2
- package/dist/rpc-service/abstract-rpc-service.mjs.map +0 -1
- package/dist/rpc-service/rpc-service-chain.cjs +0 -304
- package/dist/rpc-service/rpc-service-chain.cjs.map +0 -1
- package/dist/rpc-service/rpc-service-chain.d.cts.map +0 -1
- package/dist/rpc-service/rpc-service-chain.d.mts +0 -169
- package/dist/rpc-service/rpc-service-chain.d.mts.map +0 -1
- package/dist/rpc-service/rpc-service-chain.mjs.map +0 -1
- package/dist/rpc-service/rpc-service-requestable.cjs +0 -3
- package/dist/rpc-service/rpc-service-requestable.cjs.map +0 -1
- package/dist/rpc-service/rpc-service-requestable.d.cts.map +0 -1
- package/dist/rpc-service/rpc-service-requestable.d.mts +0 -63
- package/dist/rpc-service/rpc-service-requestable.d.mts.map +0 -1
- package/dist/rpc-service/rpc-service-requestable.mjs +0 -2
- package/dist/rpc-service/rpc-service-requestable.mjs.map +0 -1
- package/dist/rpc-service/rpc-service.cjs +0 -540
- package/dist/rpc-service/rpc-service.cjs.map +0 -1
- package/dist/rpc-service/rpc-service.d.cts +0 -247
- package/dist/rpc-service/rpc-service.d.cts.map +0 -1
- package/dist/rpc-service/rpc-service.d.mts.map +0 -1
- package/dist/rpc-service/rpc-service.mjs.map +0 -1
- package/dist/rpc-service/shared.cjs +0 -3
- package/dist/rpc-service/shared.cjs.map +0 -1
- package/dist/rpc-service/shared.d.cts.map +0 -1
- package/dist/rpc-service/shared.d.mts +0 -32
- package/dist/rpc-service/shared.d.mts.map +0 -1
- package/dist/rpc-service/shared.mjs +0 -2
- package/dist/rpc-service/shared.mjs.map +0 -1
- package/dist/rpc-service-analytics.cjs +0 -180
- package/dist/rpc-service-analytics.cjs.map +0 -1
- package/dist/rpc-service-analytics.d.cts +0 -85
- package/dist/rpc-service-analytics.d.cts.map +0 -1
- package/dist/rpc-service-analytics.d.mts.map +0 -1
- package/dist/rpc-service-analytics.mjs.map +0 -1
- package/dist/selectors.cjs +0 -16
- package/dist/selectors.cjs.map +0 -1
- package/dist/selectors.d.cts +0 -22
- package/dist/selectors.d.cts.map +0 -1
- package/dist/selectors.d.mts.map +0 -1
- package/dist/selectors.mjs.map +0 -1
- package/dist/types.cjs +0 -12
- package/dist/types.cjs.map +0 -1
- package/dist/types.d.cts.map +0 -1
- package/dist/types.d.mts +0 -49
- package/dist/types.d.mts.map +0 -1
- package/dist/types.mjs.map +0 -1
|
@@ -1,956 +0,0 @@
|
|
|
1
|
-
import type { AnalyticsControllerGetStateAction, AnalyticsControllerTrackEventAction } from "@metamask/analytics-controller";
|
|
2
|
-
import type { ControllerGetStateAction, ControllerStateChangeEvent } from "@metamask/base-controller";
|
|
3
|
-
import { BaseController } from "@metamask/base-controller";
|
|
4
|
-
import type { ConfigRegistryControllerStateChangedEvent, ConfigRegistryControllerGetNetworkConfigByCaip2ChainIdAction, ConfigRegistryControllerGetStateAction } from "@metamask/config-registry-controller";
|
|
5
|
-
import type { ConnectivityControllerGetStateAction } from "@metamask/connectivity-controller";
|
|
6
|
-
import type { Partialize } from "@metamask/controller-utils";
|
|
7
|
-
import { InfuraNetworkType } from "@metamask/controller-utils";
|
|
8
|
-
import type { PollingBlockTrackerOptions } from "@metamask/eth-block-tracker";
|
|
9
|
-
import EthQuery from "@metamask/eth-query";
|
|
10
|
-
import type { Messenger } from "@metamask/messenger";
|
|
11
|
-
import { RemoteFeatureFlagControllerGetStateAction, RemoteFeatureFlagControllerStateChangeEvent } from "@metamask/remote-feature-flag-controller";
|
|
12
|
-
import type { SwappableProxy } from "@metamask/swappable-obj-proxy";
|
|
13
|
-
import type { Hex } from "@metamask/utils";
|
|
14
|
-
import type { Draft } from "immer";
|
|
15
|
-
import type { Logger } from "loglevel";
|
|
16
|
-
import { NetworkStatus } from "./constants.mjs";
|
|
17
|
-
import type { AutoManagedNetworkClient, ProxyWithAccessibleTarget } from "./create-auto-managed-network-client.mjs";
|
|
18
|
-
import type { DegradedEventType, RetryReason } from "./create-network-client.mjs";
|
|
19
|
-
import type { NetworkControllerMethodActions } from "./NetworkController-method-action-types.mjs";
|
|
20
|
-
import type { NetworkControllerAnalyticsOptions } from "./rpc-service-analytics.mjs";
|
|
21
|
-
import type { RpcServiceOptionsWithDefaults } from "./rpc-service/rpc-service.mjs";
|
|
22
|
-
import { NetworkClientType } from "./types.mjs";
|
|
23
|
-
import type { BlockTracker, Provider, CustomNetworkClientConfiguration, InfuraNetworkClientConfiguration } from "./types.mjs";
|
|
24
|
-
export type Block = {
|
|
25
|
-
baseFeePerGas?: string;
|
|
26
|
-
};
|
|
27
|
-
/**
|
|
28
|
-
* Information about a network not held by any other part of state.
|
|
29
|
-
*/
|
|
30
|
-
export type NetworkMetadata = {
|
|
31
|
-
/**
|
|
32
|
-
* EIPs supported by the network.
|
|
33
|
-
*/
|
|
34
|
-
EIPS: {
|
|
35
|
-
[eipNumber: number]: boolean;
|
|
36
|
-
};
|
|
37
|
-
/**
|
|
38
|
-
* Indicates the availability of the network
|
|
39
|
-
*/
|
|
40
|
-
status: NetworkStatus;
|
|
41
|
-
};
|
|
42
|
-
/**
|
|
43
|
-
* The type of an RPC endpoint.
|
|
44
|
-
*
|
|
45
|
-
* @see {@link CustomRpcEndpoint}
|
|
46
|
-
* @see {@link InfuraRpcEndpoint}
|
|
47
|
-
*/
|
|
48
|
-
export declare enum RpcEndpointType {
|
|
49
|
-
Custom = "custom",
|
|
50
|
-
Infura = "infura"
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* An Infura RPC endpoint is a reference to a specific network that Infura
|
|
54
|
-
* supports as well as an Infura account we own that we allow users to make use
|
|
55
|
-
* of for free. We need to disambiguate these endpoints from custom RPC
|
|
56
|
-
* endpoints, because while the types for these kinds of object both have the
|
|
57
|
-
* same interface, the URL for an Infura endpoint contains the Infura project
|
|
58
|
-
* ID, and we don't want this to be present in state. We therefore hide it by
|
|
59
|
-
* representing it in the URL as `{infuraProjectId}`, which we replace this when
|
|
60
|
-
* create network clients. But we need to know somehow that we only need to do
|
|
61
|
-
* this replacement for Infura endpoints and not custom endpoints — hence the
|
|
62
|
-
* separate type.
|
|
63
|
-
*/
|
|
64
|
-
export type InfuraRpcEndpoint = {
|
|
65
|
-
/**
|
|
66
|
-
* Alternate RPC endpoints to use when this endpoint is down.
|
|
67
|
-
*/
|
|
68
|
-
failoverUrls?: string[];
|
|
69
|
-
/**
|
|
70
|
-
* The optional user-facing nickname of the endpoint.
|
|
71
|
-
*/
|
|
72
|
-
name?: string;
|
|
73
|
-
/**
|
|
74
|
-
* The identifier for the network client that has been created for this RPC
|
|
75
|
-
* endpoint. This is also used to uniquely identify the RPC endpoint in a
|
|
76
|
-
* set of RPC endpoints as well: once assigned, it is used to determine
|
|
77
|
-
* whether the `name`, `type`, or `url` of the RPC endpoint has changed.
|
|
78
|
-
*/
|
|
79
|
-
networkClientId: BuiltInNetworkClientId;
|
|
80
|
-
/**
|
|
81
|
-
* The type of this endpoint, always "default".
|
|
82
|
-
*/
|
|
83
|
-
type: RpcEndpointType.Infura;
|
|
84
|
-
/**
|
|
85
|
-
* The URL of the endpoint. Expected to be a template with the string
|
|
86
|
-
* `{infuraProjectId}`, which will get replaced with the Infura project ID
|
|
87
|
-
* when the network client is created.
|
|
88
|
-
*/
|
|
89
|
-
url: `https://${InfuraNetworkType}.infura.io/v3/{infuraProjectId}`;
|
|
90
|
-
};
|
|
91
|
-
/**
|
|
92
|
-
* A custom RPC endpoint is a reference to a user-defined server which fronts an
|
|
93
|
-
* EVM chain. It may refer to an Infura network, but only by coincidence.
|
|
94
|
-
*/
|
|
95
|
-
export type CustomRpcEndpoint = {
|
|
96
|
-
/**
|
|
97
|
-
* Alternate RPC endpoints to use when this endpoint is down.
|
|
98
|
-
*/
|
|
99
|
-
failoverUrls?: string[];
|
|
100
|
-
/**
|
|
101
|
-
* The optional user-facing nickname of the endpoint.
|
|
102
|
-
*/
|
|
103
|
-
name?: string;
|
|
104
|
-
/**
|
|
105
|
-
* The identifier for the network client that has been created for this RPC
|
|
106
|
-
* endpoint. This is also used to uniquely identify the RPC endpoint in a
|
|
107
|
-
* set of RPC endpoints as well: once assigned, it is used to determine
|
|
108
|
-
* whether the `name`, `type`, or `url` of the RPC endpoint has changed.
|
|
109
|
-
*/
|
|
110
|
-
networkClientId: CustomNetworkClientId;
|
|
111
|
-
/**
|
|
112
|
-
* The type of this endpoint, always "custom".
|
|
113
|
-
*/
|
|
114
|
-
type: RpcEndpointType.Custom;
|
|
115
|
-
/**
|
|
116
|
-
* The URL of the endpoint.
|
|
117
|
-
*/
|
|
118
|
-
url: string;
|
|
119
|
-
};
|
|
120
|
-
/**
|
|
121
|
-
* An RPC endpoint is a reference to a server which fronts an EVM chain. There
|
|
122
|
-
* are two varieties of RPC endpoints: Infura and custom.
|
|
123
|
-
*
|
|
124
|
-
* @see {@link CustomRpcEndpoint}
|
|
125
|
-
* @see {@link InfuraRpcEndpoint}
|
|
126
|
-
*/
|
|
127
|
-
export type RpcEndpoint = InfuraRpcEndpoint | CustomRpcEndpoint;
|
|
128
|
-
/**
|
|
129
|
-
* From a user perspective, a network configuration holds information about a
|
|
130
|
-
* network that a user can select through the client. A "network" in this sense
|
|
131
|
-
* can explicitly refer to an EVM chain that the user explicitly adds or doesn't
|
|
132
|
-
* need to add (because it comes shipped with the client). The properties here
|
|
133
|
-
* therefore directly map to fields that a user sees and can edit for a network
|
|
134
|
-
* within the client.
|
|
135
|
-
*
|
|
136
|
-
* Internally, a network configuration represents a single conceptual EVM chain,
|
|
137
|
-
* which is represented tangibly via multiple RPC endpoints. A "network" is then
|
|
138
|
-
* something for which a network client object is created automatically or
|
|
139
|
-
* created on demand when it is added to the client.
|
|
140
|
-
*/
|
|
141
|
-
export type NetworkConfiguration = {
|
|
142
|
-
/**
|
|
143
|
-
* A set of URLs that allows the user to view activity that has occurred on
|
|
144
|
-
* the chain.
|
|
145
|
-
*/
|
|
146
|
-
blockExplorerUrls: string[];
|
|
147
|
-
/**
|
|
148
|
-
* The ID of the chain. Represented in hexadecimal format with a leading "0x"
|
|
149
|
-
* instead of decimal format so that when viewed out of context it can be
|
|
150
|
-
* unambiguously interpreted.
|
|
151
|
-
*/
|
|
152
|
-
chainId: Hex;
|
|
153
|
-
/**
|
|
154
|
-
* A reference to a URL that the client will use by default to allow the user
|
|
155
|
-
* to view activity that has occurred on the chain. This index must refer to
|
|
156
|
-
* an item in `blockExplorerUrls`.
|
|
157
|
-
*/
|
|
158
|
-
defaultBlockExplorerUrlIndex?: number;
|
|
159
|
-
/**
|
|
160
|
-
* A reference to an RPC endpoint that all requests will use by default in order to
|
|
161
|
-
* interact with the chain. This index must refer to an item in
|
|
162
|
-
* `rpcEndpoints`.
|
|
163
|
-
*/
|
|
164
|
-
defaultRpcEndpointIndex: number;
|
|
165
|
-
/**
|
|
166
|
-
* The user-facing nickname assigned to the chain.
|
|
167
|
-
*/
|
|
168
|
-
name: string;
|
|
169
|
-
/**
|
|
170
|
-
* The name of the currency to use for the chain.
|
|
171
|
-
*/
|
|
172
|
-
nativeCurrency: string;
|
|
173
|
-
/**
|
|
174
|
-
* The collection of possible RPC endpoints that the client can use to
|
|
175
|
-
* interact with the chain.
|
|
176
|
-
*/
|
|
177
|
-
rpcEndpoints: RpcEndpoint[];
|
|
178
|
-
/**
|
|
179
|
-
* Profile Sync - Network Sync field.
|
|
180
|
-
* Allows comparison of local network state with state to sync.
|
|
181
|
-
*/
|
|
182
|
-
lastUpdatedAt?: number;
|
|
183
|
-
};
|
|
184
|
-
/**
|
|
185
|
-
* A custom RPC endpoint in a new network configuration, meant to be used in
|
|
186
|
-
* conjunction with `AddNetworkFields`.
|
|
187
|
-
*
|
|
188
|
-
* Custom RPC endpoints do not need a `networkClientId` property because it is
|
|
189
|
-
* assumed that they have not already been added and therefore network clients
|
|
190
|
-
* do not exist for them yet (and hence IDs need to be generated).
|
|
191
|
-
*/
|
|
192
|
-
export type AddNetworkCustomRpcEndpointFields = Omit<CustomRpcEndpoint, 'networkClientId'>;
|
|
193
|
-
/**
|
|
194
|
-
* A new network configuration that `addNetwork` takes.
|
|
195
|
-
*
|
|
196
|
-
* Custom RPC endpoints do not need a `networkClientId` property because it is
|
|
197
|
-
* assumed that they have not already been added and are not represented by
|
|
198
|
-
* network clients yet.
|
|
199
|
-
*/
|
|
200
|
-
export type AddNetworkFields = Omit<NetworkConfiguration, 'rpcEndpoints'> & {
|
|
201
|
-
rpcEndpoints: (InfuraRpcEndpoint | AddNetworkCustomRpcEndpointFields)[];
|
|
202
|
-
};
|
|
203
|
-
/**
|
|
204
|
-
* A custom RPC endpoint in an updated representation of a network
|
|
205
|
-
* configuration, meant to be used in conjunction with `UpdateNetworkFields`.
|
|
206
|
-
*
|
|
207
|
-
* Custom RPC endpoints do not need a `networkClientId` property because it is
|
|
208
|
-
* assumed that they have not already been added and therefore network clients
|
|
209
|
-
* do not exist for them yet (and hence IDs need to be generated).
|
|
210
|
-
*/
|
|
211
|
-
export type UpdateNetworkCustomRpcEndpointFields = Partialize<CustomRpcEndpoint, 'networkClientId'>;
|
|
212
|
-
/**
|
|
213
|
-
* An updated representation of an existing network configuration that
|
|
214
|
-
* `updateNetwork` takes.
|
|
215
|
-
*
|
|
216
|
-
* Custom RPC endpoints may or may not have a `networkClientId` property; if
|
|
217
|
-
* they do, then it is assumed that they already exist, and if not, then it is
|
|
218
|
-
* assumed that they are new and are not represented by network clients yet.
|
|
219
|
-
*/
|
|
220
|
-
export type UpdateNetworkFields = Omit<NetworkConfiguration, 'rpcEndpoints'> & {
|
|
221
|
-
rpcEndpoints: (InfuraRpcEndpoint | UpdateNetworkCustomRpcEndpointFields)[];
|
|
222
|
-
};
|
|
223
|
-
/**
|
|
224
|
-
* `Object.keys()` is intentionally generic: it returns the keys of an object,
|
|
225
|
-
* but it cannot make guarantees about the contents of that object, so the type
|
|
226
|
-
* of the keys is merely `string[]`. While this is technically accurate, it is
|
|
227
|
-
* also unnecessary if we have an object that we own and whose contents are
|
|
228
|
-
* known exactly.
|
|
229
|
-
*
|
|
230
|
-
* TODO: Move to @metamask/utils.
|
|
231
|
-
*
|
|
232
|
-
* @param object - The object.
|
|
233
|
-
* @returns The keys of an object, typed according to the type of the object
|
|
234
|
-
* itself.
|
|
235
|
-
*/
|
|
236
|
-
export declare function knownKeysOf<Key extends PropertyKey>(object: Partial<Record<Key, any>>): Key[];
|
|
237
|
-
/**
|
|
238
|
-
* The string that uniquely identifies an Infura network client.
|
|
239
|
-
*/
|
|
240
|
-
export type BuiltInNetworkClientId = string;
|
|
241
|
-
/**
|
|
242
|
-
* The string that uniquely identifies a custom network client.
|
|
243
|
-
*/
|
|
244
|
-
export type CustomNetworkClientId = string;
|
|
245
|
-
/**
|
|
246
|
-
* The string that uniquely identifies a network client.
|
|
247
|
-
*/
|
|
248
|
-
export type NetworkClientId = BuiltInNetworkClientId | CustomNetworkClientId;
|
|
249
|
-
/**
|
|
250
|
-
* Extra information about each network, such as whether it is accessible or
|
|
251
|
-
* blocked and whether it supports EIP-1559, keyed by network client ID.
|
|
252
|
-
*/
|
|
253
|
-
export type NetworksMetadata = Record<NetworkClientId, NetworkMetadata>;
|
|
254
|
-
/**
|
|
255
|
-
* The state that NetworkController stores.
|
|
256
|
-
*/
|
|
257
|
-
export type NetworkState = {
|
|
258
|
-
/**
|
|
259
|
-
* The ID of the network client that the proxies returned by
|
|
260
|
-
* `getSelectedNetworkClient` currently point to.
|
|
261
|
-
*/
|
|
262
|
-
selectedNetworkClientId: NetworkClientId;
|
|
263
|
-
/**
|
|
264
|
-
* The registry of networks and corresponding RPC endpoints that the
|
|
265
|
-
* controller can use to make requests for various chains.
|
|
266
|
-
*
|
|
267
|
-
* @see {@link NetworkConfiguration}
|
|
268
|
-
*/
|
|
269
|
-
networkConfigurationsByChainId: Record<Hex, NetworkConfiguration>;
|
|
270
|
-
/**
|
|
271
|
-
* Extra information about each network, such as whether it is accessible or
|
|
272
|
-
* blocked and whether it supports EIP-1559, keyed by network client ID.
|
|
273
|
-
*/
|
|
274
|
-
networksMetadata: NetworksMetadata;
|
|
275
|
-
};
|
|
276
|
-
declare const controllerName = "NetworkController";
|
|
277
|
-
/**
|
|
278
|
-
* Represents the block tracker for the currently selected network. (Note that
|
|
279
|
-
* this is a proxy around a proxy: the inner one exists so that the block
|
|
280
|
-
* tracker doesn't have to exist until it's used, and the outer one exists so
|
|
281
|
-
* that the currently selected network can change without consumers needing to
|
|
282
|
-
* refresh the object reference to that network.)
|
|
283
|
-
*/
|
|
284
|
-
export type BlockTrackerProxy = SwappableProxy<ProxyWithAccessibleTarget<BlockTracker>>;
|
|
285
|
-
/**
|
|
286
|
-
* Represents the provider for the currently selected network. (Note that this
|
|
287
|
-
* is a proxy around a proxy: the inner one exists so that the provider doesn't
|
|
288
|
-
* have to exist until it's used, and the outer one exists so that the currently
|
|
289
|
-
* selected network can change without consumers needing to refresh the object
|
|
290
|
-
* reference to that network.)
|
|
291
|
-
*/
|
|
292
|
-
export type ProviderProxy = SwappableProxy<ProxyWithAccessibleTarget<Provider>>;
|
|
293
|
-
export type NetworkControllerStateChangeEvent = ControllerStateChangeEvent<typeof controllerName, NetworkState>;
|
|
294
|
-
/**
|
|
295
|
-
* `networkWillChange` is published when the current network is about to be
|
|
296
|
-
* switched, but the new provider has not been created and no state changes have
|
|
297
|
-
* occurred yet.
|
|
298
|
-
*/
|
|
299
|
-
export type NetworkControllerNetworkWillChangeEvent = {
|
|
300
|
-
type: 'NetworkController:networkWillChange';
|
|
301
|
-
payload: [NetworkState];
|
|
302
|
-
};
|
|
303
|
-
/**
|
|
304
|
-
* `networkDidChange` is published after a provider has been created for a newly
|
|
305
|
-
* switched network (but before the network has been confirmed to be available).
|
|
306
|
-
*/
|
|
307
|
-
export type NetworkControllerNetworkDidChangeEvent = {
|
|
308
|
-
type: 'NetworkController:networkDidChange';
|
|
309
|
-
payload: [NetworkState];
|
|
310
|
-
};
|
|
311
|
-
/**
|
|
312
|
-
* `infuraIsBlocked` is published after the network is switched to an Infura
|
|
313
|
-
* network, but when Infura returns an error blocking the user based on their
|
|
314
|
-
* location.
|
|
315
|
-
*/
|
|
316
|
-
export type NetworkControllerInfuraIsBlockedEvent = {
|
|
317
|
-
type: 'NetworkController:infuraIsBlocked';
|
|
318
|
-
payload: [];
|
|
319
|
-
};
|
|
320
|
-
/**
|
|
321
|
-
* `infuraIsBlocked` is published either after the network is switched to an
|
|
322
|
-
* Infura network and Infura does not return an error blocking the user based on
|
|
323
|
-
* their location, or the network is switched to a non-Infura network.
|
|
324
|
-
*/
|
|
325
|
-
export type NetworkControllerInfuraIsUnblockedEvent = {
|
|
326
|
-
type: 'NetworkController:infuraIsUnblocked';
|
|
327
|
-
payload: [];
|
|
328
|
-
};
|
|
329
|
-
/**
|
|
330
|
-
* `networkAdded` is published after a network configuration is added to the
|
|
331
|
-
* network configuration registry and network clients are created for it.
|
|
332
|
-
*/
|
|
333
|
-
export type NetworkControllerNetworkAddedEvent = {
|
|
334
|
-
type: 'NetworkController:networkAdded';
|
|
335
|
-
payload: [networkConfiguration: NetworkConfiguration];
|
|
336
|
-
};
|
|
337
|
-
/**
|
|
338
|
-
* `networkRemoved` is published after a network configuration is removed from the
|
|
339
|
-
* network configuration registry and once the network clients have been removed.
|
|
340
|
-
*/
|
|
341
|
-
export type NetworkControllerNetworkRemovedEvent = {
|
|
342
|
-
type: 'NetworkController:networkRemoved';
|
|
343
|
-
payload: [networkConfiguration: NetworkConfiguration];
|
|
344
|
-
};
|
|
345
|
-
/**
|
|
346
|
-
* `NetworkController:rpcEndpointChainUnavailable` is published when, after
|
|
347
|
-
* trying all endpoints in an endpoint chain, the last failover reaches a
|
|
348
|
-
* maximum number of consecutive 5xx responses, breaking the underlying circuit.
|
|
349
|
-
*
|
|
350
|
-
* In other words, this event will not be published if a failover is available,
|
|
351
|
-
* even if the primary is not.
|
|
352
|
-
*
|
|
353
|
-
* @param payload - The event payload.
|
|
354
|
-
* @param payload.chainId - The target network's chain ID.
|
|
355
|
-
* @param payload.error - The last error produced by the last failover in the
|
|
356
|
-
* endpoint chain.
|
|
357
|
-
* @param payload.networkClientId - The target network's client ID.
|
|
358
|
-
*/
|
|
359
|
-
export type NetworkControllerRpcEndpointChainUnavailableEvent = {
|
|
360
|
-
type: 'NetworkController:rpcEndpointChainUnavailable';
|
|
361
|
-
payload: [
|
|
362
|
-
{
|
|
363
|
-
chainId: Hex;
|
|
364
|
-
error: unknown;
|
|
365
|
-
networkClientId: NetworkClientId;
|
|
366
|
-
}
|
|
367
|
-
];
|
|
368
|
-
};
|
|
369
|
-
/**
|
|
370
|
-
* `NetworkController:rpcEndpointUnavailable` is published when any
|
|
371
|
-
* endpoint in an endpoint chain reaches a maximum number of consecutive 5xx
|
|
372
|
-
* responses, breaking the underlying circuit.
|
|
373
|
-
*
|
|
374
|
-
* In other words, this event will be published if a primary is not available,
|
|
375
|
-
* even if a failover is.
|
|
376
|
-
*
|
|
377
|
-
* @param payload - The event payload.
|
|
378
|
-
* @param payload.chainId - The target network's chain ID.
|
|
379
|
-
* @param payload.endpointUrl - The URL of the endpoint which reached the
|
|
380
|
-
* maximum number of consecutive 5xx responses. You can compare this to
|
|
381
|
-
* `primaryEndpointUrl` to know whether it was a failover or a primary.
|
|
382
|
-
* @param payload.error - The last error produced by the endpoint.
|
|
383
|
-
* @param payload.networkClientId - The target network's client ID.
|
|
384
|
-
* @param payload.primaryEndpointUrl - The endpoint chain's primary URL.
|
|
385
|
-
*/
|
|
386
|
-
export type NetworkControllerRpcEndpointUnavailableEvent = {
|
|
387
|
-
type: 'NetworkController:rpcEndpointUnavailable';
|
|
388
|
-
payload: [
|
|
389
|
-
{
|
|
390
|
-
chainId: Hex;
|
|
391
|
-
endpointUrl: string;
|
|
392
|
-
error: unknown;
|
|
393
|
-
networkClientId: NetworkClientId;
|
|
394
|
-
primaryEndpointUrl: string;
|
|
395
|
-
}
|
|
396
|
-
];
|
|
397
|
-
};
|
|
398
|
-
/**
|
|
399
|
-
* `NetworkController:rpcEndpointChainDegraded` is published for any of the
|
|
400
|
-
* endpoints in an endpoint chain when one of the following two conditions hold
|
|
401
|
-
* (and the chain is not already in a degraded state):
|
|
402
|
-
*
|
|
403
|
-
* 1. A successful (2xx) request, even after being retried, cannot be made to
|
|
404
|
-
* the endpoint.
|
|
405
|
-
* 2. A successful (2xx) request can be made to the endpoint, but it takes
|
|
406
|
-
* longer than expected to complete.
|
|
407
|
-
*
|
|
408
|
-
* Note that this event will be published even if there are local connectivity
|
|
409
|
-
* issues which prevent requests from being initiated. This is intentional.
|
|
410
|
-
*
|
|
411
|
-
* @param payload - The event payload.
|
|
412
|
-
* @param payload.chainId - The target network's chain ID.
|
|
413
|
-
* @param payload.duration - The duration in milliseconds of the policy
|
|
414
|
-
* execution when the request succeeded but was slow. `undefined` when retries
|
|
415
|
-
* were exhausted.
|
|
416
|
-
* @param payload.error - The last error produced by the endpoint (or
|
|
417
|
-
* `undefined` if the request was slow).
|
|
418
|
-
* @param payload.networkClientId - The target network's client ID.
|
|
419
|
-
* @param payload.rpcMethodName - The JSON-RPC method that was being executed
|
|
420
|
-
* when the chain became degraded.
|
|
421
|
-
* @param payload.traceId - The value of the `X-Trace-Id` response header from
|
|
422
|
-
* the last request attempt, or `undefined` if the header was not present.
|
|
423
|
-
*/
|
|
424
|
-
export type NetworkControllerRpcEndpointChainDegradedEvent = {
|
|
425
|
-
type: 'NetworkController:rpcEndpointChainDegraded';
|
|
426
|
-
payload: [
|
|
427
|
-
{
|
|
428
|
-
chainId: Hex;
|
|
429
|
-
duration?: number;
|
|
430
|
-
error: unknown;
|
|
431
|
-
networkClientId: NetworkClientId;
|
|
432
|
-
retryReason?: RetryReason;
|
|
433
|
-
rpcMethodName: string;
|
|
434
|
-
traceId?: string;
|
|
435
|
-
type: DegradedEventType;
|
|
436
|
-
}
|
|
437
|
-
];
|
|
438
|
-
};
|
|
439
|
-
/**
|
|
440
|
-
*
|
|
441
|
-
* `NetworkController:rpcEndpointDegraded` is published for any of the endpoints
|
|
442
|
-
* in an endpoint chain when:
|
|
443
|
-
*
|
|
444
|
-
* 1. A successful (2xx) request, even after being retried, cannot be made to
|
|
445
|
-
* the endpoint.
|
|
446
|
-
* 2. A successful (2xx) request can be made to the endpoint, but it takes
|
|
447
|
-
* longer than expected to complete.
|
|
448
|
-
*
|
|
449
|
-
* Note that this event will be published even if there are local connectivity
|
|
450
|
-
* issues which prevent requests from being initiated. This is intentional.
|
|
451
|
-
*
|
|
452
|
-
* @param payload - The event payload.
|
|
453
|
-
* @param payload.chainId - The target network's chain ID.
|
|
454
|
-
* @param payload.duration - The duration in milliseconds of the policy
|
|
455
|
-
* execution when the request succeeded but was slow. `undefined` when retries
|
|
456
|
-
* were exhausted.
|
|
457
|
-
* @param payload.endpointUrl - The URL of the endpoint for which requests
|
|
458
|
-
* failed or were slow to complete. You can compare this to `primaryEndpointUrl`
|
|
459
|
-
* to know whether it was a failover or a primary.
|
|
460
|
-
* @param payload.error - The last error produced by the endpoint (or
|
|
461
|
-
* `undefined` if the request was slow).
|
|
462
|
-
* @param payload.networkClientId - The target network's client ID.
|
|
463
|
-
* @param payload.primaryEndpointUrl - The endpoint chain's primary URL.
|
|
464
|
-
* @param payload.rpcMethodName - The JSON-RPC method that was being executed
|
|
465
|
-
* when the endpoint became degraded.
|
|
466
|
-
* @param payload.traceId - The value of the `X-Trace-Id` response header from
|
|
467
|
-
* the last request attempt, or `undefined` if the header was not present.
|
|
468
|
-
*/
|
|
469
|
-
export type NetworkControllerRpcEndpointDegradedEvent = {
|
|
470
|
-
type: 'NetworkController:rpcEndpointDegraded';
|
|
471
|
-
payload: [
|
|
472
|
-
{
|
|
473
|
-
chainId: Hex;
|
|
474
|
-
duration?: number;
|
|
475
|
-
endpointUrl: string;
|
|
476
|
-
error: unknown;
|
|
477
|
-
networkClientId: NetworkClientId;
|
|
478
|
-
primaryEndpointUrl: string;
|
|
479
|
-
retryReason?: RetryReason;
|
|
480
|
-
rpcMethodName: string;
|
|
481
|
-
traceId?: string;
|
|
482
|
-
type: DegradedEventType;
|
|
483
|
-
}
|
|
484
|
-
];
|
|
485
|
-
};
|
|
486
|
-
/**
|
|
487
|
-
* `NetworkController:rpcEndpointChainAvailable` is published in one of two
|
|
488
|
-
* cases:
|
|
489
|
-
*
|
|
490
|
-
* 1. The first time that a 2xx request is made to any of the endpoints in an
|
|
491
|
-
* endpoint chain.
|
|
492
|
-
* 2. When requests to any of the endpoints previously failed (placing the
|
|
493
|
-
* endpoint in a degraded or unavailable status), but are now succeeding again.
|
|
494
|
-
*
|
|
495
|
-
* @param payload - The event payload.
|
|
496
|
-
* @param payload.chainId - The target network's chain ID.
|
|
497
|
-
* @param payload.networkClientId - The target network's client ID.
|
|
498
|
-
*/
|
|
499
|
-
export type NetworkControllerRpcEndpointChainAvailableEvent = {
|
|
500
|
-
type: 'NetworkController:rpcEndpointChainAvailable';
|
|
501
|
-
payload: [
|
|
502
|
-
{
|
|
503
|
-
chainId: Hex;
|
|
504
|
-
networkClientId: NetworkClientId;
|
|
505
|
-
}
|
|
506
|
-
];
|
|
507
|
-
};
|
|
508
|
-
/**
|
|
509
|
-
* `NetworkController:rpcEndpointRetried` is published before a request to any
|
|
510
|
-
* endpoint in an endpoint chain is retried.
|
|
511
|
-
*
|
|
512
|
-
* This is mainly useful for tests.
|
|
513
|
-
*
|
|
514
|
-
* @param payload - The event payload.
|
|
515
|
-
* @param payload.attempt - The current attempt counter for the endpoint
|
|
516
|
-
* (starting from 0).
|
|
517
|
-
* @param payload.chainId - The target network's chain ID.
|
|
518
|
-
* @param payload.endpointUrl - The URL of the endpoint being retried.
|
|
519
|
-
* @param payload.networkClientId - The target network's client ID.
|
|
520
|
-
* @param payload.primaryEndpointUrl - The endpoint chain's primary URL.
|
|
521
|
-
* @see {@link RpcService} for the list of retriable errors.
|
|
522
|
-
*/
|
|
523
|
-
export type NetworkControllerRpcEndpointRetriedEvent = {
|
|
524
|
-
type: 'NetworkController:rpcEndpointRetried';
|
|
525
|
-
payload: [
|
|
526
|
-
{
|
|
527
|
-
attempt: number;
|
|
528
|
-
chainId: Hex;
|
|
529
|
-
endpointUrl: string;
|
|
530
|
-
networkClientId: NetworkClientId;
|
|
531
|
-
primaryEndpointUrl: string;
|
|
532
|
-
}
|
|
533
|
-
];
|
|
534
|
-
};
|
|
535
|
-
export type NetworkControllerEvents = NetworkControllerStateChangeEvent | NetworkControllerNetworkWillChangeEvent | NetworkControllerNetworkDidChangeEvent | NetworkControllerInfuraIsBlockedEvent | NetworkControllerInfuraIsUnblockedEvent | NetworkControllerNetworkAddedEvent | NetworkControllerNetworkRemovedEvent | NetworkControllerRpcEndpointChainUnavailableEvent | NetworkControllerRpcEndpointUnavailableEvent | NetworkControllerRpcEndpointChainDegradedEvent | NetworkControllerRpcEndpointDegradedEvent | NetworkControllerRpcEndpointChainAvailableEvent | NetworkControllerRpcEndpointRetriedEvent;
|
|
536
|
-
/**
|
|
537
|
-
* All events that {@link NetworkController} calls internally.
|
|
538
|
-
*/
|
|
539
|
-
type AllowedEvents = RemoteFeatureFlagControllerStateChangeEvent | ConfigRegistryControllerStateChangedEvent;
|
|
540
|
-
export type NetworkControllerGetStateAction = ControllerGetStateAction<typeof controllerName, NetworkState>;
|
|
541
|
-
/**
|
|
542
|
-
* All actions that {@link NetworkController} registers, to be called
|
|
543
|
-
* externally.
|
|
544
|
-
*/
|
|
545
|
-
export type NetworkControllerActions = NetworkControllerGetStateAction | NetworkControllerMethodActions;
|
|
546
|
-
/**
|
|
547
|
-
* All actions that {@link NetworkController} calls internally.
|
|
548
|
-
*/
|
|
549
|
-
type AllowedActions = ConfigRegistryControllerGetNetworkConfigByCaip2ChainIdAction | ConfigRegistryControllerGetStateAction | ConnectivityControllerGetStateAction | RemoteFeatureFlagControllerGetStateAction | AnalyticsControllerGetStateAction | AnalyticsControllerTrackEventAction;
|
|
550
|
-
export type NetworkControllerMessenger = Messenger<typeof controllerName, NetworkControllerActions | AllowedActions, NetworkControllerEvents | AllowedEvents>;
|
|
551
|
-
/**
|
|
552
|
-
* Options for the NetworkController constructor.
|
|
553
|
-
*/
|
|
554
|
-
export type NetworkControllerOptions = {
|
|
555
|
-
/**
|
|
556
|
-
* The messenger suited for this controller.
|
|
557
|
-
*/
|
|
558
|
-
messenger: NetworkControllerMessenger;
|
|
559
|
-
/**
|
|
560
|
-
* The API key for Infura, used to make requests to Infura.
|
|
561
|
-
*/
|
|
562
|
-
infuraProjectId: string;
|
|
563
|
-
/**
|
|
564
|
-
* An optional map of available failover URLs for each chain ID.
|
|
565
|
-
*/
|
|
566
|
-
failoverUrls?: Record<Hex, string[]>;
|
|
567
|
-
/**
|
|
568
|
-
* The desired state with which to initialize this controller.
|
|
569
|
-
* Missing properties will be filled in with defaults. For instance, if not
|
|
570
|
-
* specified, `networkConfigurationsByChainId` will default to a basic set of
|
|
571
|
-
* network configurations (see {@link InfuraNetworkType} for the list).
|
|
572
|
-
*/
|
|
573
|
-
state?: Partial<NetworkState>;
|
|
574
|
-
/**
|
|
575
|
-
* A `loglevel` logger object.
|
|
576
|
-
*/
|
|
577
|
-
log?: Logger;
|
|
578
|
-
/**
|
|
579
|
-
* A function that can be used to customize a RPC service constructed for an
|
|
580
|
-
* RPC endpoint. The function takes the URL of the endpoint and should return
|
|
581
|
-
* an object with type {@link RpcServiceOptionsWithDefaults}, minus `failoverService`
|
|
582
|
-
* and `endpointUrl` (as they are filled in automatically).
|
|
583
|
-
*/
|
|
584
|
-
getRpcServiceOptions?: (rpcEndpointUrl: string) => RpcServiceOptionsWithDefaults;
|
|
585
|
-
/**
|
|
586
|
-
* A function that can be used to customize a block tracker constructed for an
|
|
587
|
-
* RPC endpoint. The function takes the URL of the endpoint and should return
|
|
588
|
-
* an object of type {@link PollingBlockTrackerOptions}, minus `provider` (as
|
|
589
|
-
* it is filled in automatically).
|
|
590
|
-
*/
|
|
591
|
-
getBlockTrackerOptions?: (rpcEndpointUrl: string) => Omit<PollingBlockTrackerOptions, 'provider'>;
|
|
592
|
-
/**
|
|
593
|
-
* Configuration for the "RPC Service Unavailable" and "RPC Service Degraded"
|
|
594
|
-
* analytics events the controller emits via the `AnalyticsController:trackEvent`
|
|
595
|
-
* action when an RPC endpoint becomes unavailable or degraded. Both the option
|
|
596
|
-
* and its properties are optional; omitted properties default to
|
|
597
|
-
* `isRpcEndpointUrlPublic: () => false` and `rpcServiceEventsSampleRate: 0`
|
|
598
|
-
* (which emits nothing). The messenger must allow `AnalyticsController:getState`
|
|
599
|
-
* and `AnalyticsController:trackEvent` regardless.
|
|
600
|
-
*/
|
|
601
|
-
analyticsOptions?: NetworkControllerAnalyticsOptions;
|
|
602
|
-
};
|
|
603
|
-
/**
|
|
604
|
-
* Constructs properties for the NetworkController state whose values will be
|
|
605
|
-
* used if not provided to the constructor.
|
|
606
|
-
*
|
|
607
|
-
* @returns The default NetworkController state.
|
|
608
|
-
*/
|
|
609
|
-
export declare function getDefaultNetworkControllerState(): NetworkState;
|
|
610
|
-
/**
|
|
611
|
-
* Get a list of all network configurations.
|
|
612
|
-
*
|
|
613
|
-
* @param state - NetworkController state
|
|
614
|
-
* @returns A list of all available network configurations
|
|
615
|
-
*/
|
|
616
|
-
export declare function getNetworkConfigurations(state: NetworkState): NetworkConfiguration[];
|
|
617
|
-
/**
|
|
618
|
-
* Redux selector for getting a list of all network configurations from
|
|
619
|
-
* NetworkController state.
|
|
620
|
-
*
|
|
621
|
-
* @param state - NetworkController state
|
|
622
|
-
* @returns A list of all available network configurations
|
|
623
|
-
*/
|
|
624
|
-
export declare const selectNetworkConfigurations: ((state: NetworkState) => NetworkConfiguration[]) & {
|
|
625
|
-
clearCache: () => void;
|
|
626
|
-
resultsCount: () => number;
|
|
627
|
-
resetResultsCount: () => void;
|
|
628
|
-
} & {
|
|
629
|
-
resultFunc: (resultFuncArgs_0: Record<`0x${string}`, NetworkConfiguration>) => NetworkConfiguration[];
|
|
630
|
-
memoizedResultFunc: ((resultFuncArgs_0: Record<`0x${string}`, NetworkConfiguration>) => NetworkConfiguration[]) & {
|
|
631
|
-
clearCache: () => void;
|
|
632
|
-
resultsCount: () => number;
|
|
633
|
-
resetResultsCount: () => void;
|
|
634
|
-
};
|
|
635
|
-
lastResult: () => NetworkConfiguration[];
|
|
636
|
-
dependencies: [(state: NetworkState) => Record<`0x${string}`, NetworkConfiguration>];
|
|
637
|
-
recomputations: () => number;
|
|
638
|
-
resetRecomputations: () => void;
|
|
639
|
-
dependencyRecomputations: () => number;
|
|
640
|
-
resetDependencyRecomputations: () => void;
|
|
641
|
-
} & {
|
|
642
|
-
argsMemoize: typeof import("reselect").weakMapMemoize;
|
|
643
|
-
memoize: typeof import("reselect").weakMapMemoize;
|
|
644
|
-
};
|
|
645
|
-
/**
|
|
646
|
-
* Get a list of all available network client IDs from a list of network
|
|
647
|
-
* configurations.
|
|
648
|
-
*
|
|
649
|
-
* @param networkConfigurations - The array of network configurations
|
|
650
|
-
* @returns A list of all available client IDs
|
|
651
|
-
*/
|
|
652
|
-
export declare function getAvailableNetworkClientIds(networkConfigurations: NetworkConfiguration[]): string[];
|
|
653
|
-
/**
|
|
654
|
-
* Redux selector for getting a list of all available network client IDs
|
|
655
|
-
* from NetworkController state.
|
|
656
|
-
*
|
|
657
|
-
* @param state - NetworkController state
|
|
658
|
-
* @returns A list of all available network client IDs.
|
|
659
|
-
*/
|
|
660
|
-
export declare const selectAvailableNetworkClientIds: ((state: NetworkState) => string[]) & {
|
|
661
|
-
clearCache: () => void;
|
|
662
|
-
resultsCount: () => number;
|
|
663
|
-
resetResultsCount: () => void;
|
|
664
|
-
} & {
|
|
665
|
-
resultFunc: (resultFuncArgs_0: NetworkConfiguration[]) => string[];
|
|
666
|
-
memoizedResultFunc: ((resultFuncArgs_0: NetworkConfiguration[]) => string[]) & {
|
|
667
|
-
clearCache: () => void;
|
|
668
|
-
resultsCount: () => number;
|
|
669
|
-
resetResultsCount: () => void;
|
|
670
|
-
};
|
|
671
|
-
lastResult: () => string[];
|
|
672
|
-
dependencies: [((state: NetworkState) => NetworkConfiguration[]) & {
|
|
673
|
-
clearCache: () => void;
|
|
674
|
-
resultsCount: () => number;
|
|
675
|
-
resetResultsCount: () => void;
|
|
676
|
-
} & {
|
|
677
|
-
resultFunc: (resultFuncArgs_0: Record<`0x${string}`, NetworkConfiguration>) => NetworkConfiguration[];
|
|
678
|
-
memoizedResultFunc: ((resultFuncArgs_0: Record<`0x${string}`, NetworkConfiguration>) => NetworkConfiguration[]) & {
|
|
679
|
-
clearCache: () => void;
|
|
680
|
-
resultsCount: () => number;
|
|
681
|
-
resetResultsCount: () => void;
|
|
682
|
-
};
|
|
683
|
-
lastResult: () => NetworkConfiguration[];
|
|
684
|
-
dependencies: [(state: NetworkState) => Record<`0x${string}`, NetworkConfiguration>];
|
|
685
|
-
recomputations: () => number;
|
|
686
|
-
resetRecomputations: () => void;
|
|
687
|
-
dependencyRecomputations: () => number;
|
|
688
|
-
resetDependencyRecomputations: () => void;
|
|
689
|
-
} & {
|
|
690
|
-
argsMemoize: typeof import("reselect").weakMapMemoize;
|
|
691
|
-
memoize: typeof import("reselect").weakMapMemoize;
|
|
692
|
-
}];
|
|
693
|
-
recomputations: () => number;
|
|
694
|
-
resetRecomputations: () => void;
|
|
695
|
-
dependencyRecomputations: () => number;
|
|
696
|
-
resetDependencyRecomputations: () => void;
|
|
697
|
-
} & {
|
|
698
|
-
argsMemoize: typeof import("reselect").weakMapMemoize;
|
|
699
|
-
memoize: typeof import("reselect").weakMapMemoize;
|
|
700
|
-
};
|
|
701
|
-
/**
|
|
702
|
-
* The collection of auto-managed network clients that map to Infura networks.
|
|
703
|
-
*/
|
|
704
|
-
export type AutoManagedBuiltInNetworkClientRegistry = Record<BuiltInNetworkClientId, AutoManagedNetworkClient<InfuraNetworkClientConfiguration>>;
|
|
705
|
-
/**
|
|
706
|
-
* The collection of auto-managed network clients that map to Infura networks.
|
|
707
|
-
*/
|
|
708
|
-
export type AutoManagedCustomNetworkClientRegistry = Record<CustomNetworkClientId, AutoManagedNetworkClient<CustomNetworkClientConfiguration>>;
|
|
709
|
-
/**
|
|
710
|
-
* The collection of auto-managed network clients that map to Infura networks
|
|
711
|
-
* as well as custom networks that users have added.
|
|
712
|
-
*/
|
|
713
|
-
export type AutoManagedNetworkClientRegistry = {
|
|
714
|
-
[NetworkClientType.Infura]: AutoManagedBuiltInNetworkClientRegistry;
|
|
715
|
-
[NetworkClientType.Custom]: AutoManagedCustomNetworkClientRegistry;
|
|
716
|
-
};
|
|
717
|
-
/**
|
|
718
|
-
* Controller that creates and manages an Ethereum network provider.
|
|
719
|
-
*/
|
|
720
|
-
export declare class NetworkController extends BaseController<typeof controllerName, NetworkState, NetworkControllerMessenger> {
|
|
721
|
-
#private;
|
|
722
|
-
/**
|
|
723
|
-
* Constructs a NetworkController.
|
|
724
|
-
*
|
|
725
|
-
* @param options - The options; see {@link NetworkControllerOptions}.
|
|
726
|
-
*/
|
|
727
|
-
constructor(options: NetworkControllerOptions);
|
|
728
|
-
/**
|
|
729
|
-
* Returns the EthQuery instance for the currently selected network.
|
|
730
|
-
*
|
|
731
|
-
* @returns The EthQuery instance, or undefined if the provider has not been
|
|
732
|
-
* initialized.
|
|
733
|
-
*/
|
|
734
|
-
getEthQuery(): EthQuery | undefined;
|
|
735
|
-
/**
|
|
736
|
-
* Accesses the provider and block tracker for the currently selected network.
|
|
737
|
-
*
|
|
738
|
-
* @returns The proxy and block tracker proxies.
|
|
739
|
-
* @deprecated This method has been replaced by `getSelectedNetworkClient` (which has a more easily used return type) and will be removed in a future release.
|
|
740
|
-
*/
|
|
741
|
-
getProviderAndBlockTracker(): {
|
|
742
|
-
provider: SwappableProxy<ProxyWithAccessibleTarget<Provider>> | undefined;
|
|
743
|
-
blockTracker: SwappableProxy<ProxyWithAccessibleTarget<BlockTracker>> | undefined;
|
|
744
|
-
};
|
|
745
|
-
/**
|
|
746
|
-
* Accesses the provider and block tracker for the currently selected network.
|
|
747
|
-
*
|
|
748
|
-
* @returns an object with the provider and block tracker proxies for the currently selected network.
|
|
749
|
-
*/
|
|
750
|
-
getSelectedNetworkClient(): {
|
|
751
|
-
provider: SwappableProxy<ProxyWithAccessibleTarget<Provider>>;
|
|
752
|
-
blockTracker: SwappableProxy<ProxyWithAccessibleTarget<BlockTracker>>;
|
|
753
|
-
} | undefined;
|
|
754
|
-
/**
|
|
755
|
-
* Accesses the chain ID from the selected network client.
|
|
756
|
-
*
|
|
757
|
-
* @returns The chain ID of the selected network client in hex format or undefined if there is no network client.
|
|
758
|
-
*/
|
|
759
|
-
getSelectedChainId(): Hex | undefined;
|
|
760
|
-
/**
|
|
761
|
-
* Internally, the Infura and custom network clients are categorized by type
|
|
762
|
-
* so that when accessing either kind of network client, TypeScript knows
|
|
763
|
-
* which type to assign to the network client. For some cases it's more useful
|
|
764
|
-
* to be able to access network clients by ID instead of by type and then ID,
|
|
765
|
-
* so this function makes that possible.
|
|
766
|
-
*
|
|
767
|
-
* @returns The network clients registered so far, keyed by ID.
|
|
768
|
-
*/
|
|
769
|
-
getNetworkClientRegistry(): AutoManagedBuiltInNetworkClientRegistry & AutoManagedCustomNetworkClientRegistry;
|
|
770
|
-
/**
|
|
771
|
-
* Returns the Infura network client with the given ID.
|
|
772
|
-
*
|
|
773
|
-
* @param infuraNetworkClientId - An Infura network client ID.
|
|
774
|
-
* @returns The Infura network client.
|
|
775
|
-
* @throws If an Infura network client does not exist with the given ID.
|
|
776
|
-
*/
|
|
777
|
-
getNetworkClientById(infuraNetworkClientId: BuiltInNetworkClientId): AutoManagedNetworkClient<InfuraNetworkClientConfiguration>;
|
|
778
|
-
/**
|
|
779
|
-
* Returns the custom network client with the given ID.
|
|
780
|
-
*
|
|
781
|
-
* @param customNetworkClientId - A custom network client ID.
|
|
782
|
-
* @returns The custom network client.
|
|
783
|
-
* @throws If a custom network client does not exist with the given ID.
|
|
784
|
-
*/
|
|
785
|
-
getNetworkClientById(customNetworkClientId: CustomNetworkClientId): AutoManagedNetworkClient<CustomNetworkClientConfiguration>;
|
|
786
|
-
/**
|
|
787
|
-
* Initialize the NetworkController:
|
|
788
|
-
* - Apply the RPC failover mode from the `corePlatformRpcFailoverMode` remote feature flag;
|
|
789
|
-
* - Apply the network selection.
|
|
790
|
-
* - Auto-add networks for any chains that are configured to be auto-enabled in ConfigRegistryController.
|
|
791
|
-
*/
|
|
792
|
-
init(): void;
|
|
793
|
-
/**
|
|
794
|
-
* Uses a request for the latest block to gather the following information on
|
|
795
|
-
* the given or selected network, persisting it to state:
|
|
796
|
-
*
|
|
797
|
-
* - The connectivity status: whether it is available, geo-blocked (Infura
|
|
798
|
-
* only), unavailable, or unknown
|
|
799
|
-
* - The capabilities status: whether it supports EIP-1559, whether it does
|
|
800
|
-
* not, or whether it is unknown
|
|
801
|
-
*
|
|
802
|
-
* @param networkClientId - The ID of the network client to inspect.
|
|
803
|
-
* If no ID is provided, uses the currently selected network.
|
|
804
|
-
*/
|
|
805
|
-
lookupNetwork(networkClientId?: NetworkClientId): Promise<void>;
|
|
806
|
-
/**
|
|
807
|
-
* Uses a request for the latest block to gather the following information on
|
|
808
|
-
* the given network, persisting it to state:
|
|
809
|
-
*
|
|
810
|
-
* - The connectivity status: whether the network is available, geo-blocked
|
|
811
|
-
* (Infura only), unavailable, or unknown
|
|
812
|
-
* - The feature compatibility status: whether the network supports EIP-1559,
|
|
813
|
-
* whether it does not, or whether it is unknown
|
|
814
|
-
*
|
|
815
|
-
* @param networkClientId - The ID of the network client to inspect.
|
|
816
|
-
* @deprecated Please use `lookupNetwork` and pass a network client ID
|
|
817
|
-
* instead. This method will be removed in a future major version.
|
|
818
|
-
*/
|
|
819
|
-
lookupNetworkByClientId(networkClientId: NetworkClientId): Promise<void>;
|
|
820
|
-
/**
|
|
821
|
-
* Convenience method to update provider network type settings.
|
|
822
|
-
*
|
|
823
|
-
* @param type - Human readable network name.
|
|
824
|
-
* @deprecated This has been replaced by `setActiveNetwork`, and will be
|
|
825
|
-
* removed in a future release
|
|
826
|
-
*/
|
|
827
|
-
setProviderType(type: InfuraNetworkType): Promise<void>;
|
|
828
|
-
/**
|
|
829
|
-
* Changes the selected network.
|
|
830
|
-
*
|
|
831
|
-
* @param networkClientId - The ID of a network client that will be used to
|
|
832
|
-
* make requests.
|
|
833
|
-
* @param options - Options for this method.
|
|
834
|
-
* @param options.updateState - Allows for updating state.
|
|
835
|
-
* @throws if no network client is associated with the given
|
|
836
|
-
* network client ID.
|
|
837
|
-
*/
|
|
838
|
-
setActiveNetwork(networkClientId: string, options?: {
|
|
839
|
-
updateState?: (state: Draft<NetworkState>) => void;
|
|
840
|
-
}): Promise<void>;
|
|
841
|
-
/**
|
|
842
|
-
* Determines whether the network supports EIP-1559 by checking whether the
|
|
843
|
-
* latest block has a `baseFeePerGas` property, then updates state
|
|
844
|
-
* appropriately.
|
|
845
|
-
*
|
|
846
|
-
* @param networkClientId - The networkClientId to fetch the correct provider against which to check 1559 compatibility.
|
|
847
|
-
* @returns A promise that resolves to true if the network supports EIP-1559
|
|
848
|
-
* , false otherwise, or `undefined` if unable to determine the compatibility.
|
|
849
|
-
*/
|
|
850
|
-
getEIP1559Compatibility(networkClientId?: NetworkClientId): Promise<undefined | boolean>;
|
|
851
|
-
get1559CompatibilityWithNetworkClientId(networkClientId: NetworkClientId): Promise<boolean>;
|
|
852
|
-
/**
|
|
853
|
-
* Ensures that the provider and block tracker proxies are pointed to the
|
|
854
|
-
* currently selected network and refreshes the metadata for the
|
|
855
|
-
*/
|
|
856
|
-
resetConnection(): Promise<void>;
|
|
857
|
-
/**
|
|
858
|
-
* Returns the network configuration that has been filed under the given chain
|
|
859
|
-
* ID.
|
|
860
|
-
*
|
|
861
|
-
* @param chainId - The chain ID to use as a key.
|
|
862
|
-
* @returns The network configuration if one exists, or undefined.
|
|
863
|
-
*/
|
|
864
|
-
getNetworkConfigurationByChainId(chainId: Hex): NetworkConfiguration | undefined;
|
|
865
|
-
/**
|
|
866
|
-
* Returns the network configuration that contains an RPC endpoint with the
|
|
867
|
-
* given network client ID.
|
|
868
|
-
*
|
|
869
|
-
* @param networkClientId - The network client ID to use as a key.
|
|
870
|
-
* @returns The network configuration if one exists, or undefined.
|
|
871
|
-
*/
|
|
872
|
-
getNetworkConfigurationByNetworkClientId(networkClientId: NetworkClientId): NetworkConfiguration | undefined;
|
|
873
|
-
/**
|
|
874
|
-
* Creates and registers network clients for the collection of Infura and
|
|
875
|
-
* custom RPC endpoints that can be used to make requests for a particular
|
|
876
|
-
* chain, storing the given configuration object in state for later reference.
|
|
877
|
-
*
|
|
878
|
-
* @param fields - The object that describes the new network/chain and lists
|
|
879
|
-
* the RPC endpoints which front that chain.
|
|
880
|
-
* @returns The newly added network configuration.
|
|
881
|
-
* @throws if any part of `fields` would produce invalid state.
|
|
882
|
-
* @see {@link NetworkConfiguration}
|
|
883
|
-
*/
|
|
884
|
-
addNetwork(fields: AddNetworkFields): NetworkConfiguration;
|
|
885
|
-
/**
|
|
886
|
-
* Updates the configuration for a previously stored network filed under the
|
|
887
|
-
* given chain ID, creating + registering new network clients to represent RPC
|
|
888
|
-
* endpoints that have been added and destroying + unregistering existing
|
|
889
|
-
* network clients for RPC endpoints that have been removed.
|
|
890
|
-
*
|
|
891
|
-
* Note that if `chainId` is changed, then all network clients associated with
|
|
892
|
-
* that chain will be removed and re-added, even if none of the RPC endpoints
|
|
893
|
-
* have changed.
|
|
894
|
-
*
|
|
895
|
-
* @param chainId - The chain ID associated with an existing network.
|
|
896
|
-
* @param fields - The object that describes the updates to the network/chain,
|
|
897
|
-
* including the new set of RPC endpoints which should front that chain.
|
|
898
|
-
* @param options - Options to provide.
|
|
899
|
-
* @param options.replacementSelectedRpcEndpointIndex - Usually you cannot
|
|
900
|
-
* remove an RPC endpoint that is being represented by the currently selected
|
|
901
|
-
* network client. This option allows you to specify another RPC endpoint
|
|
902
|
-
* (either an existing one or a new one) that should be used to select a new
|
|
903
|
-
* network instead.
|
|
904
|
-
* @returns The updated network configuration.
|
|
905
|
-
* @throws if `chainId` does not refer to an existing network configuration,
|
|
906
|
-
* if any part of `fields` would produce invalid state, etc.
|
|
907
|
-
* @see {@link NetworkConfiguration}
|
|
908
|
-
*/
|
|
909
|
-
updateNetwork(chainId: Hex, fields: UpdateNetworkFields, { replacementSelectedRpcEndpointIndex, }?: {
|
|
910
|
-
replacementSelectedRpcEndpointIndex?: number;
|
|
911
|
-
}): Promise<NetworkConfiguration>;
|
|
912
|
-
/**
|
|
913
|
-
* Destroys and unregisters the network identified by the given chain ID, also
|
|
914
|
-
* removing the associated network configuration from state.
|
|
915
|
-
*
|
|
916
|
-
* @param chainId - The chain ID associated with an existing network.
|
|
917
|
-
* @throws if `chainId` does not refer to an existing network configuration,
|
|
918
|
-
* or if the currently selected network is being removed.
|
|
919
|
-
* @see {@link NetworkConfiguration}
|
|
920
|
-
*/
|
|
921
|
-
removeNetwork(chainId: Hex): void;
|
|
922
|
-
/**
|
|
923
|
-
* Assuming that the network has been previously switched, switches to this
|
|
924
|
-
* new network.
|
|
925
|
-
*
|
|
926
|
-
* If the network has not been previously switched, this method is equivalent
|
|
927
|
-
* to {@link resetConnection}.
|
|
928
|
-
*/
|
|
929
|
-
rollbackToPreviousProvider(): Promise<void>;
|
|
930
|
-
/**
|
|
931
|
-
* Deactivates the controller, stopping any ongoing polling.
|
|
932
|
-
*
|
|
933
|
-
* In-progress requests will not be aborted.
|
|
934
|
-
*/
|
|
935
|
-
destroy(): Promise<void>;
|
|
936
|
-
/**
|
|
937
|
-
* Merges the given backup data into controller state.
|
|
938
|
-
*
|
|
939
|
-
* @param backup - The data that has been backed up.
|
|
940
|
-
* @param backup.networkConfigurationsByChainId - Network configurations,
|
|
941
|
-
* keyed by chain ID.
|
|
942
|
-
*/
|
|
943
|
-
loadBackup({ networkConfigurationsByChainId, }: Pick<NetworkState, 'networkConfigurationsByChainId'>): void;
|
|
944
|
-
/**
|
|
945
|
-
* Searches for the default RPC endpoint configured for the given chain and
|
|
946
|
-
* returns its network client ID. This can then be passed to
|
|
947
|
-
* {@link getNetworkClientById} to retrieve the network client.
|
|
948
|
-
*
|
|
949
|
-
* @param chainId - Chain ID to search for.
|
|
950
|
-
* @returns The ID of the network client created for the chain's default RPC
|
|
951
|
-
* endpoint.
|
|
952
|
-
*/
|
|
953
|
-
findNetworkClientIdByChainId(chainId: Hex): NetworkClientId;
|
|
954
|
-
}
|
|
955
|
-
export {};
|
|
956
|
-
//# sourceMappingURL=NetworkController.d.mts.map
|