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