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.
@@ -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
- ResolvedConfig,
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 {getChain, getChainByName} from '../environment/utils/chains.js';
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<ArgumentsType = undefined>(
97
- options: ConfigOptions<Extra>,
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>(options, args);
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
- options: ConfigOptions<Extra>
106
+ executionParams: ExecutionParams<Extra>
106
107
  ): Promise<EnhancedEnvironment<NamedAccounts, Data, UnknownDeployments, Extensions>> {
107
- const env = await loadEnvironment<NamedAccounts, Data, Extra>(options);
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 ConfigOptions<Extra extends Record<string, unknown> = Record<string, unknown>> = {
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 async function transformUserConfig<
227
+ export type ResolvedUserConfig<
227
228
  NamedAccounts extends UnresolvedUnknownNamedAccounts = UnresolvedUnknownNamedAccounts,
228
- Data extends UnresolvedNetworkSpecificData = UnresolvedNetworkSpecificData,
229
- Extra extends Record<string, unknown> = Record<string, unknown>
230
- >(
231
- configFile: UserConfig<NamedAccounts, Data> | undefined,
232
- options: ConfigOptions<Extra>
233
- ): Promise<Config<NamedAccounts, Data>> {
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
- Extra extends Record<string, unknown> = Record<string, unknown>
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
- return transformUserConfig(configFile, options);
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 readAndResolveConfig<
434
- NamedAccounts extends UnresolvedUnknownNamedAccounts = UnresolvedUnknownNamedAccounts,
435
- Data extends UnresolvedNetworkSpecificData = UnresolvedNetworkSpecificData,
436
- Extra extends Record<string, unknown> = Record<string, unknown>
437
- >(options: ConfigOptions<Extra>): Promise<ResolvedConfig<NamedAccounts, Data>> {
438
- return resolveConfig<NamedAccounts, Data>(await readConfig<NamedAccounts, Data>(options));
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
- export function resolveConfig<
442
- NamedAccounts extends UnresolvedUnknownNamedAccounts = UnresolvedUnknownNamedAccounts,
443
- Data extends UnresolvedNetworkSpecificData = UnresolvedNetworkSpecificData
444
- >(config: Config<NamedAccounts, Data>): ResolvedConfig<NamedAccounts, Data> {
445
- const create2Info = {
446
- factory: '0x4e59b44847b379578588920ca78fbf26c0b4956c',
447
- deployer: '0x3fab184622dc19b6109349b94811493bf2a45362',
448
- funding: '10000000000000000',
449
- signedTx:
450
- '0xf8a58085174876e800830186a08080b853604580600e600039806000f350fe7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe03601600081602082378035828234f58015156039578182fd5b8082525050506014600cf31ba02222222222222222222222222222222222222222222222222222222222222222a02222222222222222222222222222222222222222222222222222222222222222',
451
- } as const;
452
- const create3Info = {
453
- factory: '0x000000000004d4f168daE7DB3C610F408eE22F57',
454
- salt: '0x5361109ca02853ca8e22046b7125306d9ec4ae4cdecc393c567b6be861df3db6',
455
- bytecode:
456
- '0x6080604052348015600f57600080fd5b506103ca8061001f6000396000f3fe6080604052600436106100295760003560e01c8063360d0fad1461002e5780639881d19514610077575b600080fd5b34801561003a57600080fd5b5061004e610049366004610228565b61008a565b60405173ffffffffffffffffffffffffffffffffffffffff909116815260200160405180910390f35b61004e61008536600461029c565b6100ee565b6040517fffffffffffffffffffffffffffffffffffffffff000000000000000000000000606084901b166020820152603481018290526000906054016040516020818303038152906040528051906020012091506100e78261014c565b9392505050565b6040517fffffffffffffffffffffffffffffffffffffffff0000000000000000000000003360601b166020820152603481018290526000906054016040516020818303038152906040528051906020012091506100e734848461015e565b600061015882306101ce565b92915050565b60006f67363d3d37363d34f03d5260086018f3600052816010806000f58061018e5763301164256000526004601cfd5b8060145261d69460005260016034536017601e20915060008085516020870188855af1823b026101c65763301164256000526004601cfd5b509392505050565b60006040518260005260ff600b53836020527f21c35dbe1b344a2488cf3321d6ce542f8e9f305544ff09e4993a62319a497c1f6040526055600b20601452806040525061d694600052600160345350506017601e20919050565b6000806040838503121561023b57600080fd5b823573ffffffffffffffffffffffffffffffffffffffff8116811461025f57600080fd5b946020939093013593505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b600080604083850312156102af57600080fd5b823567ffffffffffffffff8111156102c657600080fd5b8301601f810185136102d757600080fd5b803567ffffffffffffffff8111156102f1576102f161026d565b6040517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0603f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f8501160116810181811067ffffffffffffffff8211171561035d5761035d61026d565b60405281815282820160200187101561037557600080fd5b816020840160208301376000602092820183015296940135945050505056fea264697066735822122059dcc5dc6453397d13ff28021e28472a80a45bbd97f3135f69bd2650773aeb0164736f6c634300081a0033',
457
- proxyBytecode: '0x67363d3d37363d34f03d5260086018f3',
458
- } as const;
459
-
460
- const defaultPollingInterval = config.defaultPollingInterval || 1;
461
- const networkPollingInterval = config.target.pollingInterval || defaultPollingInterval;
462
-
463
- let deterministicDeployment: {
464
- create2: Create2DeterministicDeploymentInfo;
465
- create3: Create3DeterministicDeploymentInfo;
466
- } = {
467
- create2: (() => {
468
- if (!config.target.deterministicDeployment) return create2Info;
469
- if (
470
- !('create3' in config.target.deterministicDeployment) &&
471
- !('create2' in config.target.deterministicDeployment)
472
- )
473
- return create2Info;
474
- return config.target.deterministicDeployment.create2 || create2Info;
475
- })(),
476
- create3:
477
- config.target.deterministicDeployment &&
478
- 'create3' in config.target.deterministicDeployment &&
479
- config.target.deterministicDeployment.create3
480
- ? config.target.deterministicDeployment.create3
481
- : create3Info,
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 (config.target.scripts) {
494
- if (typeof config.target.scripts === 'string') {
495
- scripts = [config.target.scripts];
372
+ if (targetConfig?.scripts) {
373
+ if (typeof targetConfig.scripts === 'string') {
374
+ scripts = [targetConfig.scripts];
496
375
  } else {
497
- scripts = config.target.scripts;
376
+ scripts = targetConfig.scripts;
498
377
  }
499
378
  }
500
379
 
501
- let resolvedTarget: ResolvedTargetConfig;
502
-
503
- if ('provider' in config.target) {
504
- resolvedTarget = {
505
- provider: config.target.provider,
506
- name: config.target.name,
507
- tags: config.target.tags,
508
- fork: config.target.fork,
509
- deterministicDeployment,
510
- chainInfo: config.target.chainInfo,
511
- pollingInterval: networkPollingInterval,
512
- };
513
- } else {
514
- resolvedTarget = {
515
- nodeUrl: config.target.nodeUrl,
516
- name: config.target.name,
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
- const resolvedConfig: ResolvedConfig<NamedAccounts, Data> = {
526
- ...config,
527
- target: resolvedTarget,
528
- deployments: config.deployments || 'deployments',
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
- >(options: ConfigOptions<Extra>): Promise<Environment<NamedAccounts, Data, UnknownDeployments>> {
547
- const resolvedConfig = await readAndResolveConfig<NamedAccounts, Data>(options);
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(resolvedConfig);
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
- >(options: ConfigOptions<Extra>, args?: ArgumentsType): Promise<Environment<NamedAccounts, Data, UnknownDeployments>> {
559
- const resolvedConfig = await readAndResolveConfig<NamedAccounts, Data>(options);
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>(resolvedConfig, args);
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
- config: ResolvedConfig<NamedAccounts, Data>,
464
+ userConfig: ResolvedUserConfig<NamedAccounts, Data>,
465
+ resolvedExecutionParams: ResolvedExecutionParams,
571
466
  args?: ArgumentsType
572
467
  ): Promise<Environment<NamedAccounts, Data, UnknownDeployments>> {
573
- setLogLevel(typeof config.logLevel === 'undefined' ? 0 : config.logLevel);
468
+ setLogLevel(typeof resolvedExecutionParams.logLevel === 'undefined' ? 0 : resolvedExecutionParams.logLevel);
574
469
 
575
470
  let filepaths;
576
- filepaths = traverseMultipleDirectory(config.scripts);
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 (config.tags !== undefined && config.tags.length > 0) {
526
+ if (resolvedExecutionParams.tags !== undefined && resolvedExecutionParams.tags.length > 0) {
632
527
  let found = false;
633
528
  if (scriptTags !== undefined) {
634
- for (const tagToFind of config.tags) {
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(config);
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 (config.askBeforeProceeding) {
597
+ if (resolvedExecutionParams.askBeforeProceeding) {
700
598
  console.log(
701
- `Network: ${external.network.name} \n \t Chain: ${external.network.chain.name} \n \t Tags: ${Object.keys(
702
- external.network.tags
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 (config.reportGasUse) {
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 network: ${env.network.name}`);
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);