rocketh 0.15.14 → 0.16.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.
Files changed (37) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/dist/cli.js +1 -1
  3. package/dist/cli.js.map +1 -1
  4. package/dist/environment/deployment-store.d.ts +3 -0
  5. package/dist/environment/deployment-store.d.ts.map +1 -0
  6. package/dist/environment/deployment-store.js +49 -0
  7. package/dist/environment/deployment-store.js.map +1 -0
  8. package/dist/environment/utils/artifacts.d.ts +4 -4
  9. package/dist/executor/index.d.ts +15 -6
  10. package/dist/executor/index.d.ts.map +1 -1
  11. package/dist/executor/index.js +42 -320
  12. package/dist/executor/index.js.map +1 -1
  13. package/dist/index.d.ts +9 -7
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +8 -7
  16. package/dist/index.js.map +1 -1
  17. package/dist/internal/logging.d.ts +1 -1
  18. package/dist/internal/logging.d.ts.map +1 -1
  19. package/package.json +9 -12
  20. package/src/cli.ts +2 -1
  21. package/src/environment/deployment-store.ts +72 -0
  22. package/src/executor/index.ts +92 -404
  23. package/src/index.ts +10 -11
  24. package/src/environment/deployments.ts +0 -135
  25. package/src/environment/index.ts +0 -696
  26. package/src/environment/providers/BaseProvider.ts +0 -13
  27. package/src/environment/providers/TransactionHashTracker.ts +0 -22
  28. package/src/environment/utils/artifacts.ts +0 -176
  29. package/src/environment/utils/chains.ts +0 -192
  30. package/src/executor/setup.test.ts +0 -151
  31. package/src/internal/logging.ts +0 -80
  32. package/src/internal/types.ts +0 -5
  33. package/src/types.ts +0 -601
  34. package/src/utils/eth.ts +0 -96
  35. package/src/utils/extensions.test.ts +0 -53
  36. package/src/utils/extensions.ts +0 -72
  37. package/src/utils/json.ts +0 -33
@@ -1,41 +1,34 @@
1
- import {EIP1193GenericRequestProvider, EIP1193ProviderWithoutEvents} from 'eip-1193';
2
1
  import fs from 'node:fs';
3
2
  import path from 'node:path';
4
3
  import prompts from 'prompts';
5
- // import {tsImport as tsImport_} from 'tsx/esm/api';
6
- import { register } from 'tsx/esm/api'
7
- import {formatEther} from 'viem';
8
- import type {
9
- Environment,
10
- ExecutionParams,
11
- ResolvedExecutionParams,
12
- UnknownDeployments,
13
- UnresolvedNetworkSpecificData,
14
- UnresolvedUnknownNamedAccounts,
15
- DeployScriptModule,
16
- EnhancedDeployScriptFunction,
17
- EnhancedEnvironment,
18
- ResolvedUserConfig,
19
- ConfigOverrides,
20
- UserConfig,
21
- ChainConfig,
22
- } from '../types.js';
23
- import {withEnvironment} from '../utils/extensions.js';
24
- import {logger, setLogLevel, spin} from '../internal/logging.js';
25
- import {getRoughGasPriceEstimate} from '../utils/eth.js';
4
+ import {
5
+ type Environment,
6
+ type ExecutionParams,
7
+ type ResolvedExecutionParams,
8
+ type UnknownDeployments,
9
+ type UnresolvedNetworkSpecificData,
10
+ type UnresolvedUnknownNamedAccounts,
11
+ type DeployScriptModule,
12
+ type EnhancedEnvironment,
13
+ type ResolvedUserConfig,
14
+ type ConfigOverrides,
15
+ type UserConfig,
16
+ type PromptExecutor,
17
+ } from '@rocketh/core/types';
18
+ import {
19
+ withEnvironment,
20
+ resolveConfig,
21
+ resolveExecutionParams,
22
+ createEnvironment,
23
+ logger,
24
+ getEnvironmentName,
25
+ getChainIdForEnvironment,
26
+ createExecutor,
27
+ setupDeployScripts,
28
+ loadDeployments,
29
+ } from '@rocketh/core';
26
30
  import {traverseMultipleDirectory} from '../utils/fs.js';
