rocketh 0.15.0-testing.0 → 0.15.0-testing.10
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 +60 -0
- package/dist/cli.js +1 -1
- package/dist/cli.js.map +1 -1
- package/dist/environment/deployments.d.ts +1 -1
- package/dist/environment/deployments.d.ts.map +1 -1
- package/dist/environment/index.d.ts +2 -6
- package/dist/environment/index.d.ts.map +1 -1
- package/dist/environment/index.js +27 -51
- package/dist/environment/index.js.map +1 -1
- package/dist/environment/types.d.ts +33 -75
- package/dist/environment/types.d.ts.map +1 -1
- package/dist/environment/utils/artifacts.d.ts +1 -1
- package/dist/environment/utils/artifacts.d.ts.map +1 -1
- package/dist/environment/utils/chains.d.ts +3 -4
- package/dist/environment/utils/chains.d.ts.map +1 -1
- package/dist/environment/utils/chains.js +82 -16
- package/dist/environment/utils/chains.js.map +1 -1
- package/dist/executor/index.d.ts +13 -84
- package/dist/executor/index.d.ts.map +1 -1
- package/dist/executor/index.js +153 -214
- package/dist/executor/index.js.map +1 -1
- package/dist/executor/setup.test.d.ts +3 -3
- package/dist/executor/setup.test.d.ts.map +1 -1
- package/dist/executor/setup.test.js +1 -1
- package/dist/executor/setup.test.js.map +1 -1
- package/dist/executor/types.d.ts +92 -0
- package/dist/executor/types.d.ts.map +1 -1
- package/dist/index.d.ts +6 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -6
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +469 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/extensions.d.ts +1 -2
- package/dist/utils/extensions.d.ts.map +1 -1
- package/dist/utils/extensions.test.d.ts +2 -2
- package/dist/utils/extensions.test.d.ts.map +1 -1
- package/dist/utils/fs.d.ts +1 -1
- package/dist/utils/fs.d.ts.map +1 -1
- package/dist/utils/fs.js.map +1 -1
- package/package.json +3 -3
- package/src/cli.ts +3 -3
- package/src/environment/deployments.ts +1 -1
- package/src/environment/index.ts +33 -62
- package/src/environment/utils/artifacts.ts +1 -1
- package/src/environment/utils/chains.ts +110 -19
- package/src/executor/index.ts +204 -339
- package/src/executor/setup.test.ts +2 -2
- package/src/index.ts +14 -6
- package/src/types.ts +597 -0
- package/src/utils/extensions.test.ts +1 -1
- package/src/utils/extensions.ts +2 -2
- package/src/utils/fs.ts +1 -1
- package/src/environment/types.ts +0 -380
- package/src/executor/types.ts +0 -176
package/src/executor/index.ts
CHANGED
|
@@ -5,29 +5,27 @@ 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,
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
TargetConfig,
|
|
9
|
+
ExecutionParams,
|
|
10
|
+
ResolvedExecutionParams,
|
|
13
11
|
UnknownDeployments,
|
|
14
12
|
UnresolvedNetworkSpecificData,
|
|
15
13
|
UnresolvedUnknownNamedAccounts,
|
|
16
|
-
} from '../environment/types.js';
|
|
17
|
-
import {createEnvironment, SignerProtocolFunction} from '../environment/index.js';
|
|
18
|
-
import {
|
|
19
|
-
ChainInfo,
|
|
20
|
-
DeployScriptFunction,
|
|
21
14
|
DeployScriptModule,
|
|
22
15
|
EnhancedDeployScriptFunction,
|
|
23
16
|
EnhancedEnvironment,
|
|
24
|
-
|
|
17
|
+
ResolvedUserConfig,
|
|
18
|
+
ConfigOverrides,
|
|
19
|
+
UserConfig,
|
|
20
|
+
ChainConfig,
|
|
21
|
+
} from '../types.js';
|
|
25
22
|
import {withEnvironment} from '../utils/extensions.js';
|
|
26
23
|
import {logger, setLogLevel, spin} from '../internal/logging.js';
|
|
27
24
|
import {getRoughGasPriceEstimate} from '../utils/eth.js';
|
|
28
25
|
import {traverseMultipleDirectory} from '../utils/fs.js';
|
|
29
|
-
import {
|
|
26
|
+
import {getChainByName, getChainConfig} from '../environment/utils/chains.js';
|
|
30
27
|
import {JSONRPCHTTPProvider} from 'eip-1193-jsonrpc-provider';
|
|
28
|
+
import {createEnvironment} from '../environment/index.js';
|
|
31
29
|
|
|
32
30
|
// @ts-ignore
|
|
33
31
|
const tsImport = (path: string, opts: any) => (typeof Bun !== 'undefined' ? import(path) : tsImport_(path, opts));
|
|
@@ -92,18 +90,21 @@ export function setup<
|
|
|
92
90
|
return scriptModule;
|
|
93
91
|
}
|
|
94
92
|
|
|
95
|
-
async function loadAndExecuteDeploymentsWithExtensions<
|
|
96
|
-
|
|
93
|
+
async function loadAndExecuteDeploymentsWithExtensions<
|
|
94
|
+
Extra extends Record<string, unknown> = Record<string, unknown>,
|
|
95
|
+
ArgumentsType = undefined
|
|
96
|
+
>(
|
|
97
|
+
executionParams: ExecutionParams<Extra>,
|
|
97
98
|
args?: ArgumentsType
|
|
98
99
|
): Promise<EnhancedEnvironment<NamedAccounts, Data, UnknownDeployments, Extensions>> {
|
|
99
|
-
const env = await loadAndExecuteDeployments<NamedAccounts, Data, ArgumentsType, Extra>(
|
|
100
|
+
const env = await loadAndExecuteDeployments<NamedAccounts, Data, ArgumentsType, Extra>(executionParams, args);
|
|
100
101
|
return enhanceEnvIfNeeded(env, extensions);
|
|
101
102
|
}
|
|
102
103
|
|
|
103
104
|
async function loadEnvironmentWithExtensions(
|
|
104
|
-
|
|
105
|
+
executionParams: ExecutionParams<Extra>
|
|
105
106
|
): Promise<EnhancedEnvironment<NamedAccounts, Data, UnknownDeployments, Extensions>> {
|
|
106
|
-
const env = await loadEnvironment<NamedAccounts, Data, Extra>(
|
|
107
|
+
const env = await loadEnvironment<NamedAccounts, Data, Extra>(executionParams);
|
|
107
108
|
return enhanceEnvIfNeeded(env, extensions);
|
|
108
109
|
}
|
|
109
110
|
|
|
@@ -139,252 +140,10 @@ export function enhanceEnvIfNeeded<
|
|
|
139
140
|
return enhancedEnv;
|
|
140
141
|
}
|
|
141
142
|
|
|
142
|
-
export type NamedAccountExecuteFunction<
|
|
143
|
-
NamedAccounts extends UnresolvedUnknownNamedAccounts = UnresolvedUnknownNamedAccounts,
|
|
144
|
-
Data extends UnresolvedNetworkSpecificData = UnresolvedNetworkSpecificData
|
|
145
|
-
> = <ArgumentsType = undefined, Deployments extends UnknownDeployments = UnknownDeployments>(
|
|
146
|
-
callback: DeployScriptFunction<NamedAccounts, Data, ArgumentsType, Deployments>,
|
|
147
|
-
options: {tags?: string[]; dependencies?: string[]; id?: string}
|
|
148
|
-
) => DeployScriptModule<NamedAccounts, Data, ArgumentsType, Deployments>;
|
|
149
|
-
|
|
150
|
-
export interface UntypedRequestArguments {
|
|
151
|
-
readonly method: string;
|
|
152
|
-
readonly params?: readonly unknown[] | object;
|
|
153
|
-
}
|
|
154
|
-
export type UntypedEIP1193Provider = {
|
|
155
|
-
request(requestArguments: UntypedRequestArguments): Promise<unknown>;
|
|
156
|
-
};
|
|
157
|
-
|
|
158
|
-
export type ConfigOptions<Extra extends Record<string, unknown> = Record<string, unknown>> = {
|
|
159
|
-
target?: string | {fork: string};
|
|
160
|
-
deployments?: string;
|
|
161
|
-
scripts?: string | string[];
|
|
162
|
-
tags?: string;
|
|
163
|
-
logLevel?: number;
|
|
164
|
-
provider?: EIP1193ProviderWithoutEvents | EIP1193GenericRequestProvider | UntypedEIP1193Provider;
|
|
165
|
-
ignoreMissingRPC?: boolean;
|
|
166
|
-
saveDeployments?: boolean;
|
|
167
|
-
askBeforeProceeding?: boolean;
|
|
168
|
-
reportGasUse?: boolean;
|
|
169
|
-
extra?: Extra;
|
|
170
|
-
};
|
|
171
|
-
|
|
172
|
-
export type Create2DeterministicDeploymentInfo = {
|
|
173
|
-
factory: `0x${string}`;
|
|
174
|
-
deployer: `0x${string}`;
|
|
175
|
-
funding: string;
|
|
176
|
-
signedTx: `0x${string}`;
|
|
177
|
-
};
|
|
178
|
-
|
|
179
|
-
export type Create3DeterministicDeploymentInfo = {
|
|
180
|
-
salt?: `0x${string}`;
|
|
181
|
-
factory: `0x${string}`;
|
|
182
|
-
bytecode: `0x${string}`;
|
|
183
|
-
proxyBytecode: `0x${string}`;
|
|
184
|
-
};
|
|
185
|
-
|
|
186
|
-
export type DeterministicDeploymentInfo =
|
|
187
|
-
| Create2DeterministicDeploymentInfo
|
|
188
|
-
| {
|
|
189
|
-
create2?: Create2DeterministicDeploymentInfo;
|
|
190
|
-
create3?: Create3DeterministicDeploymentInfo;
|
|
191
|
-
};
|
|
192
|
-
|
|
193
|
-
export type ChainUserConfig = {
|
|
194
|
-
rpcUrl?: string;
|
|
195
|
-
tags?: string[];
|
|
196
|
-
deterministicDeployment?: DeterministicDeploymentInfo;
|
|
197
|
-
info?: ChainInfo;
|
|
198
|
-
pollingInterval?: number;
|
|
199
|
-
properties?: Record<string, JSONTypePlusBigInt>;
|
|
200
|
-
};
|
|
201
|
-
|
|
202
|
-
export type DeploymentTargetConfig = {
|
|
203
|
-
chainId: number;
|
|
204
|
-
scripts?: string | string[];
|
|
205
|
-
overrides: Omit<ChainUserConfig, 'info'>;
|
|
206
|
-
};
|
|
207
|
-
|
|
208
|
-
export type Chains = {
|
|
209
|
-
[idOrName: number | string]: ChainUserConfig;
|
|
210
|
-
};
|
|
211
|
-
export type UserConfig<
|
|
212
|
-
NamedAccounts extends UnresolvedUnknownNamedAccounts = UnresolvedUnknownNamedAccounts,
|
|
213
|
-
Data extends UnresolvedNetworkSpecificData = UnresolvedNetworkSpecificData
|
|
214
|
-
> = {
|
|
215
|
-
targets: {[name: string]: DeploymentTargetConfig};
|
|
216
|
-
chains?: Chains;
|
|
217
|
-
deployments?: string;
|
|
218
|
-
scripts?: string | string[];
|
|
219
|
-
accounts?: NamedAccounts;
|
|
220
|
-
data?: Data;
|
|
221
|
-
signerProtocols?: Record<string, SignerProtocolFunction>;
|
|
222
|
-
defaultPollingInterval?: number;
|
|
223
|
-
};
|
|
224
|
-
|
|
225
|
-
export async function transformUserConfig<
|
|
226
|
-
NamedAccounts extends UnresolvedUnknownNamedAccounts = UnresolvedUnknownNamedAccounts,
|
|
227
|
-
Data extends UnresolvedNetworkSpecificData = UnresolvedNetworkSpecificData,
|
|
228
|
-
Extra extends Record<string, unknown> = Record<string, unknown>
|
|
229
|
-
>(
|
|
230
|
-
configFile: UserConfig<NamedAccounts, Data> | undefined,
|
|
231
|
-
options: ConfigOptions<Extra>
|
|
232
|
-
): Promise<Config<NamedAccounts, Data>> {
|
|
233
|
-
if (configFile) {
|
|
234
|
-
if (!options.deployments && configFile.deployments) {
|
|
235
|
-
options.deployments = configFile.deployments;
|
|
236
|
-
}
|
|
237
|
-
if (!options.scripts && configFile.scripts) {
|
|
238
|
-
options.scripts = configFile.scripts;
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
const fork = typeof options.target !== 'string';
|
|
243
|
-
let targetName = 'memory';
|
|
244
|
-
if (options.target) {
|
|
245
|
-
if (typeof options.target === 'string') {
|
|
246
|
-
targetName = options.target;
|
|
247
|
-
} else if ('fork' in options.target) {
|
|
248
|
-
targetName = options.target.fork;
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
let chainInfo: ChainInfo;
|
|
253
|
-
|
|
254
|
-
let chainId: number;
|
|
255
|
-
|
|
256
|
-
if (configFile?.targets[targetName]) {
|
|
257
|
-
chainId = configFile.targets[targetName].chainId;
|
|
258
|
-
} else {
|
|
259
|
-
const chainFound = getChainByName(targetName);
|
|
260
|
-
if (chainFound) {
|
|
261
|
-
chainInfo = chainFound;
|
|
262
|
-
chainId = chainInfo.id;
|
|
263
|
-
} else {
|
|
264
|
-
if (options.provider) {
|
|
265
|
-
const chainIdAsHex = await (options.provider as EIP1193ProviderWithoutEvents).request({method: 'eth_chainId'});
|
|
266
|
-
chainId = Number(chainIdAsHex);
|
|
267
|
-
} else {
|
|
268
|
-
throw new Error(`target ${targetName} is unknown`);
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
const chainFound = getChain(chainId);
|
|
274
|
-
if (chainFound) {
|
|
275
|
-
chainInfo = chainFound;
|
|
276
|
-
} else {
|
|
277
|
-
throw new Error(`target ${targetName} has no chain associated with it`);
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
const chainConfigFromChainId = configFile?.chains?.[chainId];
|
|
281
|
-
const chainConfigFromChainName = configFile?.chains?.[targetName];
|
|
282
|
-
if (chainConfigFromChainId && chainConfigFromChainName) {
|
|
283
|
-
throw new Error(
|
|
284
|
-
`conflicting config for chain, choose to configure via its chainId (${chainId}) or via its name ${targetName} but not both`
|
|
285
|
-
);
|
|
286
|
-
}
|
|
287
|
-
const chainConfig = chainConfigFromChainId || chainConfigFromChainName;
|
|
288
|
-
|
|
289
|
-
const targetConfig = configFile?.targets?.[targetName];
|
|
290
|
-
const actualChainConfig = targetConfig?.overrides
|
|
291
|
-
? {
|
|
292
|
-
...chainConfig,
|
|
293
|
-
...targetConfig.overrides,
|
|
294
|
-
properties: {
|
|
295
|
-
...chainConfig?.properties,
|
|
296
|
-
...targetConfig.overrides.properties,
|
|
297
|
-
},
|
|
298
|
-
}
|
|
299
|
-
: chainConfig;
|
|
300
|
-
|
|
301
|
-
const defaultTags: string[] = [];
|
|
302
|
-
if (chainInfo.testnet) {
|
|
303
|
-
defaultTags.push('testnet');
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
let targetTags: string[] = actualChainConfig?.tags || defaultTags;
|
|
307
|
-
|
|
308
|
-
let networkScripts: string | string[] | undefined = targetConfig?.scripts;
|
|
309
|
-
|
|
310
|
-
// no default for publicInfo
|
|
311
|
-
const defaultPollingInterval = configFile?.defaultPollingInterval;
|
|
312
|
-
const pollingInterval = actualChainConfig?.pollingInterval;
|
|
313
|
-
const deterministicDeployment = actualChainConfig?.deterministicDeployment;
|
|
314
|
-
const properties = actualChainConfig?.properties;
|
|
315
|
-
|
|
316
|
-
let resolvedTargetConfig: TargetConfig;
|
|
317
|
-
|
|
318
|
-
if (!options.provider) {
|
|
319
|
-
let rpcURL = actualChainConfig?.rpcUrl;
|
|
320
|
-
if (!rpcURL) {
|
|
321
|
-
rpcURL = chainInfo.rpcUrls.default.http[0];
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
const fromEnv = process.env['ETH_NODE_URI_' + targetName];
|
|
325
|
-
let nodeUrl: string;
|
|
326
|
-
if (typeof fromEnv === 'string' && fromEnv) {
|
|
327
|
-
nodeUrl = fromEnv;
|
|
328
|
-
} else {
|
|
329
|
-
if (rpcURL) {
|
|
330
|
-
nodeUrl = rpcURL;
|
|
331
|
-
} else if (options?.ignoreMissingRPC) {
|
|
332
|
-
nodeUrl = '';
|
|
333
|
-
} else if (options.target === 'localhost') {
|
|
334
|
-
nodeUrl = 'http://127.0.0.1:8545';
|
|
335
|
-
} else {
|
|
336
|
-
console.error(`network "${options.target}" is not configured. Please add it to the rocketh.js/ts file`);
|
|
337
|
-
process.exit(1);
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
resolvedTargetConfig = {
|
|
342
|
-
nodeUrl,
|
|
343
|
-
name: targetName,
|
|
344
|
-
tags: targetTags,
|
|
345
|
-
fork,
|
|
346
|
-
deterministicDeployment,
|
|
347
|
-
scripts: networkScripts,
|
|
348
|
-
chainInfo,
|
|
349
|
-
pollingInterval,
|
|
350
|
-
properties,
|
|
351
|
-
};
|
|
352
|
-
} else {
|
|
353
|
-
resolvedTargetConfig = {
|
|
354
|
-
provider: options.provider as EIP1193ProviderWithoutEvents,
|
|
355
|
-
name: targetName,
|
|
356
|
-
tags: targetTags,
|
|
357
|
-
fork,
|
|
358
|
-
deterministicDeployment,
|
|
359
|
-
scripts: networkScripts,
|
|
360
|
-
chainInfo,
|
|
361
|
-
pollingInterval,
|
|
362
|
-
properties,
|
|
363
|
-
};
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
return {
|
|
367
|
-
target: resolvedTargetConfig,
|
|
368
|
-
deployments: options.deployments,
|
|
369
|
-
saveDeployments: options.saveDeployments,
|
|
370
|
-
scripts: options.scripts,
|
|
371
|
-
data: configFile?.data,
|
|
372
|
-
tags: typeof options.tags === 'undefined' ? undefined : options.tags.split(','),
|
|
373
|
-
logLevel: options.logLevel,
|
|
374
|
-
askBeforeProceeding: options.askBeforeProceeding,
|
|
375
|
-
reportGasUse: options.reportGasUse,
|
|
376
|
-
accounts: configFile?.accounts,
|
|
377
|
-
signerProtocols: configFile?.signerProtocols,
|
|
378
|
-
extra: options.extra,
|
|
379
|
-
defaultPollingInterval,
|
|
380
|
-
};
|
|
381
|
-
}
|
|
382
|
-
|
|
383
143
|
export async function readConfig<
|
|
384
144
|
NamedAccounts extends UnresolvedUnknownNamedAccounts = UnresolvedUnknownNamedAccounts,
|
|
385
|
-
Data extends UnresolvedNetworkSpecificData = UnresolvedNetworkSpecificData
|
|
386
|
-
|
|
387
|
-
>(options: ConfigOptions<Extra>): Promise<Config<NamedAccounts, Data>> {
|
|
145
|
+
Data extends UnresolvedNetworkSpecificData = UnresolvedNetworkSpecificData
|
|
146
|
+
>(): Promise<UserConfig> {
|
|
388
147
|
type ConfigFile = UserConfig<NamedAccounts, Data>;
|
|
389
148
|
let configFile: ConfigFile | undefined;
|
|
390
149
|
|
|
@@ -423,59 +182,109 @@ export async function readConfig<
|
|
|
423
182
|
configFile = moduleLoaded.config;
|
|
424
183
|
}
|
|
425
184
|
|
|
426
|
-
return
|
|
185
|
+
return configFile || {};
|
|
427
186
|
}
|
|
428
187
|
|
|
429
|
-
export
|
|
188
|
+
export function resolveConfig<
|
|
430
189
|
NamedAccounts extends UnresolvedUnknownNamedAccounts = UnresolvedUnknownNamedAccounts,
|
|
431
|
-
Data extends UnresolvedNetworkSpecificData = UnresolvedNetworkSpecificData
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
190
|
+
Data extends UnresolvedNetworkSpecificData = UnresolvedNetworkSpecificData
|
|
191
|
+
>(configFile: UserConfig, overrides?: ConfigOverrides): ResolvedUserConfig<NamedAccounts, Data> {
|
|
192
|
+
const config = {
|
|
193
|
+
deployments: 'deployments',
|
|
194
|
+
defaultPollingInterval: 1,
|
|
195
|
+
...configFile,
|
|
196
|
+
scripts: configFile?.scripts
|
|
197
|
+
? typeof configFile.scripts === 'string'
|
|
198
|
+
? [configFile.scripts]
|
|
199
|
+
: configFile.scripts.length == 0
|
|
200
|
+
? ['deploy']
|
|
201
|
+
: configFile.scripts
|
|
202
|
+
: ['deploy'],
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
if (overrides) {
|
|
206
|
+
for (const key of Object.keys(overrides)) {
|
|
207
|
+
if ((overrides as any)[key] !== undefined) {
|
|
208
|
+
(config as any)[key] = (overrides as any)[key];
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
return config;
|
|
435
214
|
}
|
|
436
215
|
|
|
437
|
-
export function
|
|
216
|
+
export async function readAndResolveConfig<
|
|
438
217
|
NamedAccounts extends UnresolvedUnknownNamedAccounts = UnresolvedUnknownNamedAccounts,
|
|
439
218
|
Data extends UnresolvedNetworkSpecificData = UnresolvedNetworkSpecificData
|
|
440
|
-
>(
|
|
441
|
-
const
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
};
|
|
219
|
+
>(overrides?: ConfigOverrides): Promise<ResolvedUserConfig<NamedAccounts, Data>> {
|
|
220
|
+
const configFile = await readConfig();
|
|
221
|
+
return resolveConfig(configFile, overrides);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
export async function getChainIdForTarget(
|
|
225
|
+
config: ResolvedUserConfig,
|
|
226
|
+
targetName: string,
|
|
227
|
+
provider?: EIP1193ProviderWithoutEvents
|
|
228
|
+
) {
|
|
229
|
+
if (config?.targets?.[targetName]?.chainId) {
|
|
230
|
+
return config.targets[targetName].chainId;
|
|
231
|
+
} else {
|
|
232
|
+
const chainFound = getChainByName(targetName);
|
|
233
|
+
if (chainFound) {
|
|
234
|
+
return chainFound.id;
|
|
235
|
+
} else {
|
|
236
|
+
if (provider) {
|
|
237
|
+
const chainIdAsHex = await provider.request({method: 'eth_chainId'});
|
|
238
|
+
return Number(chainIdAsHex);
|
|
239
|
+
} else {
|
|
240
|
+
throw new Error(`target ${targetName} chain id cannot be found, specify it in the rocketh config`);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
function getTargetName(executionParams: ExecutionParams): {name: string; fork: boolean} {
|
|
247
|
+
const targetProvided = executionParams.target || (executionParams as any).network;
|
|
248
|
+
let targetName = 'memory';
|
|
249
|
+
if (targetProvided) {
|
|
250
|
+
if (typeof targetProvided === 'string') {
|
|
251
|
+
targetName = targetProvided;
|
|
252
|
+
} else if ('fork' in targetProvided) {
|
|
253
|
+
targetName = targetProvided.fork;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
const fork = typeof targetProvided !== 'string';
|
|
257
|
+
return {name: targetName, fork};
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
export function resolveExecutionParams<Extra extends Record<string, unknown> = Record<string, unknown>>(
|
|
261
|
+
config: ResolvedUserConfig,
|
|
262
|
+
executionParameters: ExecutionParams<Extra>,
|
|
263
|
+
chainId: number
|
|
264
|
+
): ResolvedExecutionParams<Extra> {
|
|
265
|
+
const {name: targetName, fork} = getTargetName(executionParameters);
|
|
266
|
+
|
|
267
|
+
let chainConfig: ChainConfig = getChainConfig(chainId, config);
|
|
268
|
+
|
|
269
|
+
let chainInfo = chainConfig.info;
|
|
270
|
+
const targetConfig = config?.targets?.[targetName];
|
|
271
|
+
const actualChainConfig = targetConfig?.overrides
|
|
272
|
+
? {
|
|
273
|
+
...chainConfig,
|
|
274
|
+
...targetConfig.overrides,
|
|
275
|
+
properties: {
|
|
276
|
+
...chainConfig?.properties,
|
|
277
|
+
...targetConfig.overrides.properties,
|
|
278
|
+
},
|
|
279
|
+
}
|
|
280
|
+
: chainConfig;
|
|
281
|
+
|
|
282
|
+
if (actualChainConfig?.properties) {
|
|
283
|
+
chainInfo = {...chainInfo, properties: actualChainConfig.properties};
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
// let targetTags: string[] = actualChainConfig.tags.concat(targetConfig?.tags); // TODO
|
|
287
|
+
const targetTags = actualChainConfig.tags;
|
|
479
288
|
|
|
480
289
|
let scripts = ['deploy'];
|
|
481
290
|
if (config.scripts) {
|
|
@@ -486,38 +295,66 @@ export function resolveConfig<
|
|
|
486
295
|
}
|
|
487
296
|
}
|
|
488
297
|
|
|
489
|
-
if (
|
|
490
|
-
if (typeof
|
|
491
|
-
scripts = [
|
|
298
|
+
if (targetConfig?.scripts) {
|
|
299
|
+
if (typeof targetConfig.scripts === 'string') {
|
|
300
|
+
scripts = [targetConfig.scripts];
|
|
492
301
|
} else {
|
|
493
|
-
scripts =
|
|
302
|
+
scripts = targetConfig.scripts;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
const provider =
|
|
307
|
+
executionParameters.provider || (new JSONRPCHTTPProvider(actualChainConfig.rpcUrl) as EIP1193ProviderWithoutEvents);
|
|
308
|
+
|
|
309
|
+
let saveDeployments = executionParameters.saveDeployments;
|
|
310
|
+
|
|
311
|
+
if (saveDeployments === undefined) {
|
|
312
|
+
if (!executionParameters.provider) {
|
|
313
|
+
saveDeployments = true;
|
|
314
|
+
} else {
|
|
315
|
+
if (targetName === 'memory' || targetName === 'hardhat' || targetName === 'default') {
|
|
316
|
+
// networkTags['memory'] = true;
|
|
317
|
+
saveDeployments = false;
|
|
318
|
+
} else {
|
|
319
|
+
saveDeployments = true;
|
|
320
|
+
}
|
|
494
321
|
}
|
|
495
322
|
}
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
323
|
+
|
|
324
|
+
return {
|
|
325
|
+
askBeforeProceeding: executionParameters.askBeforeProceeding || false,
|
|
326
|
+
chain: chainInfo,
|
|
327
|
+
logLevel: executionParameters.logLevel || 0, // TODO
|
|
328
|
+
pollingInterval: actualChainConfig.pollingInterval,
|
|
329
|
+
reportGasUse: executionParameters.reportGasUse || false,
|
|
330
|
+
saveDeployments,
|
|
331
|
+
tags: executionParameters.tags || [],
|
|
332
|
+
target: {
|
|
333
|
+
name: targetName,
|
|
334
|
+
tags: targetTags,
|
|
335
|
+
fork,
|
|
336
|
+
deterministicDeployment: actualChainConfig.deterministicDeployment,
|
|
337
|
+
},
|
|
338
|
+
extra: executionParameters.extra,
|
|
339
|
+
provider,
|
|
500
340
|
scripts,
|
|
501
|
-
tags: config.tags || [],
|
|
502
|
-
targetTags: config.targetTags || [],
|
|
503
|
-
saveDeployments: config.saveDeployments,
|
|
504
|
-
accounts: config.accounts || ({} as NamedAccounts),
|
|
505
|
-
data: config.data || ({} as Data),
|
|
506
|
-
signerProtocols: config.signerProtocols || {},
|
|
507
|
-
extra: config.extra || {},
|
|
508
|
-
defaultPollingInterval,
|
|
509
341
|
};
|
|
510
|
-
return resolvedConfig;
|
|
511
342
|
}
|
|
512
343
|
|
|
513
344
|
export async function loadEnvironment<
|
|
514
345
|
NamedAccounts extends UnresolvedUnknownNamedAccounts = UnresolvedUnknownNamedAccounts,
|
|
515
346
|
Data extends UnresolvedNetworkSpecificData = UnresolvedNetworkSpecificData,
|
|
516
347
|
Extra extends Record<string, unknown> = Record<string, unknown>
|
|
517
|
-
>(
|
|
518
|
-
const
|
|
348
|
+
>(executionParams: ExecutionParams<Extra>): Promise<Environment<NamedAccounts, Data, UnknownDeployments>> {
|
|
349
|
+
const userConfig = await readAndResolveConfig<NamedAccounts, Data>(executionParams.config);
|
|
350
|
+
const {name: targetName, fork} = getTargetName(executionParams);
|
|
351
|
+
const chainId = await getChainIdForTarget(userConfig, targetName, executionParams.provider);
|
|
352
|
+
const resolvedExecutionParams = resolveExecutionParams(userConfig, executionParams, chainId);
|
|
519
353
|
// console.log(JSON.stringify(resolvedConfig, null, 2));
|
|
520
|
-
const {external, internal} = await createEnvironment(
|
|
354
|
+
const {external, internal} = await createEnvironment<NamedAccounts, Data, UnknownDeployments>(
|
|
355
|
+
userConfig,
|
|
356
|
+
resolvedExecutionParams
|
|
357
|
+
);
|
|
521
358
|
return external;
|
|
522
359
|
}
|
|
523
360
|
|
|
@@ -526,11 +363,35 @@ export async function loadAndExecuteDeployments<
|
|
|
526
363
|
Data extends UnresolvedNetworkSpecificData = UnresolvedNetworkSpecificData,
|
|
527
364
|
ArgumentsType = undefined,
|
|
528
365
|
Extra extends Record<string, unknown> = Record<string, unknown>
|
|
529
|
-
>(
|
|
530
|
-
|
|
366
|
+
>(
|
|
367
|
+
executionParams: ExecutionParams<Extra>,
|
|
368
|
+
args?: ArgumentsType
|
|
369
|
+
): Promise<Environment<NamedAccounts, Data, UnknownDeployments>> {
|
|
370
|
+
const userConfig = await readAndResolveConfig<NamedAccounts, Data>(executionParams.config);
|
|
371
|
+
const {name: targetName, fork} = getTargetName(executionParams);
|
|
372
|
+
const chainId = await getChainIdForTarget(userConfig, targetName, executionParams.provider);
|
|
373
|
+
const resolvedExecutionParams = resolveExecutionParams(userConfig, executionParams, chainId);
|
|
531
374
|
// console.log(JSON.stringify(options, null, 2));
|
|
532
375
|
// console.log(JSON.stringify(resolvedConfig, null, 2));
|
|
533
|
-
return executeDeployScripts<NamedAccounts, Data, ArgumentsType>(
|
|
376
|
+
return executeDeployScripts<NamedAccounts, Data, ArgumentsType>(userConfig, resolvedExecutionParams, args);
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
export async function executeDeployScriptsDirectly<
|
|
380
|
+
NamedAccounts extends UnresolvedUnknownNamedAccounts = UnresolvedUnknownNamedAccounts,
|
|
381
|
+
Data extends UnresolvedNetworkSpecificData = UnresolvedNetworkSpecificData,
|
|
382
|
+
ArgumentsType = undefined,
|
|
383
|
+
Extra extends Record<string, unknown> = Record<string, unknown>
|
|
384
|
+
>(
|
|
385
|
+
userConfig: UserConfig,
|
|
386
|
+
executionParams?: ExecutionParams<Extra>,
|
|
387
|
+
args?: ArgumentsType
|
|
388
|
+
): Promise<Environment<NamedAccounts, Data, UnknownDeployments>> {
|
|
389
|
+
executionParams = executionParams || {};
|
|
390
|
+
const resolveduserConfig = resolveConfig<NamedAccounts, Data>(userConfig);
|
|
391
|
+
const {name: targetName, fork} = getTargetName(executionParams);
|
|
392
|
+
const chainId = await getChainIdForTarget(resolveduserConfig, targetName, executionParams.provider);
|
|
393
|
+
const resolvedExecutionParams = resolveExecutionParams(resolveduserConfig, executionParams, chainId);
|
|
394
|
+
return executeDeployScripts<NamedAccounts, Data, ArgumentsType>(resolveduserConfig, resolvedExecutionParams, args);
|
|
534
395
|
}
|
|
535
396
|
|
|
536
397
|
export async function executeDeployScripts<
|
|
@@ -538,13 +399,14 @@ export async function executeDeployScripts<
|
|
|
538
399
|
Data extends UnresolvedNetworkSpecificData = UnresolvedNetworkSpecificData,
|
|
539
400
|
ArgumentsType = undefined
|
|
540
401
|
>(
|
|
541
|
-
|
|
402
|
+
userConfig: ResolvedUserConfig<NamedAccounts, Data>,
|
|
403
|
+
resolvedExecutionParams: ResolvedExecutionParams,
|
|
542
404
|
args?: ArgumentsType
|
|
543
405
|
): Promise<Environment<NamedAccounts, Data, UnknownDeployments>> {
|
|
544
|
-
setLogLevel(typeof
|
|
406
|
+
setLogLevel(typeof resolvedExecutionParams.logLevel === 'undefined' ? 0 : resolvedExecutionParams.logLevel);
|
|
545
407
|
|
|
546
408
|
let filepaths;
|
|
547
|
-
filepaths = traverseMultipleDirectory(
|
|
409
|
+
filepaths = traverseMultipleDirectory(resolvedExecutionParams.scripts);
|
|
548
410
|
filepaths = filepaths
|
|
549
411
|
.filter((v) => !path.basename(v).startsWith('_'))
|
|
550
412
|
.sort((a: string, b: string) => {
|
|
@@ -599,10 +461,10 @@ export async function executeDeployScripts<
|
|
|
599
461
|
}
|
|
600
462
|
}
|
|
601
463
|
|
|
602
|
-
if (
|
|
464
|
+
if (resolvedExecutionParams.tags !== undefined && resolvedExecutionParams.tags.length > 0) {
|
|
603
465
|
let found = false;
|
|
604
466
|
if (scriptTags !== undefined) {
|
|
605
|
-
for (const tagToFind of
|
|
467
|
+
for (const tagToFind of resolvedExecutionParams.tags) {
|
|
606
468
|
for (const tag of scriptTags) {
|
|
607
469
|
if (tag === tagToFind) {
|
|
608
470
|
scriptFilePaths.push(scriptFilePath);
|
|
@@ -620,7 +482,10 @@ export async function executeDeployScripts<
|
|
|
620
482
|
}
|
|
621
483
|
}
|
|
622
484
|
|
|
623
|
-
const {internal, external} = await createEnvironment(
|
|
485
|
+
const {internal, external} = await createEnvironment<NamedAccounts, Data, UnknownDeployments>(
|
|
486
|
+
userConfig,
|
|
487
|
+
resolvedExecutionParams
|
|
488
|
+
);
|
|
624
489
|
|
|
625
490
|
await internal.recoverTransactionsIfAny();
|
|
626
491
|
|
|
@@ -667,10 +532,10 @@ export async function executeDeployScripts<
|
|
|
667
532
|
recurseDependencies(scriptFilePath);
|
|
668
533
|
}
|
|
669
534
|
|
|
670
|
-
if (
|
|
535
|
+
if (resolvedExecutionParams.askBeforeProceeding) {
|
|
671
536
|
console.log(
|
|
672
|
-
`Network: ${external.
|
|
673
|
-
external.
|
|
537
|
+
`Network: ${external.name} \n \t Chain: ${external.network.chain.name} \n \t Tags: ${Object.keys(
|
|
538
|
+
external.tags
|
|
674
539
|
).join(',')}`
|
|
675
540
|
);
|
|
676
541
|
const gasPriceEstimate = await getRoughGasPriceEstimate(external.network.provider);
|
|
@@ -736,7 +601,7 @@ Do you want to proceed (note that gas price can change for each tx)`,
|
|
|
736
601
|
}
|
|
737
602
|
}
|
|
738
603
|
|
|
739
|
-
if (
|
|
604
|
+
if (resolvedExecutionParams.reportGasUse) {
|
|
740
605
|
const provider = external.network.provider;
|
|
741
606
|
const transactionHashes = provider.transactionHashes;
|
|
742
607
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {Environment} from '../
|
|
1
|
+
import type {Environment} from '../types.js';
|
|
2
2
|
import {setup} from './index.js';
|
|
3
3
|
|
|
4
4
|
// Mock environment for testing
|
|
@@ -134,7 +134,7 @@ export const exampleUsage = () => {
|
|
|
134
134
|
await env.verifyOnEtherscan(tokenAddress, ['MyToken', 'MTK']);
|
|
135
135
|
|
|
136
136
|
// Original environment is still fully accessible
|
|
137
|
-
console.log(`Deployed on
|
|
137
|
+
console.log(`Deployed on target: ${env.name}`);
|
|
138
138
|
const deployment = env.get('MyToken');
|
|
139
139
|
|
|
140
140
|
return true;
|