rocketh 0.15.0-testing.5 → 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 +12 -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 +93 -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 +121 -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/executor/index.ts
CHANGED
|
@@ -5,12 +5,10 @@ import prompts from 'prompts';
|
|
|
5
5
|
import {tsImport as tsImport_} from 'tsx/esm/api';
|
|
6
6
|
import {formatEther} from 'viem';
|
|
7
7
|
import type {
|
|
8
|
-
Config,
|
|
9
8
|
Environment,
|
|
9
|
+
ExecutionParams,
|
|
10
10
|
JSONTypePlusBigInt,
|
|
11
|
-
|
|
12
|
-
ResolvedTargetConfig,
|
|
13
|
-
TargetConfig,
|
|
11
|
+
ResolvedExecutionParams,
|
|
14
12
|
UnknownDeployments,
|
|
15
13
|
UnresolvedNetworkSpecificData,
|
|
16
14
|
UnresolvedUnknownNamedAccounts,
|
|
@@ -27,7 +25,7 @@ import {withEnvironment} from '../utils/extensions.js';
|
|
|
27
25
|
import {logger, setLogLevel, spin} from '../internal/logging.js';
|
|
28
26
|
import {getRoughGasPriceEstimate} from '../utils/eth.js';
|
|
29
27
|
import {traverseMultipleDirectory} from '../utils/fs.js';
|
|
30
|
-
import {
|
|
28
|
+
import {getChainByName, getChainConfig} from '../environment/utils/chains.js';
|
|
31
29
|
import {JSONRPCHTTPProvider} from 'eip-1193-jsonrpc-provider';
|
|
32
30
|
|
|
33
31
|
// @ts-ignore
|
|
@@ -93,18 +91,21 @@ export function setup<
|
|
|
93
91
|
return scriptModule;
|
|
94
92
|
}
|
|
95
93
|
|
|
96
|
-
async function loadAndExecuteDeploymentsWithExtensions<
|
|
97
|
-
|
|
94
|
+
async function loadAndExecuteDeploymentsWithExtensions<
|
|
95
|
+
Extra extends Record<string, unknown> = Record<string, unknown>,
|
|
96
|
+
ArgumentsType = undefined
|
|
97
|
+
>(
|
|
98
|
+
executionParams: ExecutionParams<Extra>,
|
|
98
99
|
args?: ArgumentsType
|
|
99
100
|
): Promise<EnhancedEnvironment<NamedAccounts, Data, UnknownDeployments, Extensions>> {
|
|
100
|
-
const env = await loadAndExecuteDeployments<NamedAccounts, Data, ArgumentsType, Extra>(
|
|
101
|
+
const env = await loadAndExecuteDeployments<NamedAccounts, Data, ArgumentsType, Extra>(executionParams, args);
|
|
101
102
|
return enhanceEnvIfNeeded(env, extensions);
|
|
102
103
|
}
|
|
103
104
|
|
|
104
105
|
async function loadEnvironmentWithExtensions(
|
|
105
|
-
|
|
106
|
+
executionParams: ExecutionParams<Extra>
|
|
106
107
|
): Promise<EnhancedEnvironment<NamedAccounts, Data, UnknownDeployments, Extensions>> {
|
|
107
|
-
const env = await loadEnvironment<NamedAccounts, Data, Extra>(
|
|
108
|
+
const env = await loadEnvironment<NamedAccounts, Data, Extra>(executionParams);
|
|
108
109
|
return enhanceEnvIfNeeded(env, extensions);
|
|
109
110
|
}
|
|
110
111
|
|
|
@@ -156,18 +157,9 @@ export type UntypedEIP1193Provider = {
|
|
|
156
157
|
request(requestArguments: UntypedRequestArguments): Promise<unknown>;
|
|
157
158
|
};
|
|
158
159
|
|
|
159
|
-
export type
|
|
160
|
-
target?: string | {fork: string};
|
|
160
|
+
export type ConfigOverrides = {
|
|
161
161
|
deployments?: string;
|
|
162
162
|
scripts?: string | string[];
|
|
163
|
-
tags?: string;
|
|
164
|
-
logLevel?: number;
|
|
165
|
-
provider?: EIP1193ProviderWithoutEvents | EIP1193GenericRequestProvider | UntypedEIP1193Provider;
|
|
166
|
-
ignoreMissingRPC?: boolean;
|
|
167
|
-
saveDeployments?: boolean;
|
|
168
|
-
askBeforeProceeding?: boolean;
|
|
169
|
-
reportGasUse?: boolean;
|
|
170
|
-
extra?: Extra;
|
|
171
163
|
};
|
|
172
164
|
|
|
173
165
|
export type Create2DeterministicDeploymentInfo = {
|
|
@@ -200,6 +192,15 @@ export type ChainUserConfig = {
|
|
|
200
192
|
properties?: Record<string, JSONTypePlusBigInt>;
|
|
201
193
|
};
|
|
202
194
|
|
|
195
|
+
export type ChainConfig = {
|
|
196
|
+
rpcUrl: string;
|
|
197
|
+
tags: string[];
|
|
198
|
+
deterministicDeployment: DeterministicDeploymentInfo;
|
|
199
|
+
info: ChainInfo;
|
|
200
|
+
pollingInterval: number;
|
|
201
|
+
properties: Record<string, JSONTypePlusBigInt>;
|
|
202
|
+
};
|
|
203
|
+
|
|
203
204
|
export type DeploymentTargetConfig = {
|
|
204
205
|
chainId: number;
|
|
205
206
|
scripts?: string | string[];
|
|
@@ -223,172 +224,19 @@ export type UserConfig<
|
|
|
223
224
|
defaultPollingInterval?: number;
|
|
224
225
|
};
|
|
225
226
|
|
|
226
|
-
export
|
|
227
|
+
export type ResolvedUserConfig<
|
|
227
228
|
NamedAccounts extends UnresolvedUnknownNamedAccounts = UnresolvedUnknownNamedAccounts,
|
|
228
|
-
Data extends UnresolvedNetworkSpecificData = UnresolvedNetworkSpecificData
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
if (configFile) {
|
|
235
|
-
if (!options.deployments && configFile.deployments) {
|
|
236
|
-
options.deployments = configFile.deployments;
|
|
237
|
-
}
|
|
238
|
-
if (!options.scripts && configFile.scripts) {
|
|
239
|
-
options.scripts = configFile.scripts;
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
const targetProvided = options.target || (options as any).network; // fallback on network
|
|
244
|
-
const fork = typeof targetProvided !== 'string';
|
|
245
|
-
let targetName = 'memory';
|
|
246
|
-
if (targetProvided) {
|
|
247
|
-
if (typeof targetProvided === 'string') {
|
|
248
|
-
targetName = targetProvided;
|
|
249
|
-
} else if ('fork' in targetProvided) {
|
|
250
|
-
targetName = targetProvided.fork;
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
let chainInfo: ChainInfo;
|
|
255
|
-
|
|
256
|
-
let chainId: number;
|
|
257
|
-
|
|
258
|
-
if (configFile?.targets?.[targetName]) {
|
|
259
|
-
chainId = configFile.targets[targetName].chainId;
|
|
260
|
-
} else {
|
|
261
|
-
const chainFound = getChainByName(targetName);
|
|
262
|
-
if (chainFound) {
|
|
263
|
-
chainInfo = chainFound;
|
|
264
|
-
chainId = chainInfo.id;
|
|
265
|
-
} else {
|
|
266
|
-
if (options.provider) {
|
|
267
|
-
const chainIdAsHex = await (options.provider as EIP1193ProviderWithoutEvents).request({method: 'eth_chainId'});
|
|
268
|
-
chainId = Number(chainIdAsHex);
|
|
269
|
-
} else {
|
|
270
|
-
throw new Error(`target ${targetName} is unknown`);
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
const chainConfigFromChainId = configFile?.chains?.[chainId];
|
|
276
|
-
const chainConfigFromChainName = configFile?.chains?.[targetName];
|
|
277
|
-
if (chainConfigFromChainId && chainConfigFromChainName) {
|
|
278
|
-
throw new Error(
|
|
279
|
-
`conflicting config for chain, choose to configure via its chainId (${chainId}) or via its name ${targetName} but not both`
|
|
280
|
-
);
|
|
281
|
-
}
|
|
282
|
-
const chainConfig = chainConfigFromChainId || chainConfigFromChainName;
|
|
283
|
-
|
|
284
|
-
const targetConfig = configFile?.targets?.[targetName];
|
|
285
|
-
const actualChainConfig = targetConfig?.overrides
|
|
286
|
-
? {
|
|
287
|
-
...chainConfig,
|
|
288
|
-
...targetConfig.overrides,
|
|
289
|
-
properties: {
|
|
290
|
-
...chainConfig?.properties,
|
|
291
|
-
...targetConfig.overrides.properties,
|
|
292
|
-
},
|
|
293
|
-
}
|
|
294
|
-
: chainConfig;
|
|
295
|
-
|
|
296
|
-
const defaultTags: string[] = [];
|
|
297
|
-
|
|
298
|
-
const chainFound = actualChainConfig?.info || getChain(chainId);
|
|
299
|
-
if (chainFound) {
|
|
300
|
-
chainInfo = chainFound;
|
|
301
|
-
} else {
|
|
302
|
-
throw new Error(`chain with id ${chainId} has no chainInfo associated with it`);
|
|
303
|
-
}
|
|
304
|
-
if (chainInfo.testnet) {
|
|
305
|
-
defaultTags.push('testnet');
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
if (actualChainConfig?.properties) {
|
|
309
|
-
chainInfo = {...chainInfo, properties: actualChainConfig.properties};
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
let targetTags: string[] = actualChainConfig?.tags || defaultTags;
|
|
313
|
-
|
|
314
|
-
let networkScripts: string | string[] | undefined = targetConfig?.scripts;
|
|
315
|
-
|
|
316
|
-
// no default for publicInfo
|
|
317
|
-
const defaultPollingInterval = configFile?.defaultPollingInterval;
|
|
318
|
-
const pollingInterval = actualChainConfig?.pollingInterval;
|
|
319
|
-
const deterministicDeployment = actualChainConfig?.deterministicDeployment;
|
|
320
|
-
const properties = actualChainConfig?.properties;
|
|
321
|
-
|
|
322
|
-
let resolvedTargetConfig: TargetConfig;
|
|
323
|
-
|
|
324
|
-
if (!options.provider) {
|
|
325
|
-
let rpcURL = actualChainConfig?.rpcUrl;
|
|
326
|
-
if (!rpcURL) {
|
|
327
|
-
rpcURL = chainInfo.rpcUrls.default.http[0];
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
const fromEnv = process.env['ETH_NODE_URI_' + targetName];
|
|
331
|
-
let nodeUrl: string;
|
|
332
|
-
if (typeof fromEnv === 'string' && fromEnv) {
|
|
333
|
-
nodeUrl = fromEnv;
|
|
334
|
-
} else {
|
|
335
|
-
if (rpcURL) {
|
|
336
|
-
nodeUrl = rpcURL;
|
|
337
|
-
} else if (options?.ignoreMissingRPC) {
|
|
338
|
-
nodeUrl = '';
|
|
339
|
-
} else if (targetProvided === 'localhost') {
|
|
340
|
-
nodeUrl = 'http://127.0.0.1:8545';
|
|
341
|
-
} else {
|
|
342
|
-
console.error(`network "${targetProvided}" is not configured. Please add it to the rocketh.js/ts file`);
|
|
343
|
-
process.exit(1);
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
resolvedTargetConfig = {
|
|
348
|
-
nodeUrl,
|
|
349
|
-
name: targetName,
|
|
350
|
-
tags: targetTags,
|
|
351
|
-
fork,
|
|
352
|
-
deterministicDeployment,
|
|
353
|
-
scripts: networkScripts,
|
|
354
|
-
chainInfo,
|
|
355
|
-
pollingInterval,
|
|
356
|
-
};
|
|
357
|
-
} else {
|
|
358
|
-
resolvedTargetConfig = {
|
|
359
|
-
provider: options.provider as EIP1193ProviderWithoutEvents,
|
|
360
|
-
name: targetName,
|
|
361
|
-
tags: targetTags,
|
|
362
|
-
fork,
|
|
363
|
-
deterministicDeployment,
|
|
364
|
-
scripts: networkScripts,
|
|
365
|
-
chainInfo,
|
|
366
|
-
pollingInterval,
|
|
367
|
-
};
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
return {
|
|
371
|
-
target: resolvedTargetConfig,
|
|
372
|
-
deployments: options.deployments,
|
|
373
|
-
saveDeployments: options.saveDeployments,
|
|
374
|
-
scripts: options.scripts,
|
|
375
|
-
data: configFile?.data,
|
|
376
|
-
tags: typeof options.tags === 'undefined' ? undefined : options.tags.split(','),
|
|
377
|
-
logLevel: options.logLevel,
|
|
378
|
-
askBeforeProceeding: options.askBeforeProceeding,
|
|
379
|
-
reportGasUse: options.reportGasUse,
|
|
380
|
-
accounts: configFile?.accounts,
|
|
381
|
-
signerProtocols: configFile?.signerProtocols,
|
|
382
|
-
extra: options.extra,
|
|
383
|
-
defaultPollingInterval,
|
|
384
|
-
};
|
|
385
|
-
}
|
|
229
|
+
Data extends UnresolvedNetworkSpecificData = UnresolvedNetworkSpecificData
|
|
230
|
+
> = UserConfig & {
|
|
231
|
+
deployments: string;
|
|
232
|
+
scripts: string[];
|
|
233
|
+
defaultPollingInterval: number;
|
|
234
|
+
};
|
|
386
235
|
|
|
387
236
|
export async function readConfig<
|
|
388
237
|
NamedAccounts extends UnresolvedUnknownNamedAccounts = UnresolvedUnknownNamedAccounts,
|
|
389
|
-
Data extends UnresolvedNetworkSpecificData = UnresolvedNetworkSpecificData
|
|
390
|
-
|
|
391
|
-
>(options: ConfigOptions<Extra>): Promise<Config<NamedAccounts, Data>> {
|
|
238
|
+
Data extends UnresolvedNetworkSpecificData = UnresolvedNetworkSpecificData
|
|
239
|
+
>(overrides: ConfigOverrides): Promise<ResolvedUserConfig<NamedAccounts, Data>> {
|
|
392
240
|
type ConfigFile = UserConfig<NamedAccounts, Data>;
|
|
393
241
|
let configFile: ConfigFile | undefined;
|
|
394
242
|
|
|
@@ -427,59 +275,90 @@ export async function readConfig<
|
|
|
427
275
|
configFile = moduleLoaded.config;
|
|
428
276
|
}
|
|
429
277
|
|
|
430
|
-
|
|
278
|
+
const config = {
|
|
279
|
+
deployments: 'deployments',
|
|
280
|
+
defaultPollingInterval: 1,
|
|
281
|
+
...configFile,
|
|
282
|
+
scripts: configFile?.scripts
|
|
283
|
+
? typeof configFile.scripts === 'string'
|
|
284
|
+
? [configFile.scripts]
|
|
285
|
+
: configFile.scripts
|
|
286
|
+
: ['deploy'],
|
|
287
|
+
};
|
|
288
|
+
|
|
289
|
+
for (const key of Object.keys(overrides)) {
|
|
290
|
+
if ((overrides as any)[key] !== undefined) {
|
|
291
|
+
(config as any)[key] = (overrides as any)[key];
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
return config;
|
|
431
296
|
}
|
|
432
297
|
|
|
433
|
-
export async function
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
298
|
+
export async function getChainIdForTarget(
|
|
299
|
+
config: ResolvedUserConfig,
|
|
300
|
+
targetName: string,
|
|
301
|
+
provider?: EIP1193ProviderWithoutEvents
|
|
302
|
+
) {
|
|
303
|
+
if (config?.targets?.[targetName]?.chainId) {
|
|
304
|
+
return config.targets[targetName].chainId;
|
|
305
|
+
} else {
|
|
306
|
+
const chainFound = getChainByName(targetName);
|
|
307
|
+
if (chainFound) {
|
|
308
|
+
return chainFound.id;
|
|
309
|
+
} else {
|
|
310
|
+
if (provider) {
|
|
311
|
+
const chainIdAsHex = await provider.request({method: 'eth_chainId'});
|
|
312
|
+
return Number(chainIdAsHex);
|
|
313
|
+
} else {
|
|
314
|
+
throw new Error(`target ${targetName} chain id cannot be found, specify it in the rocketh config`);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
439
318
|
}
|
|
440
319
|
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
320
|
+
function getTargetName(targetProvided?: string | {fork: string}) {
|
|
321
|
+
let targetName = 'memory';
|
|
322
|
+
if (targetProvided) {
|
|
323
|
+
if (typeof targetProvided === 'string') {
|
|
324
|
+
targetName = targetProvided;
|
|
325
|
+
} else if ('fork' in targetProvided) {
|
|
326
|
+
targetName = targetProvided.fork;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
return targetName;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
export function resolveExecutionParams<Extra extends Record<string, unknown> = Record<string, unknown>>(
|
|
333
|
+
config: ResolvedUserConfig,
|
|
334
|
+
executionParameters: ExecutionParams<Extra>,
|
|
335
|
+
chainId: number
|
|
336
|
+
): ResolvedExecutionParams<Extra> {
|
|
337
|
+
const targetProvided = executionParameters.target || (executionParameters as any).network; // fallback on network
|
|
338
|
+
const fork = typeof targetProvided !== 'string';
|
|
339
|
+
let targetName = getTargetName(targetProvided);
|
|
340
|
+
|
|
341
|
+
let chainConfig: ChainConfig = getChainConfig(chainId, config);
|
|
342
|
+
|
|
343
|
+
let chainInfo = chainConfig.info;
|
|
344
|
+
const targetConfig = config?.targets?.[targetName];
|
|
345
|
+
const actualChainConfig = targetConfig?.overrides
|
|
346
|
+
? {
|
|
347
|
+
...chainConfig,
|
|
348
|
+
...targetConfig.overrides,
|
|
349
|
+
properties: {
|
|
350
|
+
...chainConfig?.properties,
|
|
351
|
+
...targetConfig.overrides.properties,
|
|
352
|
+
},
|
|
353
|
+
}
|
|
354
|
+
: chainConfig;
|
|
355
|
+
|
|
356
|
+
if (actualChainConfig?.properties) {
|
|
357
|
+
chainInfo = {...chainInfo, properties: actualChainConfig.properties};
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
// let targetTags: string[] = actualChainConfig.tags.concat(targetConfig?.tags); // TODO
|
|
361
|
+
const targetTags = actualChainConfig.tags;
|
|
483
362
|
|
|
484
363
|
let scripts = ['deploy'];
|
|
485
364
|
if (config.scripts) {
|
|
@@ -490,63 +369,69 @@ export function resolveConfig<
|
|
|
490
369
|
}
|
|
491
370
|
}
|
|
492
371
|
|
|
493
|
-
if (
|
|
494
|
-
if (typeof
|
|
495
|
-
scripts = [
|
|
372
|
+
if (targetConfig?.scripts) {
|
|
373
|
+
if (typeof targetConfig.scripts === 'string') {
|
|
374
|
+
scripts = [targetConfig.scripts];
|
|
496
375
|
} else {
|
|
497
|
-
scripts =
|
|
376
|
+
scripts = targetConfig.scripts;
|
|
498
377
|
}
|
|
499
378
|
}
|
|
500
379
|
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
tags: config.target.tags,
|
|
518
|
-
fork: config.target.fork,
|
|
519
|
-
deterministicDeployment,
|
|
520
|
-
chainInfo: config.target.chainInfo,
|
|
521
|
-
pollingInterval: networkPollingInterval,
|
|
522
|
-
};
|
|
380
|
+
const provider =
|
|
381
|
+
executionParameters.provider || (new JSONRPCHTTPProvider(actualChainConfig.rpcUrl) as EIP1193ProviderWithoutEvents);
|
|
382
|
+
|
|
383
|
+
let saveDeployments = executionParameters.saveDeployments;
|
|
384
|
+
|
|
385
|
+
if (saveDeployments === undefined) {
|
|
386
|
+
if (!executionParameters.provider) {
|
|
387
|
+
saveDeployments = true;
|
|
388
|
+
} else {
|
|
389
|
+
if (targetName === 'memory' || targetName === 'hardhat' || targetName === 'default') {
|
|
390
|
+
// networkTags['memory'] = true;
|
|
391
|
+
saveDeployments = false;
|
|
392
|
+
} else {
|
|
393
|
+
saveDeployments = true;
|
|
394
|
+
}
|
|
395
|
+
}
|
|
523
396
|
}
|
|
524
397
|
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
398
|
+
return {
|
|
399
|
+
askBeforeProceeding: executionParameters.askBeforeProceeding || false,
|
|
400
|
+
chain: chainInfo,
|
|
401
|
+
logLevel: executionParameters.logLevel || 0, // TODO
|
|
402
|
+
pollingInterval: actualChainConfig.pollingInterval,
|
|
403
|
+
reportGasUse: executionParameters.reportGasUse || false,
|
|
404
|
+
saveDeployments,
|
|
405
|
+
tags: executionParameters.tags || [],
|
|
406
|
+
target: {
|
|
407
|
+
name: targetName,
|
|
408
|
+
tags: targetTags,
|
|
409
|
+
fork,
|
|
410
|
+
deterministicDeployment: actualChainConfig.deterministicDeployment,
|
|
411
|
+
},
|
|
412
|
+
extra: executionParameters.extra,
|
|
413
|
+
provider,
|
|
529
414
|
scripts,
|
|
530
|
-
tags: config.tags || [],
|
|
531
|
-
targetTags: config.targetTags || [],
|
|
532
|
-
saveDeployments: config.saveDeployments,
|
|
533
|
-
accounts: config.accounts || ({} as NamedAccounts),
|
|
534
|
-
data: config.data || ({} as Data),
|
|
535
|
-
signerProtocols: config.signerProtocols || {},
|
|
536
|
-
extra: config.extra || {},
|
|
537
|
-
defaultPollingInterval,
|
|
538
415
|
};
|
|
539
|
-
return resolvedConfig;
|
|
540
416
|
}
|
|
541
417
|
|
|
542
418
|
export async function loadEnvironment<
|
|
543
419
|
NamedAccounts extends UnresolvedUnknownNamedAccounts = UnresolvedUnknownNamedAccounts,
|
|
544
420
|
Data extends UnresolvedNetworkSpecificData = UnresolvedNetworkSpecificData,
|
|
545
421
|
Extra extends Record<string, unknown> = Record<string, unknown>
|
|
546
|
-
>(
|
|
547
|
-
const
|
|
422
|
+
>(executionParams: ExecutionParams<Extra>): Promise<Environment<NamedAccounts, Data, UnknownDeployments>> {
|
|
423
|
+
const userConfig = await readConfig<NamedAccounts, Data>(executionParams.config);
|
|
424
|
+
const chainId = await getChainIdForTarget(
|
|
425
|
+
userConfig,
|
|
426
|
+
getTargetName(executionParams.target),
|
|
427
|
+
executionParams.provider
|
|
428
|
+
);
|
|
429
|
+
const resolvedExecutionParams = resolveExecutionParams(userConfig, executionParams, chainId);
|
|
548
430
|
// console.log(JSON.stringify(resolvedConfig, null, 2));
|
|
549
|
-
const {external, internal} = await createEnvironment(
|
|
431
|
+
const {external, internal} = await createEnvironment<NamedAccounts, Data, UnknownDeployments>(
|
|
432
|
+
userConfig,
|
|
433
|
+
resolvedExecutionParams
|
|
434
|
+
);
|
|
550
435
|
return external;
|
|
551
436
|
}
|
|
552
437
|
|
|
@@ -555,11 +440,20 @@ export async function loadAndExecuteDeployments<
|
|
|
555
440
|
Data extends UnresolvedNetworkSpecificData = UnresolvedNetworkSpecificData,
|
|
556
441
|
ArgumentsType = undefined,
|
|
557
442
|
Extra extends Record<string, unknown> = Record<string, unknown>
|
|
558
|
-
>(
|
|
559
|
-
|
|
443
|
+
>(
|
|
444
|
+
executionParams: ExecutionParams<Extra>,
|
|
445
|
+
args?: ArgumentsType
|
|
446
|
+
): Promise<Environment<NamedAccounts, Data, UnknownDeployments>> {
|
|
447
|
+
const userConfig = await readConfig<NamedAccounts, Data>(executionParams.config);
|
|
448
|
+
const chainId = await getChainIdForTarget(
|
|
449
|
+
userConfig,
|
|
450
|
+
getTargetName(executionParams.target),
|
|
451
|
+
executionParams.provider
|
|
452
|
+
);
|
|
453
|
+
const resolvedExecutionParams = resolveExecutionParams(userConfig, executionParams, chainId);
|
|
560
454
|
// console.log(JSON.stringify(options, null, 2));
|
|
561
455
|
// console.log(JSON.stringify(resolvedConfig, null, 2));
|
|
562
|
-
return executeDeployScripts<NamedAccounts, Data, ArgumentsType>(
|
|
456
|
+
return executeDeployScripts<NamedAccounts, Data, ArgumentsType>(userConfig, resolvedExecutionParams, args);
|
|
563
457
|
}
|
|
564
458
|
|
|
565
459
|
export async function executeDeployScripts<
|
|
@@ -567,13 +461,14 @@ export async function executeDeployScripts<
|
|
|
567
461
|
Data extends UnresolvedNetworkSpecificData = UnresolvedNetworkSpecificData,
|
|
568
462
|
ArgumentsType = undefined
|
|
569
463
|
>(
|
|
570
|
-
|
|
464
|
+
userConfig: ResolvedUserConfig<NamedAccounts, Data>,
|
|
465
|
+
resolvedExecutionParams: ResolvedExecutionParams,
|
|
571
466
|
args?: ArgumentsType
|
|
572
467
|
): Promise<Environment<NamedAccounts, Data, UnknownDeployments>> {
|
|
573
|
-
setLogLevel(typeof
|
|
468
|
+
setLogLevel(typeof resolvedExecutionParams.logLevel === 'undefined' ? 0 : resolvedExecutionParams.logLevel);
|
|
574
469
|
|
|
575
470
|
let filepaths;
|
|
576
|
-
filepaths = traverseMultipleDirectory(
|
|
471
|
+
filepaths = traverseMultipleDirectory(resolvedExecutionParams.scripts);
|
|
577
472
|
filepaths = filepaths
|
|
578
473
|
.filter((v) => !path.basename(v).startsWith('_'))
|
|
579
474
|
.sort((a: string, b: string) => {
|
|
@@ -628,10 +523,10 @@ export async function executeDeployScripts<
|
|
|
628
523
|
}
|
|
629
524
|
}
|
|
630
525
|
|
|
631
|
-
if (
|
|
526
|
+
if (resolvedExecutionParams.tags !== undefined && resolvedExecutionParams.tags.length > 0) {
|
|
632
527
|
let found = false;
|
|
633
528
|
if (scriptTags !== undefined) {
|
|
634
|
-
for (const tagToFind of
|
|
529
|
+
for (const tagToFind of resolvedExecutionParams.tags) {
|
|
635
530
|
for (const tag of scriptTags) {
|
|
636
531
|
if (tag === tagToFind) {
|
|
637
532
|
scriptFilePaths.push(scriptFilePath);
|
|
@@ -649,7 +544,10 @@ export async function executeDeployScripts<
|
|
|
649
544
|
}
|
|
650
545
|
}
|
|
651
546
|
|
|
652
|
-
const {internal, external} = await createEnvironment(
|
|
547
|
+
const {internal, external} = await createEnvironment<NamedAccounts, Data, UnknownDeployments>(
|
|
548
|
+
userConfig,
|
|
549
|
+
resolvedExecutionParams
|
|
550
|
+
);
|
|
653
551
|
|
|
654
552
|
await internal.recoverTransactionsIfAny();
|
|
655
553
|
|
|
@@ -696,10 +594,10 @@ export async function executeDeployScripts<
|
|
|
696
594
|
recurseDependencies(scriptFilePath);
|
|
697
595
|
}
|
|
698
596
|
|
|
699
|
-
if (
|
|
597
|
+
if (resolvedExecutionParams.askBeforeProceeding) {
|
|
700
598
|
console.log(
|
|
701
|
-
`Network: ${external.
|
|
702
|
-
external.
|
|
599
|
+
`Network: ${external.name} \n \t Chain: ${external.network.chain.name} \n \t Tags: ${Object.keys(
|
|
600
|
+
external.tags
|
|
703
601
|
).join(',')}`
|
|
704
602
|
);
|
|
705
603
|
const gasPriceEstimate = await getRoughGasPriceEstimate(external.network.provider);
|
|
@@ -765,7 +663,7 @@ Do you want to proceed (note that gas price can change for each tx)`,
|
|
|
765
663
|
}
|
|
766
664
|
}
|
|
767
665
|
|
|
768
|
-
if (
|
|
666
|
+
if (resolvedExecutionParams.reportGasUse) {
|
|
769
667
|
const provider = external.network.provider;
|
|
770
668
|
const transactionHashes = provider.transactionHashes;
|
|
771
669
|
|
|
@@ -134,7 +134,7 @@ export const exampleUsage = () => {
|
|
|
134
134
|
await env.verifyOnEtherscan(tokenAddress, ['MyToken', 'MTK']);
|
|
135
135
|
|
|
136
136
|
// Original environment is still fully accessible
|
|
137
|
-
console.log(`Deployed on
|
|
137
|
+
console.log(`Deployed on target: ${env.name}`);
|
|
138
138
|
const deployment = env.get('MyToken');
|
|
139
139
|
|
|
140
140
|
return true;
|
package/src/utils/fs.ts
CHANGED
|
@@ -24,7 +24,7 @@ export function lookupFile(dir: string, formats: string[], options?: LookupFileO
|
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
export function traverseMultipleDirectory(dirs: string[]): string[] {
|
|
27
|
+
export function traverseMultipleDirectory(dirs: readonly string[]): string[] {
|
|
28
28
|
const filepaths = [];
|
|
29
29
|
for (const dir of dirs) {
|
|
30
30
|
let filesStats = traverse(dir);
|