27
- import {getChainByName, getChainConfig} from '../environment/utils/chains.js';
28
- import {JSONRPCHTTPProvider} from 'eip-1193-jsonrpc-provider';
29
- import {createEnvironment} from '../environment/index.js';
30
-
31
-
32
-
33
- // @ts-ignore
34
- // const tsImport = (path: string, opts: any) => (typeof Bun !== 'undefined' ? import(path) : tsImport_(path, opts));
35
-
36
- const unregister = register();
37
- const tsImport = (path: string, opts: any) => import(path, opts);
38
-
31
+ import {createFSDeploymentStore} from '../environment/deployment-store.js';
39
32
 
40
33
  /**
41
34
  * Setup function that creates the execute function for deploy scripts. It allow to specify a set of functions that will be available in the environment.
@@ -63,6 +56,7 @@ const tsImport = (path: string, opts: any) => import(path, opts);
63
56
  * }, { tags: ['deploy'] });
64
57
  * ```
65
58
  */
59
+
66
60
  export function setup<
67
61
  Extensions extends Record<string, (env: Environment<any, any, any>) => any> = {},
68
62
  NamedAccounts extends UnresolvedUnknownNamedAccounts = UnresolvedUnknownNamedAccounts,
@@ -70,33 +64,20 @@ export function setup<
70
64
  Deployments extends UnknownDeployments = UnknownDeployments,
71
65
  Extra extends Record<string, unknown> = Record<string, unknown>
72
66
  >(extensions: Extensions) {
73
- function enhancedExecute<ArgumentsType = undefined>(
74
- callback: EnhancedDeployScriptFunction<NamedAccounts, Data, ArgumentsType, Deployments, Extensions>,
75
- options: {tags?: string[]; dependencies?: string[]; id?: string; runAtTheEnd?: boolean}
76
- ): DeployScriptModule<NamedAccounts, Data, ArgumentsType, Deployments, Extra> {
77
- const scriptModule: DeployScriptModule<NamedAccounts, Data, ArgumentsType, Deployments, Extra> = (
78
- env: Environment<NamedAccounts, Data, Deployments, Extra>,
79
- args?: ArgumentsType
80
- ) => {
81
- // Create the enhanced environment by combining the original environment with extensions
82
- const curriedFunctions = withEnvironment(env, extensions);
83
- const enhancedEnv = Object.assign(
84
- Object.create(Object.getPrototypeOf(env)),
85
- env,
86
- curriedFunctions
87
- ) as EnhancedEnvironment<NamedAccounts, Data, Deployments, Extensions, Extra>;
88
-
89
- return callback(enhancedEnv, args);
90
- };
91
-
92
- scriptModule.tags = options.tags;
93
- scriptModule.dependencies = options.dependencies;
94
- scriptModule.id = options.id;
95
- scriptModule.runAtTheEnd = options.runAtTheEnd;
96
-
97
- return scriptModule;
98
- }
67
+ const {deployScript} = setupDeployScripts<Extensions, NamedAccounts, Data, Deployments, Extra>(extensions);
68
+ const {loadAndExecuteDeployments} = setupEnvironmentFromFiles<Extensions, NamedAccounts, Data, Deployments, Extra>(
69
+ extensions
70
+ );
71
+ return {deployScript, loadAndExecuteDeployments};
72
+ }
99
73
 
74
+ export function setupEnvironmentFromFiles<
75
+ Extensions extends Record<string, (env: Environment<any, any, any>) => any> = {},
76
+ NamedAccounts extends UnresolvedUnknownNamedAccounts = UnresolvedUnknownNamedAccounts,
77
+ Data extends UnresolvedNetworkSpecificData = UnresolvedNetworkSpecificData,
78
+ Deployments extends UnknownDeployments = UnknownDeployments,
79
+ Extra extends Record<string, unknown> = Record<string, unknown>
80
+ >(extensions: Extensions) {
100
81
  async function loadAndExecuteDeploymentsWithExtensions<
101
82
  Extra extends Record<string, unknown> = Record<string, unknown>,
102
83
  ArgumentsType = undefined
@@ -116,7 +97,6 @@ export function setup<
116
97
  }
117
98
 
118
99
  return {
119
- deployScript: enhancedExecute,
120
100
  loadAndExecuteDeployments: loadAndExecuteDeploymentsWithExtensions,
121
101
  loadEnvironment: loadEnvironmentWithExtensions,
122
102
  };
@@ -158,12 +138,26 @@ export async function readConfig<
158
138
  let jsVersion: string | undefined;
