@cfxdevkit/core 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +35 -0
- package/LICENSE +72 -0
- package/README.md +257 -0
- package/dist/clients/index.cjs +2053 -0
- package/dist/clients/index.cjs.map +1 -0
- package/dist/clients/index.d.cts +7 -0
- package/dist/clients/index.d.ts +7 -0
- package/dist/clients/index.js +2043 -0
- package/dist/clients/index.js.map +1 -0
- package/dist/config/index.cjs +423 -0
- package/dist/config/index.cjs.map +1 -0
- package/dist/config/index.d.cts +99 -0
- package/dist/config/index.d.ts +99 -0
- package/dist/config/index.js +380 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config-BMtaWM0X.d.cts +165 -0
- package/dist/config-BMtaWM0X.d.ts +165 -0
- package/dist/core-C5qe16RS.d.ts +352 -0
- package/dist/core-RZA4aKwj.d.cts +352 -0
- package/dist/index-BhCpy6Fz.d.cts +165 -0
- package/dist/index-Qz84U9Oq.d.ts +165 -0
- package/dist/index.cjs +3773 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +945 -0
- package/dist/index.d.ts +945 -0
- package/dist/index.js +3730 -0
- package/dist/index.js.map +1 -0
- package/dist/types/index.cjs +44 -0
- package/dist/types/index.cjs.map +1 -0
- package/dist/types/index.d.cts +5 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/index.js +17 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/index.cjs +83 -0
- package/dist/utils/index.cjs.map +1 -0
- package/dist/utils/index.d.cts +11 -0
- package/dist/utils/index.d.ts +11 -0
- package/dist/utils/index.js +56 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/wallet/index.cjs +852 -0
- package/dist/wallet/index.cjs.map +1 -0
- package/dist/wallet/index.d.cts +726 -0
- package/dist/wallet/index.d.ts +726 -0
- package/dist/wallet/index.js +815 -0
- package/dist/wallet/index.js.map +1 -0
- package/package.json +119 -0
|
@@ -0,0 +1,423 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/config/index.ts
|
|
21
|
+
var config_exports = {};
|
|
22
|
+
__export(config_exports, {
|
|
23
|
+
CORE_LOCAL: () => CORE_LOCAL,
|
|
24
|
+
CORE_MAINNET: () => CORE_MAINNET,
|
|
25
|
+
CORE_TESTNET: () => CORE_TESTNET,
|
|
26
|
+
EVM_LOCAL: () => EVM_LOCAL,
|
|
27
|
+
EVM_MAINNET: () => EVM_MAINNET,
|
|
28
|
+
EVM_TESTNET: () => EVM_TESTNET,
|
|
29
|
+
NetworkSelector: () => NetworkSelector,
|
|
30
|
+
SUPPORTED_CHAINS: () => SUPPORTED_CHAINS,
|
|
31
|
+
defaultNetworkSelector: () => defaultNetworkSelector,
|
|
32
|
+
getChainConfig: () => getChainConfig,
|
|
33
|
+
getCoreChains: () => getCoreChains,
|
|
34
|
+
getEvmChains: () => getEvmChains,
|
|
35
|
+
getMainnetChains: () => getMainnetChains,
|
|
36
|
+
getTestnetChains: () => getTestnetChains,
|
|
37
|
+
isValidChainId: () => isValidChainId,
|
|
38
|
+
toCiveChain: () => toCiveChain,
|
|
39
|
+
toViemChain: () => toViemChain
|
|
40
|
+
});
|
|
41
|
+
module.exports = __toCommonJS(config_exports);
|
|
42
|
+
|
|
43
|
+
// src/config/chains.ts
|
|
44
|
+
var import_utils = require("cive/utils");
|
|
45
|
+
var import_viem = require("viem");
|
|
46
|
+
var CORE_MAINNET = {
|
|
47
|
+
id: 1029,
|
|
48
|
+
name: "conflux-core",
|
|
49
|
+
type: "core",
|
|
50
|
+
testnet: false,
|
|
51
|
+
nativeCurrency: {
|
|
52
|
+
name: "Conflux",
|
|
53
|
+
symbol: "CFX",
|
|
54
|
+
decimals: 18
|
|
55
|
+
},
|
|
56
|
+
rpcUrls: {
|
|
57
|
+
default: {
|
|
58
|
+
http: ["https://main.confluxrpc.com"],
|
|
59
|
+
webSocket: ["wss://main.confluxrpc.com/ws"]
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
blockExplorers: {
|
|
63
|
+
default: {
|
|
64
|
+
name: "ConfluxScan",
|
|
65
|
+
url: "https://confluxscan.io"
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
var CORE_TESTNET = {
|
|
70
|
+
id: 1,
|
|
71
|
+
name: "conflux-core-testnet",
|
|
72
|
+
type: "core",
|
|
73
|
+
testnet: true,
|
|
74
|
+
nativeCurrency: {
|
|
75
|
+
name: "Conflux",
|
|
76
|
+
symbol: "CFX",
|
|
77
|
+
decimals: 18
|
|
78
|
+
},
|
|
79
|
+
rpcUrls: {
|
|
80
|
+
default: {
|
|
81
|
+
http: ["https://test.confluxrpc.com"],
|
|
82
|
+
webSocket: ["wss://test.confluxrpc.com/ws"]
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
blockExplorers: {
|
|
86
|
+
default: {
|
|
87
|
+
name: "ConfluxScan Testnet",
|
|
88
|
+
url: "https://testnet.confluxscan.io"
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
var CORE_LOCAL = {
|
|
93
|
+
id: 2029,
|
|
94
|
+
name: "conflux-core-local",
|
|
95
|
+
type: "core",
|
|
96
|
+
testnet: true,
|
|
97
|
+
nativeCurrency: {
|
|
98
|
+
name: "Conflux",
|
|
99
|
+
symbol: "CFX",
|
|
100
|
+
decimals: 18
|
|
101
|
+
},
|
|
102
|
+
rpcUrls: {
|
|
103
|
+
default: {
|
|
104
|
+
http: ["http://localhost:12537"],
|
|
105
|
+
webSocket: ["ws://localhost:12536"]
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
var EVM_MAINNET = {
|
|
110
|
+
id: 1030,
|
|
111
|
+
name: "conflux-espace",
|
|
112
|
+
type: "evm",
|
|
113
|
+
testnet: false,
|
|
114
|
+
nativeCurrency: {
|
|
115
|
+
name: "Conflux",
|
|
116
|
+
symbol: "CFX",
|
|
117
|
+
decimals: 18
|
|
118
|
+
},
|
|
119
|
+
rpcUrls: {
|
|
120
|
+
default: {
|
|
121
|
+
http: ["https://evm.confluxrpc.com"]
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
blockExplorers: {
|
|
125
|
+
default: {
|
|
126
|
+
name: "ConfluxScan eSpace",
|
|
127
|
+
url: "https://evm.confluxscan.net"
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
contracts: {
|
|
131
|
+
multicall3: {
|
|
132
|
+
address: "0xcA11bde05977b3631167028862bE2a173976CA11",
|
|
133
|
+
blockCreated: 62512243
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
var EVM_TESTNET = {
|
|
138
|
+
id: 71,
|
|
139
|
+
name: "conflux-espace-testnet",
|
|
140
|
+
type: "evm",
|
|
141
|
+
testnet: true,
|
|
142
|
+
nativeCurrency: {
|
|
143
|
+
name: "Conflux",
|
|
144
|
+
symbol: "CFX",
|
|
145
|
+
decimals: 18
|
|
146
|
+
},
|
|
147
|
+
rpcUrls: {
|
|
148
|
+
default: {
|
|
149
|
+
http: ["https://evmtestnet.confluxrpc.com"]
|
|
150
|
+
}
|
|
151
|
+
},
|
|
152
|
+
blockExplorers: {
|
|
153
|
+
default: {
|
|
154
|
+
name: "ConfluxScan eSpace Testnet",
|
|
155
|
+
url: "https://evmtestnet.confluxscan.net"
|
|
156
|
+
}
|
|
157
|
+
},
|
|
158
|
+
contracts: {
|
|
159
|
+
multicall3: {
|
|
160
|
+
address: "0xcA11bde05977b3631167028862bE2a173976CA11",
|
|
161
|
+
blockCreated: 117499050
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
var EVM_LOCAL = {
|
|
166
|
+
id: 2030,
|
|
167
|
+
name: "conflux-espace-local",
|
|
168
|
+
type: "evm",
|
|
169
|
+
testnet: true,
|
|
170
|
+
nativeCurrency: {
|
|
171
|
+
name: "Conflux",
|
|
172
|
+
symbol: "CFX",
|
|
173
|
+
decimals: 18
|
|
174
|
+
},
|
|
175
|
+
rpcUrls: {
|
|
176
|
+
default: {
|
|
177
|
+
http: ["http://localhost:8545"]
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
var SUPPORTED_CHAINS = {
|
|
182
|
+
1029: CORE_MAINNET,
|
|
183
|
+
1: CORE_TESTNET,
|
|
184
|
+
2029: CORE_LOCAL,
|
|
185
|
+
1030: EVM_MAINNET,
|
|
186
|
+
71: EVM_TESTNET,
|
|
187
|
+
2030: EVM_LOCAL
|
|
188
|
+
};
|
|
189
|
+
function getChainConfig(chainId) {
|
|
190
|
+
const config = SUPPORTED_CHAINS[chainId];
|
|
191
|
+
if (!config) {
|
|
192
|
+
throw new Error(`Unsupported chain ID: ${chainId}`);
|
|
193
|
+
}
|
|
194
|
+
return config;
|
|
195
|
+
}
|
|
196
|
+
function isValidChainId(chainId) {
|
|
197
|
+
return chainId in SUPPORTED_CHAINS;
|
|
198
|
+
}
|
|
199
|
+
function getCoreChains() {
|
|
200
|
+
return Object.values(SUPPORTED_CHAINS).filter(
|
|
201
|
+
(chain) => chain.type === "core"
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
function getEvmChains() {
|
|
205
|
+
return Object.values(SUPPORTED_CHAINS).filter(
|
|
206
|
+
(chain) => chain.type === "evm"
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
function getMainnetChains() {
|
|
210
|
+
return Object.values(SUPPORTED_CHAINS).filter((chain) => !chain.testnet);
|
|
211
|
+
}
|
|
212
|
+
function getTestnetChains() {
|
|
213
|
+
return Object.values(SUPPORTED_CHAINS).filter((chain) => chain.testnet);
|
|
214
|
+
}
|
|
215
|
+
function toCiveChain(config) {
|
|
216
|
+
if (config.type !== "core") {
|
|
217
|
+
throw new Error(`Cannot convert ${config.type} chain to Cive chain`);
|
|
218
|
+
}
|
|
219
|
+
return (0, import_utils.defineChain)({
|
|
220
|
+
id: config.id,
|
|
221
|
+
name: config.name,
|
|
222
|
+
nativeCurrency: config.nativeCurrency,
|
|
223
|
+
rpcUrls: config.rpcUrls,
|
|
224
|
+
blockExplorers: config.blockExplorers
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
function toViemChain(config) {
|
|
228
|
+
if (config.type !== "evm") {
|
|
229
|
+
throw new Error(`Cannot convert ${config.type} chain to Viem chain`);
|
|
230
|
+
}
|
|
231
|
+
return (0, import_viem.defineChain)({
|
|
232
|
+
id: config.id,
|
|
233
|
+
name: config.name,
|
|
234
|
+
nativeCurrency: config.nativeCurrency,
|
|
235
|
+
rpcUrls: config.rpcUrls,
|
|
236
|
+
blockExplorers: config.blockExplorers,
|
|
237
|
+
contracts: config.contracts
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
var NetworkSelector = class {
|
|
241
|
+
currentChainId;
|
|
242
|
+
previousChainId = null;
|
|
243
|
+
listeners = /* @__PURE__ */ new Set();
|
|
244
|
+
nodeRunningListeners = /* @__PURE__ */ new Set();
|
|
245
|
+
isNodeRunning = false;
|
|
246
|
+
lockedToLocal = false;
|
|
247
|
+
constructor(initialChainId = 1) {
|
|
248
|
+
this.currentChainId = initialChainId;
|
|
249
|
+
}
|
|
250
|
+
getCurrentChain() {
|
|
251
|
+
return getChainConfig(this.currentChainId);
|
|
252
|
+
}
|
|
253
|
+
getCurrentChainId() {
|
|
254
|
+
return this.currentChainId;
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Switch to a specific chain
|
|
258
|
+
* @param chainId - Chain ID to switch to
|
|
259
|
+
* @param force - Force switch even if node is running (for wallet operations)
|
|
260
|
+
*/
|
|
261
|
+
switchChain(chainId, force = false) {
|
|
262
|
+
if (!isValidChainId(chainId)) {
|
|
263
|
+
throw new Error(`Invalid chain ID: ${chainId}`);
|
|
264
|
+
}
|
|
265
|
+
if (this.isNodeRunning && !this.isLocalChain(chainId) && !force) {
|
|
266
|
+
console.warn(
|
|
267
|
+
`Cannot switch to chain ${chainId} while local node is running. Use force=true for wallet operations.`
|
|
268
|
+
);
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
271
|
+
if (this.currentChainId !== chainId) {
|
|
272
|
+
this.currentChainId = chainId;
|
|
273
|
+
this.notifyListeners();
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Called when local node starts - automatically switches to local chains
|
|
278
|
+
*/
|
|
279
|
+
onNodeStart(coreChainId = 2029, evmChainId = 2030) {
|
|
280
|
+
if (!this.isNodeRunning) {
|
|
281
|
+
if (!this.isLocal()) {
|
|
282
|
+
this.previousChainId = this.currentChainId;
|
|
283
|
+
}
|
|
284
|
+
this.isNodeRunning = true;
|
|
285
|
+
this.lockedToLocal = true;
|
|
286
|
+
const targetLocalChain = this.isEvm() ? evmChainId : coreChainId;
|
|
287
|
+
this.switchChain(targetLocalChain, true);
|
|
288
|
+
this.notifyNodeRunningListeners();
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Called when local node stops - can restore previous chain
|
|
293
|
+
*/
|
|
294
|
+
onNodeStop(restorePrevious = true) {
|
|
295
|
+
if (this.isNodeRunning) {
|
|
296
|
+
this.isNodeRunning = false;
|
|
297
|
+
this.lockedToLocal = false;
|
|
298
|
+
if (restorePrevious && this.previousChainId) {
|
|
299
|
+
this.switchChain(this.previousChainId, true);
|
|
300
|
+
this.previousChainId = null;
|
|
301
|
+
}
|
|
302
|
+
this.notifyNodeRunningListeners();
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Check if node is currently running
|
|
307
|
+
*/
|
|
308
|
+
getNodeRunningStatus() {
|
|
309
|
+
return this.isNodeRunning;
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Check if selector is locked to local chains
|
|
313
|
+
*/
|
|
314
|
+
isLockedToLocal() {
|
|
315
|
+
return this.lockedToLocal;
|
|
316
|
+
}
|
|
317
|
+
onChainChange(listener) {
|
|
318
|
+
this.listeners.add(listener);
|
|
319
|
+
return () => this.listeners.delete(listener);
|
|
320
|
+
}
|
|
321
|
+
onNodeRunningChange(listener) {
|
|
322
|
+
this.nodeRunningListeners.add(listener);
|
|
323
|
+
return () => this.nodeRunningListeners.delete(listener);
|
|
324
|
+
}
|
|
325
|
+
notifyListeners() {
|
|
326
|
+
for (const listener of this.listeners) {
|
|
327
|
+
try {
|
|
328
|
+
listener(this.currentChainId);
|
|
329
|
+
} catch (error) {
|
|
330
|
+
console.error("Error in chain change listener:", error);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
notifyNodeRunningListeners() {
|
|
335
|
+
for (const listener of this.nodeRunningListeners) {
|
|
336
|
+
try {
|
|
337
|
+
listener(this.isNodeRunning);
|
|
338
|
+
} catch (error) {
|
|
339
|
+
console.error("Error in node running listener:", error);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
isLocalChain(chainId) {
|
|
344
|
+
return chainId === 2029 || chainId === 2030;
|
|
345
|
+
}
|
|
346
|
+
// Helper methods for chain type detection
|
|
347
|
+
isCore() {
|
|
348
|
+
return this.getCurrentChain().type === "core";
|
|
349
|
+
}
|
|
350
|
+
isEvm() {
|
|
351
|
+
return this.getCurrentChain().type === "evm";
|
|
352
|
+
}
|
|
353
|
+
isTestnet() {
|
|
354
|
+
return this.getCurrentChain().testnet;
|
|
355
|
+
}
|
|
356
|
+
isLocal() {
|
|
357
|
+
return this.currentChainId === 2029 || this.currentChainId === 2030;
|
|
358
|
+
}
|
|
359
|
+
// Get corresponding chain IDs
|
|
360
|
+
getCorrespondingChainId() {
|
|
361
|
+
switch (this.currentChainId) {
|
|
362
|
+
case 1029:
|
|
363
|
+
return 1030;
|
|
364
|
+
// Core mainnet -> eSpace mainnet
|
|
365
|
+
case 1030:
|
|
366
|
+
return 1029;
|
|
367
|
+
// eSpace mainnet -> Core mainnet
|
|
368
|
+
case 1:
|
|
369
|
+
return 71;
|
|
370
|
+
// Core testnet -> eSpace testnet
|
|
371
|
+
case 71:
|
|
372
|
+
return 1;
|
|
373
|
+
// eSpace testnet -> Core testnet
|
|
374
|
+
case 2029:
|
|
375
|
+
return 2030;
|
|
376
|
+
// Core local -> eSpace local
|
|
377
|
+
case 2030:
|
|
378
|
+
return 2029;
|
|
379
|
+
// eSpace local -> Core local
|
|
380
|
+
default:
|
|
381
|
+
return null;
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* Update local chain configurations with actual node URLs
|
|
386
|
+
* Called when ServerManager starts with specific ports
|
|
387
|
+
*/
|
|
388
|
+
updateLocalChainUrls(coreRpcPort, evmRpcPort, wsPort) {
|
|
389
|
+
const coreLocal = SUPPORTED_CHAINS[2029];
|
|
390
|
+
if (coreLocal) {
|
|
391
|
+
coreLocal.rpcUrls.default.http = [`http://localhost:${coreRpcPort}`];
|
|
392
|
+
if (wsPort) {
|
|
393
|
+
coreLocal.rpcUrls.default.webSocket = [`ws://localhost:${wsPort}`];
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
const evmLocal = SUPPORTED_CHAINS[2030];
|
|
397
|
+
if (evmLocal) {
|
|
398
|
+
evmLocal.rpcUrls.default.http = [`http://localhost:${evmRpcPort}`];
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
};
|
|
402
|
+
var defaultNetworkSelector = new NetworkSelector();
|
|
403
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
404
|
+
0 && (module.exports = {
|
|
405
|
+
CORE_LOCAL,
|
|
406
|
+
CORE_MAINNET,
|
|
407
|
+
CORE_TESTNET,
|
|
408
|
+
EVM_LOCAL,
|
|
409
|
+
EVM_MAINNET,
|
|
410
|
+
EVM_TESTNET,
|
|
411
|
+
NetworkSelector,
|
|
412
|
+
SUPPORTED_CHAINS,
|
|
413
|
+
defaultNetworkSelector,
|
|
414
|
+
getChainConfig,
|
|
415
|
+
getCoreChains,
|
|
416
|
+
getEvmChains,
|
|
417
|
+
getMainnetChains,
|
|
418
|
+
getTestnetChains,
|
|
419
|
+
isValidChainId,
|
|
420
|
+
toCiveChain,
|
|
421
|
+
toViemChain
|
|
422
|
+
});
|
|
423
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/config/index.ts","../../src/config/chains.ts"],"sourcesContent":["/*\n * Copyright 2025 Conflux DevKit Team\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// Core package configuration exports\n\nexport * from './chains.js';\n","/*\n * Copyright 2025 Conflux DevKit Team\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// Centralized Chain Configuration\n// Matches Hardhat configuration with consistent naming across all clients\n\nimport type { Chain as CiveChain } from 'cive';\nimport { defineChain } from 'cive/utils';\nimport type { Chain as ViemChain } from 'viem';\nimport { defineChain as defineEvmChain } from 'viem';\n\nexport type SupportedChainId = 1029 | 1 | 2029 | 1030 | 71 | 2030;\n\nexport interface ChainConfig {\n id: SupportedChainId;\n name: string;\n type: 'core' | 'evm';\n testnet: boolean;\n nativeCurrency: {\n name: string;\n symbol: string;\n decimals: number;\n };\n rpcUrls: {\n default: {\n http: string[];\n webSocket?: string[];\n };\n };\n blockExplorers?: {\n default: {\n name: string;\n url: string;\n };\n };\n contracts?: {\n multicall3?: {\n address: `0x${string}`;\n blockCreated?: number;\n };\n };\n}\n\n// Core Space Chains (Conflux Protocol)\nexport const CORE_MAINNET: ChainConfig = {\n id: 1029,\n name: 'conflux-core',\n type: 'core',\n testnet: false,\n nativeCurrency: {\n name: 'Conflux',\n symbol: 'CFX',\n decimals: 18,\n },\n rpcUrls: {\n default: {\n http: ['https://main.confluxrpc.com'],\n webSocket: ['wss://main.confluxrpc.com/ws'],\n },\n },\n blockExplorers: {\n default: {\n name: 'ConfluxScan',\n url: 'https://confluxscan.io',\n },\n },\n};\n\nexport const CORE_TESTNET: ChainConfig = {\n id: 1,\n name: 'conflux-core-testnet',\n type: 'core',\n testnet: true,\n nativeCurrency: {\n name: 'Conflux',\n symbol: 'CFX',\n decimals: 18,\n },\n rpcUrls: {\n default: {\n http: ['https://test.confluxrpc.com'],\n webSocket: ['wss://test.confluxrpc.com/ws'],\n },\n },\n blockExplorers: {\n default: {\n name: 'ConfluxScan Testnet',\n url: 'https://testnet.confluxscan.io',\n },\n },\n};\n\nexport const CORE_LOCAL: ChainConfig = {\n id: 2029,\n name: 'conflux-core-local',\n type: 'core',\n testnet: true,\n nativeCurrency: {\n name: 'Conflux',\n symbol: 'CFX',\n decimals: 18,\n },\n rpcUrls: {\n default: {\n http: ['http://localhost:12537'],\n webSocket: ['ws://localhost:12536'],\n },\n },\n};\n\n// EVM Space Chains (Ethereum Compatible)\nexport const EVM_MAINNET: ChainConfig = {\n id: 1030,\n name: 'conflux-espace',\n type: 'evm',\n testnet: false,\n nativeCurrency: {\n name: 'Conflux',\n symbol: 'CFX',\n decimals: 18,\n },\n rpcUrls: {\n default: {\n http: ['https://evm.confluxrpc.com'],\n },\n },\n blockExplorers: {\n default: {\n name: 'ConfluxScan eSpace',\n url: 'https://evm.confluxscan.net',\n },\n },\n contracts: {\n multicall3: {\n address: '0xcA11bde05977b3631167028862bE2a173976CA11',\n blockCreated: 62512243,\n },\n },\n};\n\nexport const EVM_TESTNET: ChainConfig = {\n id: 71,\n name: 'conflux-espace-testnet',\n type: 'evm',\n testnet: true,\n nativeCurrency: {\n name: 'Conflux',\n symbol: 'CFX',\n decimals: 18,\n },\n rpcUrls: {\n default: {\n http: ['https://evmtestnet.confluxrpc.com'],\n },\n },\n blockExplorers: {\n default: {\n name: 'ConfluxScan eSpace Testnet',\n url: 'https://evmtestnet.confluxscan.net',\n },\n },\n contracts: {\n multicall3: {\n address: '0xcA11bde05977b3631167028862bE2a173976CA11',\n blockCreated: 117499050,\n },\n },\n};\n\nexport const EVM_LOCAL: ChainConfig = {\n id: 2030,\n name: 'conflux-espace-local',\n type: 'evm',\n testnet: true,\n nativeCurrency: {\n name: 'Conflux',\n symbol: 'CFX',\n decimals: 18,\n },\n rpcUrls: {\n default: {\n http: ['http://localhost:8545'],\n },\n },\n};\n\n// All supported chains\nexport const SUPPORTED_CHAINS: Record<SupportedChainId, ChainConfig> = {\n 1029: CORE_MAINNET,\n 1: CORE_TESTNET,\n 2029: CORE_LOCAL,\n 1030: EVM_MAINNET,\n 71: EVM_TESTNET,\n 2030: EVM_LOCAL,\n};\n\n// Chain utilities\nexport function getChainConfig(chainId: SupportedChainId): ChainConfig {\n const config = SUPPORTED_CHAINS[chainId];\n if (!config) {\n throw new Error(`Unsupported chain ID: ${chainId}`);\n }\n return config;\n}\n\nexport function isValidChainId(chainId: number): chainId is SupportedChainId {\n return chainId in SUPPORTED_CHAINS;\n}\n\nexport function getCoreChains(): ChainConfig[] {\n return Object.values(SUPPORTED_CHAINS).filter(\n (chain) => chain.type === 'core'\n );\n}\n\nexport function getEvmChains(): ChainConfig[] {\n return Object.values(SUPPORTED_CHAINS).filter(\n (chain) => chain.type === 'evm'\n );\n}\n\nexport function getMainnetChains(): ChainConfig[] {\n return Object.values(SUPPORTED_CHAINS).filter((chain) => !chain.testnet);\n}\n\nexport function getTestnetChains(): ChainConfig[] {\n return Object.values(SUPPORTED_CHAINS).filter((chain) => chain.testnet);\n}\n\n// Convert to native chain objects\nexport function toCiveChain(config: ChainConfig): CiveChain {\n if (config.type !== 'core') {\n throw new Error(`Cannot convert ${config.type} chain to Cive chain`);\n }\n\n return defineChain({\n id: config.id,\n name: config.name,\n nativeCurrency: config.nativeCurrency,\n rpcUrls: config.rpcUrls,\n blockExplorers: config.blockExplorers,\n });\n}\n\nexport function toViemChain(config: ChainConfig): ViemChain {\n if (config.type !== 'evm') {\n throw new Error(`Cannot convert ${config.type} chain to Viem chain`);\n }\n\n return defineEvmChain({\n id: config.id,\n name: config.name,\n nativeCurrency: config.nativeCurrency,\n rpcUrls: config.rpcUrls,\n blockExplorers: config.blockExplorers,\n contracts: config.contracts,\n });\n}\n\n// Network selector utility with automatic local switching\nexport class NetworkSelector {\n private currentChainId: SupportedChainId;\n private previousChainId: SupportedChainId | null = null;\n private listeners: Set<(chainId: SupportedChainId) => void> = new Set();\n private nodeRunningListeners: Set<(isRunning: boolean) => void> = new Set();\n private isNodeRunning = false;\n private lockedToLocal = false;\n\n constructor(initialChainId: SupportedChainId = 1) {\n this.currentChainId = initialChainId;\n }\n\n getCurrentChain(): ChainConfig {\n return getChainConfig(this.currentChainId);\n }\n\n getCurrentChainId(): SupportedChainId {\n return this.currentChainId;\n }\n\n /**\n * Switch to a specific chain\n * @param chainId - Chain ID to switch to\n * @param force - Force switch even if node is running (for wallet operations)\n */\n switchChain(chainId: SupportedChainId, force = false): void {\n if (!isValidChainId(chainId)) {\n throw new Error(`Invalid chain ID: ${chainId}`);\n }\n\n // If node is running and we're trying to switch to non-local, only allow if forced\n if (this.isNodeRunning && !this.isLocalChain(chainId) && !force) {\n console.warn(\n `Cannot switch to chain ${chainId} while local node is running. Use force=true for wallet operations.`\n );\n return;\n }\n\n if (this.currentChainId !== chainId) {\n this.currentChainId = chainId;\n this.notifyListeners();\n }\n }\n\n /**\n * Called when local node starts - automatically switches to local chains\n */\n onNodeStart(\n coreChainId: SupportedChainId = 2029,\n evmChainId: SupportedChainId = 2030\n ): void {\n if (!this.isNodeRunning) {\n // Store previous chain for restoration later\n if (!this.isLocal()) {\n this.previousChainId = this.currentChainId;\n }\n\n this.isNodeRunning = true;\n this.lockedToLocal = true;\n\n // Switch to appropriate local chain based on current chain type\n const targetLocalChain = this.isEvm() ? evmChainId : coreChainId;\n this.switchChain(targetLocalChain, true); // Force switch to local\n\n // Notify node running listeners\n this.notifyNodeRunningListeners();\n }\n }\n\n /**\n * Called when local node stops - can restore previous chain\n */\n onNodeStop(restorePrevious = true): void {\n if (this.isNodeRunning) {\n this.isNodeRunning = false;\n this.lockedToLocal = false;\n\n // Restore previous chain if requested and available\n if (restorePrevious && this.previousChainId) {\n this.switchChain(this.previousChainId, true);\n this.previousChainId = null;\n }\n\n // Notify node running listeners\n this.notifyNodeRunningListeners();\n }\n }\n\n /**\n * Check if node is currently running\n */\n getNodeRunningStatus(): boolean {\n return this.isNodeRunning;\n }\n\n /**\n * Check if selector is locked to local chains\n */\n isLockedToLocal(): boolean {\n return this.lockedToLocal;\n }\n\n onChainChange(listener: (chainId: SupportedChainId) => void): () => void {\n this.listeners.add(listener);\n return () => this.listeners.delete(listener);\n }\n\n onNodeRunningChange(listener: (isRunning: boolean) => void): () => void {\n this.nodeRunningListeners.add(listener);\n return () => this.nodeRunningListeners.delete(listener);\n }\n\n private notifyListeners(): void {\n for (const listener of this.listeners) {\n try {\n listener(this.currentChainId);\n } catch (error) {\n console.error('Error in chain change listener:', error);\n }\n }\n }\n\n private notifyNodeRunningListeners(): void {\n for (const listener of this.nodeRunningListeners) {\n try {\n listener(this.isNodeRunning);\n } catch (error) {\n console.error('Error in node running listener:', error);\n }\n }\n }\n\n private isLocalChain(chainId: SupportedChainId): boolean {\n return chainId === 2029 || chainId === 2030;\n }\n\n // Helper methods for chain type detection\n isCore(): boolean {\n return this.getCurrentChain().type === 'core';\n }\n\n isEvm(): boolean {\n return this.getCurrentChain().type === 'evm';\n }\n\n isTestnet(): boolean {\n return this.getCurrentChain().testnet;\n }\n\n isLocal(): boolean {\n return this.currentChainId === 2029 || this.currentChainId === 2030;\n }\n\n // Get corresponding chain IDs\n getCorrespondingChainId(): SupportedChainId | null {\n switch (this.currentChainId) {\n case 1029:\n return 1030; // Core mainnet -> eSpace mainnet\n case 1030:\n return 1029; // eSpace mainnet -> Core mainnet\n case 1:\n return 71; // Core testnet -> eSpace testnet\n case 71:\n return 1; // eSpace testnet -> Core testnet\n case 2029:\n return 2030; // Core local -> eSpace local\n case 2030:\n return 2029; // eSpace local -> Core local\n default:\n return null;\n }\n }\n\n /**\n * Update local chain configurations with actual node URLs\n * Called when ServerManager starts with specific ports\n */\n updateLocalChainUrls(\n coreRpcPort: number,\n evmRpcPort: number,\n wsPort?: number\n ): void {\n // Update Core local chain\n const coreLocal = SUPPORTED_CHAINS[2029];\n if (coreLocal) {\n coreLocal.rpcUrls.default.http = [`http://localhost:${coreRpcPort}`];\n if (wsPort) {\n coreLocal.rpcUrls.default.webSocket = [`ws://localhost:${wsPort}`];\n }\n }\n\n // Update eSpace local chain\n const evmLocal = SUPPORTED_CHAINS[2030];\n if (evmLocal) {\n evmLocal.rpcUrls.default.http = [`http://localhost:${evmRpcPort}`];\n }\n }\n}\n\n// Default network selector instance\nexport const defaultNetworkSelector = new NetworkSelector();\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACoBA,mBAA4B;AAE5B,kBAA8C;AAmCvC,IAAM,eAA4B;AAAA,EACvC,IAAI;AAAA,EACJ,MAAM;AAAA,EACN,MAAM;AAAA,EACN,SAAS;AAAA,EACT,gBAAgB;AAAA,IACd,MAAM;AAAA,IACN,QAAQ;AAAA,IACR,UAAU;AAAA,EACZ;AAAA,EACA,SAAS;AAAA,IACP,SAAS;AAAA,MACP,MAAM,CAAC,6BAA6B;AAAA,MACpC,WAAW,CAAC,8BAA8B;AAAA,IAC5C;AAAA,EACF;AAAA,EACA,gBAAgB;AAAA,IACd,SAAS;AAAA,MACP,MAAM;AAAA,MACN,KAAK;AAAA,IACP;AAAA,EACF;AACF;AAEO,IAAM,eAA4B;AAAA,EACvC,IAAI;AAAA,EACJ,MAAM;AAAA,EACN,MAAM;AAAA,EACN,SAAS;AAAA,EACT,gBAAgB;AAAA,IACd,MAAM;AAAA,IACN,QAAQ;AAAA,IACR,UAAU;AAAA,EACZ;AAAA,EACA,SAAS;AAAA,IACP,SAAS;AAAA,MACP,MAAM,CAAC,6BAA6B;AAAA,MACpC,WAAW,CAAC,8BAA8B;AAAA,IAC5C;AAAA,EACF;AAAA,EACA,gBAAgB;AAAA,IACd,SAAS;AAAA,MACP,MAAM;AAAA,MACN,KAAK;AAAA,IACP;AAAA,EACF;AACF;AAEO,IAAM,aAA0B;AAAA,EACrC,IAAI;AAAA,EACJ,MAAM;AAAA,EACN,MAAM;AAAA,EACN,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AAgB,EAAE,SAAS;AAAA,EACzC;AAAA,EAEA,QAAiB;AACf,WAAO,KAAK,gBAAgB,EAAE,SAAS;AAAA,EACzC;AAAA,EAEA,YAAqB;AACnB,WAAO,KAAK,gBAAgB,EAAE;AAAA,EAChC;AAAA,EAEA,UAAmB;AACjB,WAAO,KAAK,mBAAmB,QAAQ,KAAK,mBAAmB;AAAA,EACjE;AAAA;AAAA,EAGA,0BAAmD;AACjD,YAAQ,KAAK,gBAAgB;AAAA,MAC3B,KAAK;AACH,eAAO;AAAA;AAAA,MACT,KAAK;AACH,eAAO;AAAA;AAAA,MACT,KAAK;AACH,eAAO;AAAA;AAAA,MACT,KAAK;AACH,eAAO;AAAA;AAAA,MACT,KAAK;AACH,eAAO;AAAA;AAAA,MACT,KAAK;AACH,eAAO;AAAA;AAAA,MACT;AACE,eAAO;AAAA,IACX;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,qBACE,aACA,YACA,QACM;AAEN,UAAM,YAAY,iBAAiB,IAAI;AACvC,QAAI,WAAW;AACb,gBAAU,QAAQ,QAAQ,OAAO,CAAC,oBAAoB,WAAW,EAAE;AACnE,UAAI,QAAQ;AACV,kBAAU,QAAQ,QAAQ,YAAY,CAAC,kBAAkB,MAAM,EAAE;AAAA,MACnE;AAAA,IACF;AAGA,UAAM,WAAW,iBAAiB,IAAI;AACtC,QAAI,UAAU;AACZ,eAAS,QAAQ,QAAQ,OAAO,CAAC,oBAAoB,UAAU,EAAE;AAAA,IACnE;AAAA,EACF;AACF;AAGO,IAAM,yBAAyB,IAAI,gBAAgB;","names":["defineEvmChain"]}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { Chain } from 'cive';
|
|
2
|
+
import { Chain as Chain$1 } from 'viem';
|
|
3
|
+
|
|
4
|
+
type SupportedChainId = 1029 | 1 | 2029 | 1030 | 71 | 2030;
|
|
5
|
+
interface ChainConfig {
|
|
6
|
+
id: SupportedChainId;
|
|
7
|
+
name: string;
|
|
8
|
+
type: 'core' | 'evm';
|
|
9
|
+
testnet: boolean;
|
|
10
|
+
nativeCurrency: {
|
|
11
|
+
name: string;
|
|
12
|
+
symbol: string;
|
|
13
|
+
decimals: number;
|
|
14
|
+
};
|
|
15
|
+
rpcUrls: {
|
|
16
|
+
default: {
|
|
17
|
+
http: string[];
|
|
18
|
+
webSocket?: string[];
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
blockExplorers?: {
|
|
22
|
+
default: {
|
|
23
|
+
name: string;
|
|
24
|
+
url: string;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
contracts?: {
|
|
28
|
+
multicall3?: {
|
|
29
|
+
address: `0x${string}`;
|
|
30
|
+
blockCreated?: number;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
declare const CORE_MAINNET: ChainConfig;
|
|
35
|
+
declare const CORE_TESTNET: ChainConfig;
|
|
36
|
+
declare const CORE_LOCAL: ChainConfig;
|
|
37
|
+
declare const EVM_MAINNET: ChainConfig;
|
|
38
|
+
declare const EVM_TESTNET: ChainConfig;
|
|
39
|
+
declare const EVM_LOCAL: ChainConfig;
|
|
40
|
+
declare const SUPPORTED_CHAINS: Record<SupportedChainId, ChainConfig>;
|
|
41
|
+
declare function getChainConfig(chainId: SupportedChainId): ChainConfig;
|
|
42
|
+
declare function isValidChainId(chainId: number): chainId is SupportedChainId;
|
|
43
|
+
declare function getCoreChains(): ChainConfig[];
|
|
44
|
+
declare function getEvmChains(): ChainConfig[];
|
|
45
|
+
declare function getMainnetChains(): ChainConfig[];
|
|
46
|
+
declare function getTestnetChains(): ChainConfig[];
|
|
47
|
+
declare function toCiveChain(config: ChainConfig): Chain;
|
|
48
|
+
declare function toViemChain(config: ChainConfig): Chain$1;
|
|
49
|
+
declare class NetworkSelector {
|
|
50
|
+
private currentChainId;
|
|
51
|
+
private previousChainId;
|
|
52
|
+
private listeners;
|
|
53
|
+
private nodeRunningListeners;
|
|
54
|
+
private isNodeRunning;
|
|
55
|
+
private lockedToLocal;
|
|
56
|
+
constructor(initialChainId?: SupportedChainId);
|
|
57
|
+
getCurrentChain(): ChainConfig;
|
|
58
|
+
getCurrentChainId(): SupportedChainId;
|
|
59
|
+
/**
|
|
60
|
+
* Switch to a specific chain
|
|
61
|
+
* @param chainId - Chain ID to switch to
|
|
62
|
+
* @param force - Force switch even if node is running (for wallet operations)
|
|
63
|
+
*/
|
|
64
|
+
switchChain(chainId: SupportedChainId, force?: boolean): void;
|
|
65
|
+
/**
|
|
66
|
+
* Called when local node starts - automatically switches to local chains
|
|
67
|
+
*/
|
|
68
|
+
onNodeStart(coreChainId?: SupportedChainId, evmChainId?: SupportedChainId): void;
|
|
69
|
+
/**
|
|
70
|
+
* Called when local node stops - can restore previous chain
|
|
71
|
+
*/
|
|
72
|
+
onNodeStop(restorePrevious?: boolean): void;
|
|
73
|
+
/**
|
|
74
|
+
* Check if node is currently running
|
|
75
|
+
*/
|
|
76
|
+
getNodeRunningStatus(): boolean;
|
|
77
|
+
/**
|
|
78
|
+
* Check if selector is locked to local chains
|
|
79
|
+
*/
|
|
80
|
+
isLockedToLocal(): boolean;
|
|
81
|
+
onChainChange(listener: (chainId: SupportedChainId) => void): () => void;
|
|
82
|
+
onNodeRunningChange(listener: (isRunning: boolean) => void): () => void;
|
|
83
|
+
private notifyListeners;
|
|
84
|
+
private notifyNodeRunningListeners;
|
|
85
|
+
private isLocalChain;
|
|
86
|
+
isCore(): boolean;
|
|
87
|
+
isEvm(): boolean;
|
|
88
|
+
isTestnet(): boolean;
|
|
89
|
+
isLocal(): boolean;
|
|
90
|
+
getCorrespondingChainId(): SupportedChainId | null;
|
|
91
|
+
/**
|
|
92
|
+
* Update local chain configurations with actual node URLs
|
|
93
|
+
* Called when ServerManager starts with specific ports
|
|
94
|
+
*/
|
|
95
|
+
updateLocalChainUrls(coreRpcPort: number, evmRpcPort: number, wsPort?: number): void;
|
|
96
|
+
}
|
|
97
|
+
declare const defaultNetworkSelector: NetworkSelector;
|
|
98
|
+
|
|
99
|
+
export { CORE_LOCAL, CORE_MAINNET, CORE_TESTNET, type ChainConfig, EVM_LOCAL, EVM_MAINNET, EVM_TESTNET, NetworkSelector, SUPPORTED_CHAINS, type SupportedChainId, defaultNetworkSelector, getChainConfig, getCoreChains, getEvmChains, getMainnetChains, getTestnetChains, isValidChainId, toCiveChain, toViemChain };
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { Chain } from 'cive';
|
|
2
|
+
import { Chain as Chain$1 } from 'viem';
|
|
3
|
+
|
|
4
|
+
type SupportedChainId = 1029 | 1 | 2029 | 1030 | 71 | 2030;
|
|
5
|
+
interface ChainConfig {
|
|
6
|
+
id: SupportedChainId;
|
|
7
|
+
name: string;
|
|
8
|
+
type: 'core' | 'evm';
|
|
9
|
+
testnet: boolean;
|
|
10
|
+
nativeCurrency: {
|
|
11
|
+
name: string;
|
|
12
|
+
symbol: string;
|
|
13
|
+
decimals: number;
|
|
14
|
+
};
|
|
15
|
+
rpcUrls: {
|
|
16
|
+
default: {
|
|
17
|
+
http: string[];
|
|
18
|
+
webSocket?: string[];
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
blockExplorers?: {
|
|
22
|
+
default: {
|
|
23
|
+
name: string;
|
|
24
|
+
url: string;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
contracts?: {
|
|
28
|
+
multicall3?: {
|
|
29
|
+
address: `0x${string}`;
|
|
30
|
+
blockCreated?: number;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
declare const CORE_MAINNET: ChainConfig;
|
|
35
|
+
declare const CORE_TESTNET: ChainConfig;
|
|
36
|
+
declare const CORE_LOCAL: ChainConfig;
|
|
37
|
+
declare const EVM_MAINNET: ChainConfig;
|
|
38
|
+
declare const EVM_TESTNET: ChainConfig;
|
|
39
|
+
declare const EVM_LOCAL: ChainConfig;
|
|
40
|
+
declare const SUPPORTED_CHAINS: Record<SupportedChainId, ChainConfig>;
|
|
41
|
+
declare function getChainConfig(chainId: SupportedChainId): ChainConfig;
|
|
42
|
+
declare function isValidChainId(chainId: number): chainId is SupportedChainId;
|
|
43
|
+
declare function getCoreChains(): ChainConfig[];
|
|
44
|
+
declare function getEvmChains(): ChainConfig[];
|
|
45
|
+
declare function getMainnetChains(): ChainConfig[];
|
|
46
|
+
declare function getTestnetChains(): ChainConfig[];
|
|
47
|
+
declare function toCiveChain(config: ChainConfig): Chain;
|
|
48
|
+
declare function toViemChain(config: ChainConfig): Chain$1;
|
|
49
|
+
declare class NetworkSelector {
|
|
50
|
+
private currentChainId;
|
|
51
|
+
private previousChainId;
|
|
52
|
+
private listeners;
|
|
53
|
+
private nodeRunningListeners;
|
|
54
|
+
private isNodeRunning;
|
|
55
|
+
private lockedToLocal;
|
|
56
|
+
constructor(initialChainId?: SupportedChainId);
|
|
57
|
+
getCurrentChain(): ChainConfig;
|
|
58
|
+
getCurrentChainId(): SupportedChainId;
|
|
59
|
+
/**
|
|
60
|
+
* Switch to a specific chain
|
|
61
|
+
* @param chainId - Chain ID to switch to
|
|
62
|
+
* @param force - Force switch even if node is running (for wallet operations)
|
|
63
|
+
*/
|
|
64
|
+
switchChain(chainId: SupportedChainId, force?: boolean): void;
|
|
65
|
+
/**
|
|
66
|
+
* Called when local node starts - automatically switches to local chains
|
|
67
|
+
*/
|
|
68
|
+
onNodeStart(coreChainId?: SupportedChainId, evmChainId?: SupportedChainId): void;
|
|
69
|
+
/**
|
|
70
|
+
* Called when local node stops - can restore previous chain
|
|
71
|
+
*/
|
|
72
|
+
onNodeStop(restorePrevious?: boolean): void;
|
|
73
|
+
/**
|
|
74
|
+
* Check if node is currently running
|
|
75
|
+
*/
|
|
76
|
+
getNodeRunningStatus(): boolean;
|
|
77
|
+
/**
|
|
78
|
+
* Check if selector is locked to local chains
|
|
79
|
+
*/
|
|
80
|
+
isLockedToLocal(): boolean;
|
|
81
|
+
onChainChange(listener: (chainId: SupportedChainId) => void): () => void;
|
|
82
|
+
onNodeRunningChange(listener: (isRunning: boolean) => void): () => void;
|
|
83
|
+
private notifyListeners;
|
|
84
|
+
private notifyNodeRunningListeners;
|
|
85
|
+
private isLocalChain;
|
|
86
|
+
isCore(): boolean;
|
|
87
|
+
isEvm(): boolean;
|
|
88
|
+
isTestnet(): boolean;
|
|
89
|
+
isLocal(): boolean;
|
|
90
|
+
getCorrespondingChainId(): SupportedChainId | null;
|
|
91
|
+
/**
|
|
92
|
+
* Update local chain configurations with actual node URLs
|
|
93
|
+
* Called when ServerManager starts with specific ports
|
|
94
|
+
*/
|
|
95
|
+
updateLocalChainUrls(coreRpcPort: number, evmRpcPort: number, wsPort?: number): void;
|
|
96
|
+
}
|
|
97
|
+
declare const defaultNetworkSelector: NetworkSelector;
|
|
98
|
+
|
|
99
|
+
export { CORE_LOCAL, CORE_MAINNET, CORE_TESTNET, type ChainConfig, EVM_LOCAL, EVM_MAINNET, EVM_TESTNET, NetworkSelector, SUPPORTED_CHAINS, type SupportedChainId, defaultNetworkSelector, getChainConfig, getCoreChains, getEvmChains, getMainnetChains, getTestnetChains, isValidChainId, toCiveChain, toViemChain };
|