rocketh 0.15.15 → 0.17.0-next.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/dist/environment/index.d.ts +12 -2
- package/dist/environment/index.d.ts.map +1 -1
- package/dist/environment/index.js +94 -48
- package/dist/environment/index.js.map +1 -1
- package/dist/executor/index.d.ts +11 -9
- package/dist/executor/index.d.ts.map +1 -1
- package/dist/executor/index.js +144 -238
- package/dist/executor/index.js.map +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -4
- package/dist/index.js.map +1 -1
- package/dist/internal/types.d.ts +0 -1
- package/dist/internal/types.d.ts.map +1 -1
- package/dist/types.d.ts +25 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +18 -20
- package/.prettierignore +0 -3
- package/.prettierrc +0 -7
- package/CHANGELOG.md +0 -950
- package/dist/cli.d.ts +0 -3
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js +0 -30
- package/dist/cli.js.map +0 -1
- package/dist/environment/deployments.d.ts +0 -12
- package/dist/environment/deployments.d.ts.map +0 -1
- package/dist/environment/deployments.js +0 -108
- package/dist/environment/deployments.js.map +0 -1
- package/dist/executor/setup.test.d.ts +0 -14
- package/dist/executor/setup.test.d.ts.map +0 -1
- package/dist/executor/setup.test.js +0 -107
- package/dist/executor/setup.test.js.map +0 -1
- package/dist/utils/fs.d.ts +0 -16
- package/dist/utils/fs.d.ts.map +0 -1
- package/dist/utils/fs.js +0 -52
- package/dist/utils/fs.js.map +0 -1
- package/src/cli.ts +0 -34
- 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/index.ts +0 -638
- package/src/executor/setup.test.ts +0 -151
- package/src/index.ts +0 -17
- 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/fs.ts +0 -70
- package/src/utils/json.ts +0 -33
- package/tsconfig.json +0 -18
package/src/executor/index.ts
DELETED
|
@@ -1,638 +0,0 @@
|
|
|
1
|
-
import {EIP1193GenericRequestProvider, EIP1193ProviderWithoutEvents} from 'eip-1193';
|
|
2
|
-
import fs from 'node:fs';
|
|
3
|
-
import path from 'node:path';
|
|
4
|
-
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';
|
|
26
|
-
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
|
-
const unregister = register();
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* 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.
|
|
39
|
-
*
|
|
40
|
-
* @param functions - An object of utility functions that expect Environment as their first parameter
|
|
41
|
-
* @returns An execute function that provides an enhanced environment with curried functions
|
|
42
|
-
*
|
|
43
|
-
* @example
|
|
44
|
-
* ```typescript
|
|
45
|
-
* const functions = {
|
|
46
|
-
* deploy: (env: Environment) => ((contractName: string, args: any[]) => Promise<void>),
|
|
47
|
-
* verify: (env: Environment) => ((address: string) => Promise<boolean>)
|
|
48
|
-
* };
|
|
49
|
-
*
|
|
50
|
-
* const {deployScript} = setup(functions);
|
|
51
|
-
*
|
|
52
|
-
* export default deployScript(async (env, args) => {
|
|
53
|
-
* // env now includes both the original environment AND the curried functions
|
|
54
|
-
* await env.deploy('MyContract', []); // No need to pass env
|
|
55
|
-
* await env.verify('0x123...'); // No need to pass env
|
|
56
|
-
*
|
|
57
|
-
* // Original environment properties are still available
|
|
58
|
-
* console.log(env.network.name);
|
|
59
|
-
* const deployment = env.get('MyContract');
|
|
60
|
-
* }, { tags: ['deploy'] });
|
|
61
|
-
* ```
|
|
62
|
-
*/
|
|
63
|
-
export function setup<
|
|
64
|
-
Extensions extends Record<string, (env: Environment<any, any, any>) => any> = {},
|
|
65
|
-
NamedAccounts extends UnresolvedUnknownNamedAccounts = UnresolvedUnknownNamedAccounts,
|
|
66
|
-
Data extends UnresolvedNetworkSpecificData = UnresolvedNetworkSpecificData,
|
|
67
|
-
Deployments extends UnknownDeployments = UnknownDeployments,
|
|
68
|
-
Extra extends Record<string, unknown> = Record<string, unknown>
|
|
69
|
-
>(extensions: Extensions) {
|
|
70
|
-
function enhancedExecute<ArgumentsType = undefined>(
|
|
71
|
-
callback: EnhancedDeployScriptFunction<NamedAccounts, Data, ArgumentsType, Deployments, Extensions>,
|
|
72
|
-
options: {tags?: string[]; dependencies?: string[]; id?: string; runAtTheEnd?: boolean}
|
|
73
|
-
): DeployScriptModule<NamedAccounts, Data, ArgumentsType, Deployments, Extra> {
|
|
74
|
-
const scriptModule: DeployScriptModule<NamedAccounts, Data, ArgumentsType, Deployments, Extra> = (
|
|
75
|
-
env: Environment<NamedAccounts, Data, Deployments, Extra>,
|
|
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
|
-
}
|
|
96
|
-
|
|
97
|
-
async function loadAndExecuteDeploymentsWithExtensions<
|
|
98
|
-
Extra extends Record<string, unknown> = Record<string, unknown>,
|
|
99
|
-
ArgumentsType = undefined
|
|
100
|
-
>(
|
|
101
|
-
executionParams: ExecutionParams<Extra>,
|
|
102
|
-
args?: ArgumentsType
|
|
103
|
-
): Promise<EnhancedEnvironment<NamedAccounts, Data, UnknownDeployments, Extensions>> {
|
|
104
|
-
const env = await loadAndExecuteDeployments<NamedAccounts, Data, ArgumentsType, Extra>(executionParams, args);
|
|
105
|
-
return enhanceEnvIfNeeded(env, extensions);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
async function loadEnvironmentWithExtensions(
|
|
109
|
-
executionParams: ExecutionParams<Extra>
|
|
110
|
-
): Promise<EnhancedEnvironment<NamedAccounts, Data, UnknownDeployments, Extensions>> {
|
|
111
|
-
const env = await loadEnvironment<NamedAccounts, Data, Extra>(executionParams);
|
|
112
|
-
return enhanceEnvIfNeeded(env, extensions);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
return {
|
|
116
|
-
deployScript: enhancedExecute,
|
|
117
|
-
loadAndExecuteDeployments: loadAndExecuteDeploymentsWithExtensions,
|
|
118
|
-
loadEnvironment: loadEnvironmentWithExtensions,
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
export function enhanceEnvIfNeeded<
|
|
123
|
-
Extensions extends Record<string, (env: Environment<any, any, any>) => any> = {},
|
|
124
|
-
NamedAccounts extends UnresolvedUnknownNamedAccounts = UnresolvedUnknownNamedAccounts,
|
|
125
|
-
Data extends UnresolvedNetworkSpecificData = UnresolvedNetworkSpecificData,
|
|
126
|
-
Extra extends Record<string, unknown> = Record<string, unknown>
|
|
127
|
-
>(
|
|
128
|
-
env: Environment,
|
|
129
|
-
extensions: Extensions
|
|
130
|
-
): EnhancedEnvironment<NamedAccounts, Data, UnknownDeployments, Extensions, Extra> {
|
|
131
|
-
// Use the original env object as the base
|
|
132
|
-
const enhancedEnv = env as EnhancedEnvironment<NamedAccounts, Data, UnknownDeployments, Extensions, Extra>;
|
|
133
|
-
|
|
134
|
-
// Only create curried functions for extensions not already present in env
|
|
135
|
-
for (const key in extensions) {
|
|
136
|
-
if (!Object.prototype.hasOwnProperty.call(env, key)) {
|
|
137
|
-
// Create curried function only for this specific extension
|
|
138
|
-
const singleExtension: Record<string, unknown> = {};
|
|
139
|
-
singleExtension[key] = (extensions as any)[key];
|
|
140
|
-
const curriedFunction = withEnvironment(env, singleExtension as any);
|
|
141
|
-
(enhancedEnv as any)[key] = (curriedFunction as any)[key];
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
return enhancedEnv;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
export async function readConfig<
|
|
148
|
-
NamedAccounts extends UnresolvedUnknownNamedAccounts = UnresolvedUnknownNamedAccounts,
|
|
149
|
-
Data extends UnresolvedNetworkSpecificData = UnresolvedNetworkSpecificData
|
|
150
|
-
>(): Promise<UserConfig> {
|
|
151
|
-
type ConfigFile = UserConfig<NamedAccounts, Data>;
|
|
152
|
-
let configFile: ConfigFile | undefined;
|
|
153
|
-
|
|
154
|
-
let tsVersion: string | undefined;
|
|
155
|
-
let jsVersion: string | undefined;
|
|
156
|
-
|
|
157
|
-
if (typeof process !== 'undefined') {
|
|
158
|
-
// TODO more sophisticated config file finding mechanism (look up parents, etc..)
|
|
159
|
-
const tsFilePath = path.join(process.cwd(), 'rocketh.ts');
|
|
160
|
-
const jsFilePath = path.join(process.cwd(), 'rocketh.js');
|
|
161
|
-
|
|
162
|
-
tsVersion = fs.existsSync(tsFilePath) ? `file://${tsFilePath}` : undefined;
|
|
163
|
-
jsVersion = fs.existsSync(jsFilePath) ? `file://${jsFilePath}` : undefined;
|
|
164
|
-
}
|
|
165
|
-
const existingConfigs = [tsVersion, jsVersion].filter(Boolean).length;
|
|
166
|
-
|
|
167
|
-
// console.log({tsFilePath, tsVersionExists, existingConfigs});
|
|
168
|
-
|
|
169
|
-
// Throw error if multiple config files exist
|
|
170
|
-
if (existingConfigs > 1) {
|
|
171
|
-
throw new Error('Multiple configuration files found. Please use only one of: rocketh.ts, rocketh.js');
|
|
172
|
-
}
|
|
173
|
-
if (tsVersion) {
|
|
174
|
-
const moduleLoaded = await import(tsVersion);
|
|
175
|
-
configFile = moduleLoaded.config;
|
|
176
|
-
// console.log({tsVersionExists: configFile});
|
|
177
|
-
// if ((configFile as any).default) {
|
|
178
|
-
// configFile = (configFile as any).default as ConfigFile;
|
|
179
|
-
// if ((configFile as any).default) {
|
|
180
|
-
// logger.warn(`double default...`);
|
|
181
|
-
// configFile = (configFile as any).default as ConfigFile;
|
|
182
|
-
// }
|
|
183
|
-
// }
|
|
184
|
-
} else if (jsVersion) {
|
|
185
|
-
const moduleLoaded = await import(jsVersion);
|
|
186
|
-
configFile = moduleLoaded.config;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
return configFile || {};
|
|
190
|
-
}
|
|
191
|
-
|
|
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
|
-
export async function readAndResolveConfig<
|
|
221
|
-
NamedAccounts extends UnresolvedUnknownNamedAccounts = UnresolvedUnknownNamedAccounts,
|
|
222
|
-
Data extends UnresolvedNetworkSpecificData = UnresolvedNetworkSpecificData
|
|
223
|
-
>(overrides?: ConfigOverrides): Promise<ResolvedUserConfig<NamedAccounts, Data>> {
|
|
224
|
-
const configFile = await readConfig();
|
|
225
|
-
return resolveConfig(configFile, overrides);
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
export async function getChainIdForEnvironment(
|
|
229
|
-
config: ResolvedUserConfig,
|
|
230
|
-
environmentName: string,
|
|
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
|
-
|
|
341
|
-
return {
|
|
342
|
-
askBeforeProceeding: executionParameters.askBeforeProceeding || false,
|
|
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,
|
|
358
|
-
};
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
export async function loadEnvironment<
|
|
362
|
-
NamedAccounts extends UnresolvedUnknownNamedAccounts = UnresolvedUnknownNamedAccounts,
|
|
363
|
-
Data extends UnresolvedNetworkSpecificData = UnresolvedNetworkSpecificData,
|
|
364
|
-
Extra extends Record<string, unknown> = Record<string, unknown>
|
|
365
|
-
>(executionParams: ExecutionParams<Extra>): Promise<Environment<NamedAccounts, Data, UnknownDeployments>> {
|
|
366
|
-
const userConfig = await readAndResolveConfig<NamedAccounts, Data>(executionParams.config);
|
|
367
|
-
const {name: environmentName, fork} = getEnvironmentName(executionParams);
|
|
368
|
-
const chainId = await getChainIdForEnvironment(userConfig, environmentName, executionParams.provider);
|
|
369
|
-
const resolvedExecutionParams = resolveExecutionParams(userConfig, executionParams, chainId);
|
|
370
|
-
// console.log(JSON.stringify(resolvedConfig, null, 2));
|
|
371
|
-
const {external, internal} = await createEnvironment<NamedAccounts, Data, UnknownDeployments>(
|
|
372
|
-
userConfig,
|
|
373
|
-
resolvedExecutionParams
|
|
374
|
-
);
|
|
375
|
-
return external;
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
export async function loadAndExecuteDeployments<
|
|
379
|
-
NamedAccounts extends UnresolvedUnknownNamedAccounts = UnresolvedUnknownNamedAccounts,
|
|
380
|
-
Data extends UnresolvedNetworkSpecificData = UnresolvedNetworkSpecificData,
|
|
381
|
-
ArgumentsType = undefined,
|
|
382
|
-
Extra extends Record<string, unknown> = Record<string, unknown>
|
|
383
|
-
>(
|
|
384
|
-
executionParams: ExecutionParams<Extra>,
|
|
385
|
-
args?: ArgumentsType
|
|
386
|
-
): Promise<Environment<NamedAccounts, Data, UnknownDeployments>> {
|
|
387
|
-
const userConfig = await readAndResolveConfig<NamedAccounts, Data>(executionParams.config);
|
|
388
|
-
const {name: environmentName, fork} = getEnvironmentName(executionParams);
|
|
389
|
-
const chainId = await getChainIdForEnvironment(userConfig, environmentName, executionParams.provider);
|
|
390
|
-
const resolvedExecutionParams = resolveExecutionParams(userConfig, executionParams, chainId);
|
|
391
|
-
// console.log(JSON.stringify(options, null, 2));
|
|
392
|
-
// console.log(JSON.stringify(resolvedConfig, null, 2));
|
|
393
|
-
return _executeDeployScripts<NamedAccounts, Data, ArgumentsType>(userConfig, resolvedExecutionParams, args);
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
export async function executeDeployScripts<
|
|
397
|
-
NamedAccounts extends UnresolvedUnknownNamedAccounts = UnresolvedUnknownNamedAccounts,
|
|
398
|
-
Data extends UnresolvedNetworkSpecificData = UnresolvedNetworkSpecificData,
|
|
399
|
-
ArgumentsType = undefined,
|
|
400
|
-
Extra extends Record<string, unknown> = Record<string, unknown>
|
|
401
|
-
>(
|
|
402
|
-
userConfig: UserConfig,
|
|
403
|
-
executionParams?: ExecutionParams<Extra>,
|
|
404
|
-
args?: ArgumentsType
|
|
405
|
-
): Promise<Environment<NamedAccounts, Data, UnknownDeployments>> {
|
|
406
|
-
executionParams = executionParams || {};
|
|
407
|
-
const resolveduserConfig = resolveConfig<NamedAccounts, Data>(userConfig, executionParams.config);
|
|
408
|
-
const {name: environmentName, fork} = getEnvironmentName(executionParams);
|
|
409
|
-
const chainId = await getChainIdForEnvironment(resolveduserConfig, environmentName, executionParams.provider);
|
|
410
|
-
const resolvedExecutionParams = resolveExecutionParams(resolveduserConfig, executionParams, chainId);
|
|
411
|
-
return _executeDeployScripts<NamedAccounts, Data, ArgumentsType>(resolveduserConfig, resolvedExecutionParams, args);
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
async function _executeDeployScripts<
|
|
415
|
-
NamedAccounts extends UnresolvedUnknownNamedAccounts = UnresolvedUnknownNamedAccounts,
|
|
416
|
-
Data extends UnresolvedNetworkSpecificData = UnresolvedNetworkSpecificData,
|
|
417
|
-
ArgumentsType = undefined
|
|
418
|
-
>(
|
|
419
|
-
userConfig: ResolvedUserConfig<NamedAccounts, Data>,
|
|
420
|
-
resolvedExecutionParams: ResolvedExecutionParams,
|
|
421
|
-
args?: ArgumentsType
|
|
422
|
-
): Promise<Environment<NamedAccounts, Data, UnknownDeployments>> {
|
|
423
|
-
setLogLevel(typeof resolvedExecutionParams.logLevel === 'undefined' ? 0 : resolvedExecutionParams.logLevel);
|
|
424
|
-
|
|
425
|
-
let filepaths;
|
|
426
|
-
filepaths = traverseMultipleDirectory(resolvedExecutionParams.scripts);
|
|
427
|
-
filepaths = filepaths
|
|
428
|
-
.filter((v) => !path.basename(v).startsWith('_'))
|
|
429
|
-
.sort((a: string, b: string) => {
|
|
430
|
-
if (a < b) {
|
|
431
|
-
return -1;
|
|
432
|
-
}
|
|
433
|
-
if (a > b) {
|
|
434
|
-
return 1;
|
|
435
|
-
}
|
|
436
|
-
return 0;
|
|
437
|
-
});
|
|
438
|
-
|
|
439
|
-
const scriptModuleByFilePath: {[filename: string]: DeployScriptModule<NamedAccounts, Data, ArgumentsType>} = {};
|
|
440
|
-
const scriptPathBags: {[tag: string]: string[]} = {};
|
|
441
|
-
const scriptFilePaths: string[] = [];
|
|
442
|
-
|
|
443
|
-
for (const filepath of filepaths) {
|
|
444
|
-
const scriptFilePath = path.resolve(filepath);
|
|
445
|
-
let scriptModule: DeployScriptModule<NamedAccounts, Data, ArgumentsType>;
|
|
446
|
-
try {
|
|
447
|
-
scriptModule = await import(`file://${scriptFilePath}`);
|
|
448
|
-
|
|
449
|
-
// console.log({
|
|
450
|
-
// scriptFilePath,
|
|
451
|
-
// scriptModule,
|
|
452
|
-
// });
|
|
453
|
-
if ((scriptModule as any).default) {
|
|
454
|
-
scriptModule = (scriptModule as any).default as DeployScriptModule<NamedAccounts, Data, ArgumentsType>;
|
|
455
|
-
if ((scriptModule as any).default) {
|
|
456
|
-
logger.warn(`double default...`);
|
|
457
|
-
scriptModule = (scriptModule as any).default as DeployScriptModule<NamedAccounts, Data, ArgumentsType>;
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
scriptModuleByFilePath[scriptFilePath] = scriptModule;
|
|
461
|
-
} catch (e) {
|
|
462
|
-
logger.error(`could not import ${filepath}`);
|
|
463
|
-
throw e;
|
|
464
|
-
}
|
|
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
|
-
}
|
|
501
|
-
|
|
502
|
-
const {internal, external} = await createEnvironment<NamedAccounts, Data, UnknownDeployments>(
|
|
503
|
-
userConfig,
|
|
504
|
-
resolvedExecutionParams
|
|
505
|
-
);
|
|
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
|
-
}
|