159
139
 
160
140
  if (typeof process !== 'undefined') {
161
- // TODO more sophisticated config file finding mechanism (look up parents, etc..)
162
- const tsFilePath = path.join(process.cwd(), 'rocketh.ts');
163
- const jsFilePath = path.join(process.cwd(), 'rocketh.js');
164
-
165
- tsVersion = fs.existsSync(tsFilePath) ? `file://${tsFilePath}` : undefined;
166
- jsVersion = fs.existsSync(jsFilePath) ? `file://${jsFilePath}` : undefined;
141
+ const listOfFileToTryForTS = [
142
+ path.join(process.cwd(), 'rocketh.ts'),
143
+ path.join(process.cwd(), 'rocketh', 'config.ts'),
144
+ ];
145
+ for (const filepath of listOfFileToTryForTS) {
146
+ if (fs.existsSync(filepath)) {
147
+ tsVersion = `file://${filepath}`;
148
+ break;
149
+ }
150
+ }
151
+ const listOfFileToTryForJS = [
152
+ path.join(process.cwd(), 'rocketh.js'),
153
+ path.join(process.cwd(), 'rocketh', 'config.s'),
154
+ ];
155
+ for (const filepath of listOfFileToTryForJS) {
156
+ if (fs.existsSync(filepath)) {
157
+ jsVersion = `file://${filepath}`;
158
+ break;
159
+ }
160
+ }
167
161
  }
168
162
  const existingConfigs = [tsVersion, jsVersion].filter(Boolean).length;
169
163
 
@@ -174,7 +168,7 @@ export async function readConfig<
174
168
  throw new Error('Multiple configuration files found. Please use only one of: rocketh.ts, rocketh.js');
175
169
  }
176
170
  if (tsVersion) {
177
- const moduleLoaded = await tsImport(tsVersion, import.meta.url);
171
+ const moduleLoaded = await import(tsVersion);
178
172
  configFile = moduleLoaded.config;
179
173
  // console.log({tsVersionExists: configFile});
180
174
  // if ((configFile as any).default) {
@@ -185,41 +179,13 @@ export async function readConfig<
185
179
  // }
186
180
  // }
187
181
  } else if (jsVersion) {
188
- const moduleLoaded = await tsImport(jsVersion, import.meta.url);
182
+ const moduleLoaded = await import(jsVersion);
189
183
  configFile = moduleLoaded.config;
190
184
  }
191
185
 
192
186
  return configFile || {};
193
187
  }
194
188
 
195
- export function resolveConfig<
196
- NamedAccounts extends UnresolvedUnknownNamedAccounts = UnresolvedUnknownNamedAccounts,
197
- Data extends UnresolvedNetworkSpecificData = UnresolvedNetworkSpecificData
198
- >(configFile: UserConfig, overrides?: ConfigOverrides): ResolvedUserConfig<NamedAccounts, Data> {
199
- const config = {
200
- deployments: 'deployments',
201
- defaultPollingInterval: 1,
202
- ...configFile,
203
- scripts: configFile?.scripts
204
- ? typeof configFile.scripts === 'string'
205
- ? [configFile.scripts]
206
- : configFile.scripts.length == 0
207
- ? ['deploy']
208
- : configFile.scripts
209
- : ['deploy'],
210
- };
211
-
212
- if (overrides) {
213
- for (const key of Object.keys(overrides)) {
214
- if ((overrides as any)[key] !== undefined) {
215
- (config as any)[key] = (overrides as any)[key];
216
- }
217
- }
218
- }
219
-
220
- return config;
221
- }
222
-
223
189
  export async function readAndResolveConfig<
224
190
  NamedAccounts extends UnresolvedUnknownNamedAccounts = UnresolvedUnknownNamedAccounts,
225
191
  Data extends UnresolvedNetworkSpecificData = UnresolvedNetworkSpecificData
@@ -228,137 +194,27 @@ export async function readAndResolveConfig<
228
194
  return resolveConfig(configFile, overrides);
229
195
  }
230
196
 
