rocketh 0.15.0-testing.6 → 0.15.0-testing.7
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 +6 -0
- package/dist/cli.js.map +1 -1
- package/dist/environment/index.d.ts +3 -2
- package/dist/environment/index.d.ts.map +1 -1
- package/dist/environment/index.js +27 -51
- package/dist/environment/index.js.map +1 -1
- package/dist/environment/types.d.ts +44 -74
- package/dist/environment/types.d.ts.map +1 -1
- package/dist/environment/utils/chains.d.ts +3 -3
- package/dist/environment/utils/chains.d.ts.map +1 -1
- package/dist/environment/utils/chains.js +92 -27
- package/dist/environment/utils/chains.js.map +1 -1
- package/dist/executor/index.d.ts +24 -23
- package/dist/executor/index.d.ts.map +1 -1
- package/dist/executor/index.js +130 -237
- package/dist/executor/index.js.map +1 -1
- package/dist/executor/setup.test.js +1 -1
- package/dist/executor/setup.test.js.map +1 -1
- package/dist/utils/fs.d.ts +1 -1
- package/dist/utils/fs.d.ts.map +1 -1
- package/dist/utils/fs.js.map +1 -1
- package/package.json +1 -1
- package/src/cli.ts +2 -2
- package/src/environment/index.ts +31 -55
- package/src/environment/types.ts +39 -91
- package/src/environment/utils/chains.ts +119 -29
- package/src/executor/index.ts +184 -286
- package/src/executor/setup.test.ts +1 -1
- package/src/utils/fs.ts +1 -1
package/src/environment/index.ts
CHANGED
|
@@ -9,7 +9,6 @@ import {
|
|
|
9
9
|
PendingDeployment,
|
|
10
10
|
PendingTransaction,
|
|
11
11
|
ResolvedAccount,
|
|
12
|
-
ResolvedConfig,
|
|
13
12
|
ResolvedNamedAccounts,
|
|
14
13
|
ResolvedNamedSigners,
|
|
15
14
|
UnknownDeployments,
|
|
@@ -17,8 +16,8 @@ import {
|
|
|
17
16
|
UnresolvedNetworkSpecificData,
|
|
18
17
|
ResolvedNetworkSpecificData,
|
|
19
18
|
DataType,
|
|
19
|
+
ResolvedExecutionParams,
|
|
20
20
|
} from './types.js';
|
|
21
|
-
import {JSONRPCHTTPProvider} from 'eip-1193-jsonrpc-provider';
|
|
22
21
|
import {Abi, Address} from 'abitype';
|
|
23
22
|
import {InternalEnvironment} from '../internal/types.js';
|
|
24
23
|
import path from 'node:path';
|
|
@@ -29,16 +28,14 @@ import {
|
|
|
29
28
|
EIP1193Block,
|
|
30
29
|
EIP1193BlockWithTransactions,
|
|
31
30
|
EIP1193DATA,
|
|
32
|
-
EIP1193ProviderWithoutEvents,
|
|
33
|
-
EIP1193QUANTITY,
|
|
34
31
|
EIP1193Transaction,
|
|
35
32
|
EIP1193TransactionReceipt,
|
|
36
33
|
} from 'eip-1193';
|
|
37
34
|
import {ProgressIndicator, log, spin} from '../internal/logging.js';
|
|
38
35
|
import {PendingExecution} from './types.js';
|
|
39
|
-
import {getChainWithConfig} from './utils/chains.js';
|
|
40
36
|
import {mergeArtifacts} from './utils/artifacts.js';
|
|
41
37
|
import {TransactionHashTracker, TransactionHashTrackerProvider} from './providers/TransactionHashTracker.js';
|
|
38
|
+
import {ResolvedUserConfig} from '../executor/index.js';
|
|
42
39
|
|
|
43
40
|
export type SignerProtocolFunction = (protocolString: string) => Promise<Signer>;
|
|
44
41
|
export type SignerProtocol = {
|
|
@@ -66,12 +63,10 @@ export async function createEnvironment<
|
|
|
66
63
|
Data extends UnresolvedNetworkSpecificData = UnresolvedNetworkSpecificData,
|
|
67
64
|
Deployments extends UnknownDeployments = UnknownDeployments
|
|
68
65
|
>(
|
|
69
|
-
|
|
66
|
+
userConfig: ResolvedUserConfig<NamedAccounts, Data>,
|
|
67
|
+
resolvedExecutionParams: ResolvedExecutionParams
|
|
70
68
|
): Promise<{internal: InternalEnvironment; external: Environment<NamedAccounts, Data, Deployments>}> {
|
|
71
|
-
const rawProvider =
|
|
72
|
-
'provider' in config.target
|
|
73
|
-
? config.target.provider
|
|
74
|
-
: (new JSONRPCHTTPProvider(config.target.nodeUrl) as EIP1193ProviderWithoutEvents);
|
|
69
|
+
const rawProvider = resolvedExecutionParams.provider;
|
|
75
70
|
|
|
76
71
|
const provider: TransactionHashTracker = new TransactionHashTrackerProvider(rawProvider);
|
|
77
72
|
|
|
@@ -95,34 +90,14 @@ export async function createEnvironment<
|
|
|
95
90
|
console.error(`failed to get genesis block`);
|
|
96
91
|
}
|
|
97
92
|
|
|
98
|
-
|
|
99
|
-
|
|
93
|
+
const deploymentsFolder = userConfig.deployments || 'deployments';
|
|
94
|
+
const targetName = resolvedExecutionParams.target.name;
|
|
95
|
+
const saveDeployments = resolvedExecutionParams.saveDeployments;
|
|
100
96
|
let networkTags: {[tag: string]: boolean} = {};
|
|
101
|
-
for (const networkTag of
|
|
97
|
+
for (const networkTag of resolvedExecutionParams.target.tags) {
|
|
102
98
|
networkTags[networkTag] = true;
|
|
103
99
|
}
|
|
104
100
|
|
|
105
|
-
if ('nodeUrl' in config) {
|
|
106
|
-
networkName = config.target.name;
|
|
107
|
-
saveDeployments = true;
|
|
108
|
-
} else {
|
|
109
|
-
if (config.target.name) {
|
|
110
|
-
networkName = config.target.name;
|
|
111
|
-
} else {
|
|
112
|
-
networkName = 'memory';
|
|
113
|
-
}
|
|
114
|
-
if (networkName === 'memory' || networkName === 'hardhat' || networkName === 'default') {
|
|
115
|
-
networkTags['memory'] = true;
|
|
116
|
-
saveDeployments = false;
|
|
117
|
-
} else {
|
|
118
|
-
saveDeployments = true;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
if (config.saveDeployments !== undefined) {
|
|
123
|
-
saveDeployments = config.saveDeployments;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
101
|
const resolvedAccounts: {[name: string]: ResolvedAccount} = {};
|
|
127
102
|
|
|
128
103
|
const allRemoteAccounts = await provider.request({method: 'eth_accounts'});
|
|
@@ -149,7 +124,7 @@ export async function createEnvironment<
|
|
|
149
124
|
} else if (typeof accountDef === 'string') {
|
|
150
125
|
if (accountDef.startsWith('0x')) {
|
|
151
126
|
if (accountDef.length === 66) {
|
|
152
|
-
const privateKeyProtocol =
|
|
127
|
+
const privateKeyProtocol = userConfig.signerProtocols?.['privateKey'];
|
|
153
128
|
if (privateKeyProtocol) {
|
|
154
129
|
const namedSigner = await privateKeyProtocol(`privateKey:${accountDef}`);
|
|
155
130
|
const [address] = await namedSigner.signer.request({method: 'eth_accounts'});
|
|
@@ -168,7 +143,7 @@ export async function createEnvironment<
|
|
|
168
143
|
} else {
|
|
169
144
|
if (accountDef.indexOf(':') > 0) {
|
|
170
145
|
const [protocolID, extra] = accountDef.split(':');
|
|
171
|
-
const protocol =
|
|
146
|
+
const protocol = userConfig.signerProtocols?.[protocolID];
|
|
172
147
|
if (!protocol) {
|
|
173
148
|
throw new Error(`protocol: ${protocolID} is not supported`);
|
|
174
149
|
}
|
|
@@ -186,7 +161,8 @@ export async function createEnvironment<
|
|
|
186
161
|
}
|
|
187
162
|
}
|
|
188
163
|
} else {
|
|
189
|
-
|
|
164
|
+
// TODO allow for canonical chain name ?
|
|
165
|
+
const accountForNetwork = accountDef[targetName] || accountDef[chainId] || accountDef['default'];
|
|
190
166
|
if (typeof accountForNetwork !== undefined) {
|
|
191
167
|
const accountFetched = await getAccount(name, accounts, accountForNetwork);
|
|
192
168
|
if (accountFetched) {
|
|
@@ -198,24 +174,24 @@ export async function createEnvironment<
|
|
|
198
174
|
return account;
|
|
199
175
|
}
|
|
200
176
|
|
|
201
|
-
if (
|
|
202
|
-
const accountNames = Object.keys(
|
|
177
|
+
if (userConfig.accounts) {
|
|
178
|
+
const accountNames = Object.keys(userConfig.accounts);
|
|
203
179
|
for (const accountName of accountNames) {
|
|
204
|
-
let account = await getAccount(accountName,
|
|
180
|
+
let account = await getAccount(accountName, userConfig.accounts, userConfig.accounts[accountName]);
|
|
205
181
|
(resolvedAccounts as any)[accountName] = account;
|
|
206
182
|
}
|
|
207
183
|
}
|
|
208
184
|
|
|
209
185
|
const resolvedData: ResolvedNetworkSpecificData<Data> = {} as ResolvedNetworkSpecificData<Data>;
|
|
210
186
|
async function getData<T = unknown>(name: string, dataDef: DataType<T>): Promise<T | undefined> {
|
|
211
|
-
const dataForNetwork = dataDef[
|
|
187
|
+
const dataForNetwork = dataDef[targetName] || dataDef[chainId] || dataDef['default'];
|
|
212
188
|
return dataForNetwork;
|
|
213
189
|
}
|
|
214
190
|
|
|
215
|
-
if (
|
|
216
|
-
const dataFields = Object.keys(
|
|
191
|
+
if (userConfig.data) {
|
|
192
|
+
const dataFields = Object.keys(userConfig.data);
|
|
217
193
|
for (const dataField of dataFields) {
|
|
218
|
-
let fieldData = await getData(dataField,
|
|
194
|
+
let fieldData = await getData(dataField, userConfig.data[dataField]);
|
|
219
195
|
(resolvedData as any)[dataField] = fieldData;
|
|
220
196
|
}
|
|
221
197
|
}
|
|
@@ -224,8 +200,7 @@ export async function createEnvironment<
|
|
|
224
200
|
accounts: resolvedAccounts,
|
|
225
201
|
data: resolvedData,
|
|
226
202
|
network: {
|
|
227
|
-
|
|
228
|
-
fork: config.target.fork,
|
|
203
|
+
fork: resolvedExecutionParams.target.fork,
|
|
229
204
|
saveDeployments,
|
|
230
205
|
tags: networkTags,
|
|
231
206
|
},
|
|
@@ -234,8 +209,8 @@ export async function createEnvironment<
|
|
|
234
209
|
// console.log(`context`, JSON.stringify(context.network, null, 2));
|
|
235
210
|
|
|
236
211
|
const {deployments, migrations} = loadDeployments(
|
|
237
|
-
|
|
238
|
-
|
|
212
|
+
deploymentsFolder,
|
|
213
|
+
targetName,
|
|
239
214
|
false,
|
|
240
215
|
context.network.fork
|
|
241
216
|
? undefined
|
|
@@ -267,7 +242,8 @@ export async function createEnvironment<
|
|
|
267
242
|
}
|
|
268
243
|
|
|
269
244
|
const perliminaryEnvironment = {
|
|
270
|
-
|
|
245
|
+
name: targetName,
|
|
246
|
+
tags: context.network.tags,
|
|
271
247
|
deployments: deployments as Deployments,
|
|
272
248
|
namedAccounts: namedAccounts as ResolvedNamedAccounts<NamedAccounts>,
|
|
273
249
|
data: resolvedData,
|
|
@@ -275,16 +251,16 @@ export async function createEnvironment<
|
|
|
275
251
|
unnamedAccounts,
|
|
276
252
|
addressSigners: addressSigners,
|
|
277
253
|
network: {
|
|
278
|
-
chain:
|
|
279
|
-
|
|
280
|
-
tags: context.network.tags,
|
|
254
|
+
chain: resolvedExecutionParams.chain,
|
|
255
|
+
fork: context.network.fork,
|
|
281
256
|
provider,
|
|
257
|
+
deterministicDeployment: resolvedExecutionParams.target.deterministicDeployment,
|
|
282
258
|
},
|
|
283
|
-
extra:
|
|
259
|
+
extra: resolvedExecutionParams.extra || {},
|
|
284
260
|
};
|
|
285
261
|
|
|
286
262
|
function getDeploymentFolder(): string {
|
|
287
|
-
const folderPath = path.join(
|
|
263
|
+
const folderPath = path.join(deploymentsFolder, targetName);
|
|
288
264
|
return folderPath;
|
|
289
265
|
}
|
|
290
266
|
|
|
@@ -458,7 +434,7 @@ export async function createEnvironment<
|
|
|
458
434
|
// confirmations?: number; // TODO
|
|
459
435
|
// timeout?: number; // TODO
|
|
460
436
|
}): Promise<EIP1193TransactionReceipt> {
|
|
461
|
-
const {hash, pollingInterval} = {pollingInterval:
|
|
437
|
+
const {hash, pollingInterval} = {pollingInterval: resolvedExecutionParams.pollingInterval, ...params};
|
|
462
438
|
|
|
463
439
|
let receipt: EIP1193TransactionReceipt | null = null;
|
|
464
440
|
try {
|
package/src/environment/types.ts
CHANGED
|
@@ -9,14 +9,9 @@ import {
|
|
|
9
9
|
EIP1193WalletProvider,
|
|
10
10
|
} from 'eip-1193';
|
|
11
11
|
import type {Address, Chain, DeployContractParameters} from 'viem';
|
|
12
|
-
import {
|
|
13
|
-
DeterministicDeploymentInfo,
|
|
14
|
-
type Create2DeterministicDeploymentInfo,
|
|
15
|
-
type Create3DeterministicDeploymentInfo,
|
|
16
|
-
} from '../executor/index.js';
|
|
12
|
+
import {ConfigOverrides, DeterministicDeploymentInfo} from '../executor/index.js';
|
|
17
13
|
import {ProgressIndicator} from '../internal/logging.js';
|
|
18
14
|
import {TransactionHashTracker} from './providers/TransactionHashTracker.js';
|
|
19
|
-
import {SignerProtocolFunction} from './index.js';
|
|
20
15
|
import {ChainInfo} from '../executor/types.js';
|
|
21
16
|
|
|
22
17
|
export type {Abi, AbiConstructor, AbiError, AbiEvent, AbiFallback, AbiFunction, AbiReceive};
|
|
@@ -231,84 +226,36 @@ export type ResolvedNamedSigners<T extends UnknownNamedAccounts> = {
|
|
|
231
226
|
|
|
232
227
|
export type UnknownDeploymentsAcrossNetworks = Record<string, UnknownDeployments>;
|
|
233
228
|
|
|
234
|
-
type
|
|
235
|
-
|
|
236
|
-
tags: string[];
|
|
237
|
-
fork?: boolean;
|
|
238
|
-
deterministicDeployment?: DeterministicDeploymentInfo;
|
|
239
|
-
scripts?: string | string[];
|
|
240
|
-
chainInfo: ChainInfo;
|
|
241
|
-
pollingInterval?: number;
|
|
242
|
-
};
|
|
243
|
-
type TargetConfigForJSONRPC = TargetConfigBase & {
|
|
244
|
-
nodeUrl: string;
|
|
245
|
-
};
|
|
246
|
-
|
|
247
|
-
type TargetConfigForEIP1193Provider = TargetConfigBase & {
|
|
248
|
-
provider: EIP1193ProviderWithoutEvents;
|
|
249
|
-
};
|
|
250
|
-
|
|
251
|
-
export type TargetConfig = TargetConfigForJSONRPC | TargetConfigForEIP1193Provider;
|
|
252
|
-
|
|
253
|
-
type ResolvedTargetConfigBase = {
|
|
254
|
-
name: string;
|
|
255
|
-
tags: string[];
|
|
256
|
-
fork?: boolean;
|
|
257
|
-
deterministicDeployment: DeterministicDeploymentInfo;
|
|
258
|
-
chainInfo: ChainInfo;
|
|
259
|
-
pollingInterval: number;
|
|
260
|
-
};
|
|
261
|
-
type ResolvedTargetConfigForJSONRPC = ResolvedTargetConfigBase & {
|
|
262
|
-
nodeUrl: string;
|
|
263
|
-
};
|
|
264
|
-
|
|
265
|
-
type ResolvedTargetConfigForEIP1193Provider = ResolvedTargetConfigBase & {
|
|
266
|
-
provider: EIP1193ProviderWithoutEvents;
|
|
267
|
-
};
|
|
268
|
-
|
|
269
|
-
export type ResolvedTargetConfig = ResolvedTargetConfigForJSONRPC | ResolvedTargetConfigForEIP1193Provider;
|
|
270
|
-
|
|
271
|
-
export type Config<
|
|
272
|
-
AccountsType extends UnresolvedUnknownNamedAccounts = UnresolvedUnknownNamedAccounts,
|
|
273
|
-
Data extends UnresolvedNetworkSpecificData = UnresolvedNetworkSpecificData
|
|
274
|
-
> = {
|
|
275
|
-
target: TargetConfig;
|
|
276
|
-
targetTags?: string[];
|
|
277
|
-
scripts?: string | string[];
|
|
278
|
-
deployments?: string;
|
|
279
|
-
saveDeployments?: boolean;
|
|
280
|
-
|
|
229
|
+
export type ExecutionParams<Extra extends Record<string, unknown> = Record<string, unknown>> = {
|
|
230
|
+
target?: string | {fork: string};
|
|
281
231
|
tags?: string[];
|
|
232
|
+
saveDeployments?: boolean;
|
|
282
233
|
askBeforeProceeding?: boolean;
|
|
283
234
|
reportGasUse?: boolean;
|
|
284
|
-
|
|
285
|
-
logLevel?: number;
|
|
286
|
-
// TODO
|
|
287
|
-
gasPricing?: {};
|
|
288
|
-
accounts?: AccountsType;
|
|
289
|
-
|
|
290
|
-
data?: Data;
|
|
291
|
-
signerProtocols?: Record<string, SignerProtocolFunction>;
|
|
292
|
-
extra?: Record<string, unknown>;
|
|
293
235
|
defaultPollingInterval?: number;
|
|
236
|
+
extra?: Extra;
|
|
237
|
+
logLevel?: number;
|
|
238
|
+
provider?: EIP1193ProviderWithoutEvents;
|
|
239
|
+
config: ConfigOverrides;
|
|
294
240
|
};
|
|
295
241
|
|
|
296
|
-
export type
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
242
|
+
export type ResolvedExecutionParams<Extra extends Record<string, unknown> = Record<string, unknown>> = {
|
|
243
|
+
readonly target: {
|
|
244
|
+
readonly name: string;
|
|
245
|
+
readonly tags: readonly string[];
|
|
246
|
+
readonly fork?: boolean;
|
|
247
|
+
readonly deterministicDeployment: DeterministicDeploymentInfo;
|
|
248
|
+
};
|
|
249
|
+
readonly chain: ChainInfo;
|
|
250
|
+
readonly tags: readonly string[];
|
|
251
|
+
readonly saveDeployments: boolean;
|
|
252
|
+
readonly askBeforeProceeding: boolean;
|
|
253
|
+
readonly reportGasUse: boolean;
|
|
254
|
+
readonly pollingInterval: number;
|
|
255
|
+
readonly extra?: Extra;
|
|
256
|
+
readonly logLevel: number;
|
|
257
|
+
readonly provider: EIP1193ProviderWithoutEvents;
|
|
258
|
+
readonly scripts: readonly string[];
|
|
312
259
|
};
|
|
313
260
|
|
|
314
261
|
export interface Environment<
|
|
@@ -317,20 +264,21 @@ export interface Environment<
|
|
|
317
264
|
Deployments extends UnknownDeployments = UnknownDeployments,
|
|
318
265
|
Extra extends Record<string, unknown> = Record<string, unknown>
|
|
319
266
|
> {
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
267
|
+
readonly name: string;
|
|
268
|
+
readonly tags: {readonly [tag: string]: boolean};
|
|
269
|
+
readonly network: {
|
|
270
|
+
readonly chain: Chain;
|
|
271
|
+
readonly provider: TransactionHashTracker;
|
|
272
|
+
readonly fork?: boolean;
|
|
273
|
+
readonly deterministicDeployment: DeterministicDeploymentInfo;
|
|
326
274
|
};
|
|
327
|
-
deployments: Deployments;
|
|
328
|
-
namedAccounts: ResolvedNamedAccounts<NamedAccounts>;
|
|
329
|
-
data: ResolvedNetworkSpecificData<Data>;
|
|
330
|
-
namedSigners: ResolvedNamedSigners<ResolvedNamedAccounts<NamedAccounts>>;
|
|
331
|
-
unnamedAccounts: EIP1193Account[];
|
|
275
|
+
readonly deployments: Deployments;
|
|
276
|
+
readonly namedAccounts: ResolvedNamedAccounts<NamedAccounts>;
|
|
277
|
+
readonly data: ResolvedNetworkSpecificData<Data>;
|
|
278
|
+
readonly namedSigners: ResolvedNamedSigners<ResolvedNamedAccounts<NamedAccounts>>;
|
|
279
|
+
readonly unnamedAccounts: EIP1193Account[];
|
|
332
280
|
// unnamedSigners: {type: 'remote'; signer: EIP1193ProviderWithoutEvents}[];
|
|
333
|
-
addressSigners: {[name: `0x${string}`]: Signer};
|
|
281
|
+
readonly addressSigners: {[name: `0x${string}`]: Signer};
|
|
334
282
|
save<TAbi extends Abi = Abi>(
|
|
335
283
|
name: string,
|
|
336
284
|
deployment: Deployment<TAbi>,
|
|
@@ -346,7 +294,7 @@ export interface Environment<
|
|
|
346
294
|
showProgress(message?: string): ProgressIndicator;
|
|
347
295
|
|
|
348
296
|
hasMigrationBeenDone(id: string): boolean;
|
|
349
|
-
extra?: Extra;
|
|
297
|
+
readonly extra?: Extra;
|
|
350
298
|
}
|
|
351
299
|
|
|
352
300
|
export type DeploymentConstruction<TAbi extends Abi> = Omit<
|
|
@@ -1,8 +1,14 @@
|
|
|
1
|
-
import type {Chain} from 'viem/chains';
|
|
2
1
|
import * as chains from 'viem/chains';
|
|
3
|
-
import {ResolvedConfig} from '../types.js';
|
|
4
2
|
import {kebabCase} from 'change-case';
|
|
5
3
|
import {ChainInfo} from '../../executor/types.js';
|
|
4
|
+
import {
|
|
5
|
+
ChainConfig,
|
|
6
|
+
ChainUserConfig,
|
|
7
|
+
Create2DeterministicDeploymentInfo,
|
|
8
|
+
Create3DeterministicDeploymentInfo,
|
|
9
|
+
ResolvedUserConfig,
|
|
10
|
+
UserConfig,
|
|
11
|
+
} from '../../executor/index.js';
|
|
6
12
|
|
|
7
13
|
export type ChainType = 'zksync' | 'op-stack' | 'celo' | 'default';
|
|
8
14
|
|
|
@@ -31,7 +37,7 @@ export const chainTypes: {[chainId: string]: ChainType} = {};
|
|
|
31
37
|
|
|
32
38
|
export const chainById: {[chainId: string]: ChainInfo} = {};
|
|
33
39
|
export const allChains = {...((chains as any).default || chains)};
|
|
34
|
-
|
|
40
|
+
allChains['localhost'] = allChains['hardhat'];
|
|
35
41
|
|
|
36
42
|
for (const key of Object.keys(allChains)) {
|
|
37
43
|
const chain = (allChains as any)[key] as ChainInfo;
|
|
@@ -50,7 +56,7 @@ for (const key of Object.keys(allChains)) {
|
|
|
50
56
|
chainByCanonicalName[canonicalName] = chain;
|
|
51
57
|
}
|
|
52
58
|
|
|
53
|
-
export function
|
|
59
|
+
export function getChainById(id: string | number): ChainInfo | undefined {
|
|
54
60
|
const chain = chainById['' + id];
|
|
55
61
|
|
|
56
62
|
return chain;
|
|
@@ -61,35 +67,119 @@ export function getChainByName(name: string): ChainInfo | undefined {
|
|
|
61
67
|
return chain;
|
|
62
68
|
}
|
|
63
69
|
|
|
64
|
-
export function
|
|
65
|
-
|
|
66
|
-
|
|
70
|
+
export function getChainConfig(id: number, config: ResolvedUserConfig): ChainConfig {
|
|
71
|
+
const defaultChainInfo = getChainById(id);
|
|
72
|
+
const canonicalName = defaultChainInfo ? kebabCase(defaultChainInfo.name) : undefined;
|
|
73
|
+
if (canonicalName) {
|
|
74
|
+
if (config.chains?.[id] && config.chains?.[canonicalName]) {
|
|
75
|
+
throw new Error(
|
|
76
|
+
`chain should be configured by chainId or name but not both, remove either ${id} or ${canonicalName}`
|
|
77
|
+
);
|
|
78
|
+
}
|
|
67
79
|
}
|
|
68
80
|
|
|
69
|
-
|
|
70
|
-
if (
|
|
71
|
-
|
|
81
|
+
let chainConfig: ChainUserConfig | undefined = config.chains?.[id];
|
|
82
|
+
if (!chainConfig && canonicalName) {
|
|
83
|
+
chainConfig = config.chains?.[canonicalName];
|
|
72
84
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
if (!('nodeUrl' in config.target)) {
|
|
76
|
-
console.error(`no nodeUrl found either for ${config.target.name}`);
|
|
77
|
-
} else {
|
|
78
|
-
nodeUrl = config.target.nodeUrl;
|
|
85
|
+
if (!chainConfig) {
|
|
86
|
+
chainConfig = {info: defaultChainInfo};
|
|
79
87
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
88
|
+
|
|
89
|
+
let chainInfo = chainConfig?.info || defaultChainInfo;
|
|
90
|
+
|
|
91
|
+
let rpcUrl = process.env['ETH_NODE_URI_' + id];
|
|
92
|
+
if (canonicalName) {
|
|
93
|
+
const fromEnv = process.env['ETH_NODE_URI_' + canonicalName];
|
|
94
|
+
if (fromEnv) {
|
|
95
|
+
rpcUrl = fromEnv;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (!rpcUrl) {
|
|
100
|
+
rpcUrl = chainConfig.rpcUrl;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (!rpcUrl) {
|
|
104
|
+
rpcUrl = chainConfig.info?.rpcUrls.default.http[0];
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (!rpcUrl) {
|
|
108
|
+
if (id === 31337 || id === 1337) {
|
|
109
|
+
rpcUrl = 'http://127.0.0.1:8545';
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (!chainInfo) {
|
|
114
|
+
if (!rpcUrl) {
|
|
115
|
+
throw new Error(`no chain info found for chain with id ${id}`);
|
|
116
|
+
} else {
|
|
117
|
+
console.error(`chain with id ${id} has no public info`);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
chainInfo = {
|
|
121
|
+
id,
|
|
122
|
+
name: 'unkwown',
|
|
123
|
+
nativeCurrency: {
|
|
124
|
+
name: 'Unknown Currency',
|
|
125
|
+
symbol: 'UNKNOWN',
|
|
126
|
+
decimals: 18,
|
|
127
|
+
},
|
|
128
|
+
rpcUrls: {
|
|
129
|
+
default: {
|
|
130
|
+
http: [rpcUrl],
|
|
131
|
+
},
|
|
91
132
|
},
|
|
92
|
-
|
|
93
|
-
|
|
133
|
+
chainType: 'default',
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const create2Info = {
|
|
138
|
+
factory: '0x4e59b44847b379578588920ca78fbf26c0b4956c',
|
|
139
|
+
deployer: '0x3fab184622dc19b6109349b94811493bf2a45362',
|
|
140
|
+
funding: '10000000000000000',
|
|
141
|
+
signedTx:
|
|
142
|
+
'0xf8a58085174876e800830186a08080b853604580600e600039806000f350fe7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe03601600081602082378035828234f58015156039578182fd5b8082525050506014600cf31ba02222222222222222222222222222222222222222222222222222222222222222a02222222222222222222222222222222222222222222222222222222222222222',
|
|
143
|
+
} as const;
|
|
144
|
+
const create3Info = {
|
|
145
|
+
factory: '0x000000000004d4f168daE7DB3C610F408eE22F57',
|
|
146
|
+
salt: '0x5361109ca02853ca8e22046b7125306d9ec4ae4cdecc393c567b6be861df3db6',
|
|
147
|
+
bytecode:
|
|
148
|
+
'0x6080604052348015600f57600080fd5b506103ca8061001f6000396000f3fe6080604052600436106100295760003560e01c8063360d0fad1461002e5780639881d19514610077575b600080fd5b34801561003a57600080fd5b5061004e610049366004610228565b61008a565b60405173ffffffffffffffffffffffffffffffffffffffff909116815260200160405180910390f35b61004e61008536600461029c565b6100ee565b6040517fffffffffffffffffffffffffffffffffffffffff000000000000000000000000606084901b166020820152603481018290526000906054016040516020818303038152906040528051906020012091506100e78261014c565b9392505050565b6040517fffffffffffffffffffffffffffffffffffffffff0000000000000000000000003360601b166020820152603481018290526000906054016040516020818303038152906040528051906020012091506100e734848461015e565b600061015882306101ce565b92915050565b60006f67363d3d37363d34f03d5260086018f3600052816010806000f58061018e5763301164256000526004601cfd5b8060145261d69460005260016034536017601e20915060008085516020870188855af1823b026101c65763301164256000526004601cfd5b509392505050565b60006040518260005260ff600b53836020527f21c35dbe1b344a2488cf3321d6ce542f8e9f305544ff09e4993a62319a497c1f6040526055600b20601452806040525061d694600052600160345350506017601e20919050565b6000806040838503121561023b57600080fd5b823573ffffffffffffffffffffffffffffffffffffffff8116811461025f57600080fd5b946020939093013593505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b600080604083850312156102af57600080fd5b823567ffffffffffffffff8111156102c657600080fd5b8301601f810185136102d757600080fd5b803567ffffffffffffffff8111156102f1576102f161026d565b6040517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0603f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f8501160116810181811067ffffffffffffffff8211171561035d5761035d61026d565b60405281815282820160200187101561037557600080fd5b816020840160208301376000602092820183015296940135945050505056fea264697066735822122059dcc5dc6453397d13ff28021e28472a80a45bbd97f3135f69bd2650773aeb0164736f6c634300081a0033',
|
|
149
|
+
proxyBytecode: '0x67363d3d37363d34f03d5260086018f3',
|
|
150
|
+
} as const;
|
|
151
|
+
|
|
152
|
+
const pollingInterval = chainConfig.pollingInterval || config.defaultPollingInterval || 1;
|
|
153
|
+
|
|
154
|
+
let deterministicDeployment: {
|
|
155
|
+
create2: Create2DeterministicDeploymentInfo;
|
|
156
|
+
create3: Create3DeterministicDeploymentInfo;
|
|
157
|
+
} = {
|
|
158
|
+
create2: (() => {
|
|
159
|
+
if (!chainConfig.deterministicDeployment) return create2Info;
|
|
160
|
+
if (!('create3' in chainConfig.deterministicDeployment) && !('create2' in chainConfig.deterministicDeployment))
|
|
161
|
+
return create2Info;
|
|
162
|
+
return chainConfig.deterministicDeployment.create2 || create2Info;
|
|
163
|
+
})(),
|
|
164
|
+
create3:
|
|
165
|
+
chainConfig.deterministicDeployment &&
|
|
166
|
+
'create3' in chainConfig.deterministicDeployment &&
|
|
167
|
+
chainConfig.deterministicDeployment.create3
|
|
168
|
+
? chainConfig.deterministicDeployment.create3
|
|
169
|
+
: create3Info,
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
const defaultTags: string[] = [];
|
|
173
|
+
if (chainInfo.testnet) {
|
|
174
|
+
defaultTags.push('testnet');
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
return {
|
|
178
|
+
info: {...chainInfo},
|
|
179
|
+
deterministicDeployment,
|
|
180
|
+
pollingInterval,
|
|
181
|
+
properties: chainConfig.properties || {},
|
|
182
|
+
rpcUrl: rpcUrl || chainInfo.rpcUrls.default.http[0],
|
|
183
|
+
tags: chainConfig.tags || [...defaultTags],
|
|
94
184
|
};
|
|
95
185
|
}
|