231
- export async function getChainIdForEnvironment(
232
- config: ResolvedUserConfig,
233
- environmentName: string,
234
- provider?: EIP1193ProviderWithoutEvents
235
- ) {
236
- if (config?.environments?.[environmentName]?.chain) {
237
- const chainAsNumber =
238
- typeof config.environments[environmentName].chain === 'number'
239
- ? config.environments[environmentName].chain
240
- : parseInt(config.environments[environmentName].chain);
241
- if (!isNaN(chainAsNumber)) {
242
- return chainAsNumber;
243
- }
244
- const chainFound = getChainByName(config.environments[environmentName].chain as string);
245
- if (chainFound) {
246
- return chainFound.id;
247
- } else {
248
- throw new Error(`environment ${environmentName} chain id cannot be found, specify it in the rocketh config`);
249
- }
250
- } else {
251
- const chainFound = getChainByName(environmentName);
252
- if (chainFound) {
253
- return chainFound.id;
254
- } else {
255
- if (provider) {
256
- const chainIdAsHex = await provider.request({method: 'eth_chainId'});
257
- return Number(chainIdAsHex);
258
- } else {
259
- throw new Error(`environment ${environmentName} chain id cannot be found, specify it in the rocketh config`);
260
- }
261
- }
262
- }
263
- }
264
-
265
- function getEnvironmentName(executionParams: ExecutionParams): {name: string; fork: boolean} {
266
- const environmentProvided = executionParams.environment || (executionParams as any).network;
267
- let environmentName = 'memory';
268
- if (environmentProvided) {
269
- if (typeof environmentProvided === 'string') {
270
- environmentName = environmentProvided;
271
- } else if ('fork' in environmentProvided) {
272
- environmentName = environmentProvided.fork;
273
- }
274
- }
275
- const fork = typeof environmentProvided !== 'string';
276
- return {name: environmentName, fork};
277
- }
278
-
279
- export function resolveExecutionParams<Extra extends Record<string, unknown> = Record<string, unknown>>(
280
- config: ResolvedUserConfig,
281
- executionParameters: ExecutionParams<Extra>,
282
- chainId: number
283
- ): ResolvedExecutionParams<Extra> {
284
- const {name: environmentName, fork} = getEnvironmentName(executionParameters);
285
-
286
- // TODO fork chainId resolution option to keep the network being used
287
- let chainConfig: ChainConfig = getChainConfig(fork ? 31337 : chainId, config);
288
-
289
- let chainInfo = chainConfig.info;
290
- const environmentConfig = config?.environments?.[environmentName];
291
- const actualChainConfig = environmentConfig?.overrides
292
- ? {
293
- ...chainConfig,
294
- ...environmentConfig.overrides,
295
- properties: {
296
- ...chainConfig?.properties,
297
- ...environmentConfig.overrides.properties,
298
- },
299
- }
300
- : chainConfig;
301
-
302
- if (actualChainConfig?.properties) {
303
- chainInfo = {...chainInfo, properties: actualChainConfig.properties};
304
- }
305
-
306
- // let environmentTags: string[] = actualChainConfig.tags.concat(environmentConfig?.tags); // TODO
307
- const environmentTags = actualChainConfig.tags;
308
-
309
- let scripts = ['deploy'];
310
- if (config.scripts) {
311
- if (typeof config.scripts === 'string') {
312
- scripts = [config.scripts];
313
- } else {
314
- scripts = [...config.scripts];
315
- }
316
- }
317
-
318
- if (environmentConfig?.scripts) {
319
- if (typeof environmentConfig.scripts === 'string') {
320
- scripts = [environmentConfig.scripts];
321
- } else {
322
- scripts = [...environmentConfig.scripts];
323
- }
324
- }
325
-
326
- const provider =
327
- executionParameters.provider || (new JSONRPCHTTPProvider(actualChainConfig.rpcUrl) as EIP1193ProviderWithoutEvents);
328
-
329
- let saveDeployments = executionParameters.saveDeployments;
330
-
331
- if (saveDeployments === undefined) {
332
- if (!executionParameters.provider) {
333
- saveDeployments = true;
334
- } else {
335
- if (environmentName === 'memory' || environmentName === 'hardhat' || environmentName === 'default') {
336
- // networkTags['memory'] = true;
337
- saveDeployments = false;
338
- } else {
339
- saveDeployments = true;
340
- }
341
- }
342
- }
343
-
197
+ const deploymentStore = createFSDeploymentStore();
198
+ const promptExecutor: PromptExecutor = async (request: {type: 'confirm'; name: string; message: string}) => {
199
+ const answer = await prompts<string>(request);
344
200
  return {
345
- askBeforeProceeding: executionParameters.askBeforeProceeding || false,
346
- chain: chainInfo,
347
- logLevel: executionParameters.logLevel || 0, // TODO
348
- pollingInterval: actualChainConfig.pollingInterval,
349
- reportGasUse: executionParameters.reportGasUse || false,
350
- saveDeployments,
351
- tags: executionParameters.tags || [],
352
- environment: {
353
- name: environmentName,
354
- tags: environmentTags,
355
- fork,
356
- deterministicDeployment: actualChainConfig.deterministicDeployment,
357
- },
358
- extra: executionParameters.extra,
359
- provider,
360
- scripts,
201
+ proceed: answer.proceed,
361
202
  };
203
+ };
204
+ const executor = createExecutor(deploymentStore, promptExecutor);
205
+
206
+ export function loadDeploymentsFromFiles(
207
+ deploymentsPath: string,
208
+ networkName: string,
209
+ onlyABIAndAddress?: boolean,
210
+ expectedChain?: {chainId: string; genesisHash?: `0x${string}`; deleteDeploymentsIfDifferentGenesisHash?: boolean}
211
+ ): Promise<{
212
+ deployments: UnknownDeployments;
213
+ migrations: Record<string, number>;
214
+ chainId?: string;
215
+ genesisHash?: `0x${string}`;
216
+ }> {
217
+ return loadDeployments(deploymentStore, deploymentsPath, networkName, onlyABIAndAddress, expectedChain);
362
218
  }
363
219
 
364
220
  export async function loadEnvironment<
@@ -373,7 +229,8 @@ export async function loadEnvironment<
373
229
  // console.log(JSON.stringify(resolvedConfig, null, 2));
374
230
  const {external, internal} = await createEnvironment<NamedAccounts, Data, UnknownDeployments>(
375
231
  userConfig,
376
- resolvedExecutionParams
232
+ resolvedExecutionParams,
233
+ deploymentStore
377
234
  );
378
235
  return external;
379
236
  }
@@ -393,6 +250,7 @@ export async function loadAndExecuteDeployments<
393
250
  const resolvedExecutionParams = resolveExecutionParams(userConfig, executionParams, chainId);
394
251
  // console.log(JSON.stringify(options, null, 2));
395
252
  // console.log(JSON.stringify(resolvedConfig, null, 2));
253
+
396
254
  return _executeDeployScripts<NamedAccounts, Data, ArgumentsType>(userConfig, resolvedExecutionParams, args);
397
255
  }
398
256
 
@@ -423,8 +281,6 @@ async function _executeDeployScripts<
423
281
  resolvedExecutionParams: ResolvedExecutionParams,
424
282
  args?: ArgumentsType
425
283
  ): Promise<Environment<NamedAccounts, Data, UnknownDeployments>> {
426
- setLogLevel(typeof resolvedExecutionParams.logLevel === 'undefined' ? 0 : resolvedExecutionParams.logLevel);
427
-
428
284
  let filepaths;
429
285
  filepaths = traverseMultipleDirectory(resolvedExecutionParams.scripts);
430
286
  filepaths = filepaths
@@ -439,15 +295,12 @@ async function _executeDeployScripts<
439
295
  return 0;
440
296
  });
441
297
 
442
- const scriptModuleByFilePath: {[filename: string]: DeployScriptModule<NamedAccounts, Data, ArgumentsType>} = {};
443
- const scriptPathBags: {[tag: string]: string[]} = {};
444
- const scriptFilePaths: string[] = [];
445
-
298
+ const moduleObjects: {id: string; module: DeployScriptModule<NamedAccounts, Data, ArgumentsType>}[] = [];
446
299
  for (const filepath of filepaths) {
447
300
  const scriptFilePath = path.resolve(filepath);
448
301
  let scriptModule: DeployScriptModule<NamedAccounts, Data, ArgumentsType>;
449
302
  try {
450
- scriptModule = await tsImport(`file://${scriptFilePath}`, import.meta.url);
303
+ scriptModule = await import(`file://${scriptFilePath}`);
451
304
 
452
305
  // console.log({
453
306
  // scriptFilePath,
@@ -460,182 +313,17 @@ async function _executeDeployScripts<
460
313
  scriptModule = (scriptModule as any).default as DeployScriptModule<NamedAccounts, Data, ArgumentsType>;
461
314
  }
462
315
  }
463
- scriptModuleByFilePath[scriptFilePath] = scriptModule;
316
+ moduleObjects.push({id: scriptFilePath, module: scriptModule});
464
317
  } catch (e) {
465
318
  logger.error(`could not import ${filepath}`);
466
319
  throw e;
467
320
  }
468
-
469
- let scriptTags = scriptModule.tags;
470
- if (scriptTags !== undefined) {
471
- if (typeof scriptTags === 'string') {
472
- scriptTags = [scriptTags];
473
- }
474
- for (const tag of scriptTags) {
475
- if (tag.indexOf(',') >= 0) {
476
- throw new Error('Tag cannot contains commas');
477
- }
478
- const bag = scriptPathBags[tag] || [];
479
- scriptPathBags[tag] = bag;
480
- bag.push(scriptFilePath);
481
- }
482
- }
483
-
484
- if (resolvedExecutionParams.tags !== undefined && resolvedExecutionParams.tags.length > 0) {
485
- let found = false;
486
- if (scriptTags !== undefined) {
487
- for (const tagToFind of resolvedExecutionParams.tags) {
488
- for (const tag of scriptTags) {
489
- if (tag === tagToFind) {
490
- scriptFilePaths.push(scriptFilePath);
491
- found = true;
492
- break;
493
- }
494
- }
495
- if (found) {
496
- break;
497
- }
498
- }
499
- }
500
- } else {
501
- scriptFilePaths.push(scriptFilePath);
502
- }
503
321
  }
504
322
 
505
- const {internal, external} = await createEnvironment<NamedAccounts, Data, UnknownDeployments>(
323
+ return executor.executeDeployScriptModules<NamedAccounts, Data, ArgumentsType>(
324
+ moduleObjects,
506
325
  userConfig,
507
- resolvedExecutionParams
326
+ resolvedExecutionParams,
327
+ args
508
328
  );
509
-
510
- await internal.recoverTransactionsIfAny();
511
-
512
- const scriptsRegisteredToRun: {[filename: string]: boolean} = {};
513
- const scriptsToRun: Array<{
514
- func: DeployScriptModule<NamedAccounts, Data, ArgumentsType>;
515
- filePath: string;
516
- }> = [];
517
- const scriptsToRunAtTheEnd: Array<{
518
- func: DeployScriptModule<NamedAccounts, Data, ArgumentsType>;
519
- filePath: string;
520
- }> = [];
521
- function recurseDependencies(scriptFilePath: string) {
522
- if (scriptsRegisteredToRun[scriptFilePath]) {
523
- return;
524
- }
525
- const scriptModule = scriptModuleByFilePath[scriptFilePath];
526
- if (scriptModule.dependencies) {
527
- for (const dependency of scriptModule.dependencies) {
528
- const scriptFilePathsToAdd = scriptPathBags[dependency];
529
- if (scriptFilePathsToAdd) {
530
- for (const scriptFilenameToAdd of scriptFilePathsToAdd) {
531
- recurseDependencies(scriptFilenameToAdd);
532
- }
533
- }
534
- }
535
- }
536
- if (!scriptsRegisteredToRun[scriptFilePath]) {
537
- if (scriptModule.runAtTheEnd) {
538
- scriptsToRunAtTheEnd.push({
539
- filePath: scriptFilePath,
540
- func: scriptModule,
541
- });
542
- } else {
543
- scriptsToRun.push({
544
- filePath: scriptFilePath,
545
- func: scriptModule,
546
- });
547
- }
548
- scriptsRegisteredToRun[scriptFilePath] = true;
549
- }
550
- }
551
- for (const scriptFilePath of scriptFilePaths) {
552
- recurseDependencies(scriptFilePath);
553
- }
554
-
555
- if (resolvedExecutionParams.askBeforeProceeding) {
556
- console.log(
557
- `Network: ${external.name} \n \t Chain: ${external.network.chain.name} \n \t Tags: ${Object.keys(
558
- external.tags
559
- ).join(',')}`
560
- );
561
- const gasPriceEstimate = await getRoughGasPriceEstimate(external.network.provider);
562
- const prompt = await prompts({
563
- type: 'confirm',
564
- name: 'proceed',
565
- message: `gas price is currently in this range:
566
- slow: ${formatEther(gasPriceEstimate.slow.maxFeePerGas)} (priority: ${formatEther(
567
- gasPriceEstimate.slow.maxPriorityFeePerGas
568
- )})
569
- average: ${formatEther(gasPriceEstimate.average.maxFeePerGas)} (priority: ${formatEther(
570
- gasPriceEstimate.average.maxPriorityFeePerGas
571
- )})
572
- fast: ${formatEther(gasPriceEstimate.fast.maxFeePerGas)} (priority: ${formatEther(
573
- gasPriceEstimate.fast.maxPriorityFeePerGas
574
- )})
575
-
576
- Do you want to proceed (note that gas price can change for each tx)`,
577
- });
578
-
579
- if (!prompt.proceed) {
580
- process.exit();
581
- }
582
- }
583
-
584
- for (const deployScript of scriptsToRun.concat(scriptsToRunAtTheEnd)) {
585
- const filename = path.basename(deployScript.filePath);
586
- const relativeFilepath = path.relative('.', deployScript.filePath);
587
- if (deployScript.func.id && external.hasMigrationBeenDone(deployScript.func.id)) {
588
- logger.info(`skipping ${filename} as migrations already executed and complete`);
589
- continue;
590
- }
591
- let skip = false;
592
- const spinner = spin(`- Executing ${filename}`);
593
- // if (deployScript.func.skip) {
594
- // const spinner = spin(` - skip?()`);
595
- // try {
596
- // skip = await deployScript.func.skip(external, args);
597
- // spinner.succeed(skip ? `skipping ${filename}` : undefined);
598
- // } catch (e) {
599
- // spinner.fail();
600
- // throw e;
601
- // }
602
- // }
603
- if (!skip) {
604
- let result;
605
-
606
- try {
607
- result = await deployScript.func(external, args);
608
- spinner.succeed(`\n`);
609
- } catch (e) {
610
- spinner.fail();
611
- throw e;
612
- }
613
- if (result && typeof result === 'boolean') {
614
- if (!deployScript.func.id) {
615
- throw new Error(
616
- `${deployScript.filePath} return true to not be executed again, but does not provide an id. the script function needs to have the field "id" to be set`
617
- );
618
- }
619
- internal.recordMigration(deployScript.func.id);
620
- }
621
- }
622
- }
623
-
624
- if (resolvedExecutionParams.reportGasUse) {
625
- const provider = external.network.provider;
626
- const transactionHashes = provider.transactionHashes;
627
-
628
- let totalGasUsed = 0;
629
- for (const hash of transactionHashes) {
630
- const transactionReceipt = await provider.request({method: 'eth_getTransactionReceipt', params: [hash]});
631
- if (transactionReceipt) {
632
- const gasUsed = Number(transactionReceipt.gasUsed);
633
- totalGasUsed += gasUsed;
634
- }
635
- }
636
-
637
- console.log({totalGasUsed});
638
- }
639
-
640
- return external;
641
329
  }
package/src/index.ts CHANGED
@@ -1,17 +1,16 @@
1
1
  export {
2
- setup,
3
- loadAndExecuteDeployments,
4
- executeDeployScripts,
5
- readAndResolveConfig,
2
+ executeDeployScripts, // TODO rename ...FromFiles
3
+ setupEnvironmentFromFiles, // TODO rename ...FromFiles
6
4
  enhanceEnvIfNeeded,
7
- loadEnvironment,
5
+ loadEnvironment, // TODO rename loadEnvironmentFromFiles
6
+ readAndResolveConfig, // TODO rename ...FromFiles
7
+ loadAndExecuteDeployments, // TODO rename ...FromFiles
8
+ setup, // TODO remove, we use split setup to make it explicity which require file system access
9
+ loadDeploymentsFromFiles,
8
10
  } from './executor/index.js';
9
11
 
10
- export {getChainConfig, chainByCanonicalName} from './environment/utils/chains.js';
11
- export * from './types.js';
12
- export {loadDeployments} from './environment/deployments.js';
13
- export {mergeArtifacts, mergeABIs} from './environment/utils/artifacts.js';
14
- export {getGasPriceEstimate, getRoughGasPriceEstimate} from './utils/eth.js';
15
- export {bigIntToStringReplacer} from './utils/json.js';
12
+ export {setupDeployScripts, chainByCanonicalName} from '@rocketh/core';
13
+
14
+ export type * from '@rocketh/core/types';
16
15
 
17
16
  export type * from 'eip-1193';