rocketh 0.15.0-testing.1 → 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 +54 -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 -215
- 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 -340
- 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,253 +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 targetProvided = options.target || (options as any).network; // fallback on network
|
|
243
|
-
const fork = typeof targetProvided !== 'string';
|
|
244
|
-
let targetName = 'memory';
|
|
245
|
-
if (options.target) {
|
|
246
|
-
if (typeof options.target === 'string') {
|
|
247
|
-
targetName = options.target;
|
|
248
|
-
} else if ('fork' in options.target) {
|
|
249
|
-
targetName = options.target.fork;
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
let chainInfo: ChainInfo;
|
|
254
|
-
|
|
255
|
-
let chainId: number;
|
|
256
|
-
|
|
257
|
-
if (configFile?.targets?.[targetName]) {
|
|
258
|
-
chainId = configFile.targets[targetName].chainId;
|
|
259
|
-
} else {
|
|
260
|
-
const chainFound = getChainByName(targetName);
|
|
261
|
-
if (chainFound) {
|
|
262
|
-
chainInfo = chainFound;
|
|
263
|
-
chainId = chainInfo.id;
|
|
264
|
-
} else {
|
|
265
|
-
if (options.provider) {
|
|
266
|
-
const chainIdAsHex = await (options.provider as EIP1193ProviderWithoutEvents).request({method: 'eth_chainId'});
|
|
267
|
-
chainId = Number(chainIdAsHex);
|
|
268
|
-
} else {
|
|
269
|
-
throw new Error(`target ${targetName} is unknown`);
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
const chainConfigFromChainId = configFile?.chains?.[chainId];
|
|
275
|
-
const chainConfigFromChainName = configFile?.chains?.[targetName];
|
|
276
|
-
if (chainConfigFromChainId && chainConfigFromChainName) {
|
|
277
|
-
throw new Error(
|
|
278
|
-
`conflicting config for chain, choose to configure via its chainId (${chainId}) or via its name ${targetName} but not both`
|
|
279
|
-
);
|
|
280
|
-
}
|
|
281
|
-
const chainConfig = chainConfigFromChainId || chainConfigFromChainName;
|
|
282
|
-
|
|
283
|
-
const targetConfig = configFile?.targets?.[targetName];
|
|
284
|
-
const actualChainConfig = targetConfig?.overrides
|
|
285
|
-
? {
|
|
286
|
-
...chainConfig,
|
|
287
|
-
...targetConfig.overrides,
|
|
288
|
-
properties: {
|
|
289
|
-
...chainConfig?.properties,
|
|
290
|
-
...targetConfig.overrides.properties,
|
|
291
|
-
},
|
|
292
|
-
}
|
|
293
|
-
: chainConfig;
|
|
294
|
-
|
|
295
|
-
const defaultTags: string[] = [];
|
|
296
|
-
|
|
297
|
-
const chainFound = actualChainConfig?.info || getChain(chainId);
|
|
298
|
-
if (chainFound) {
|
|
299
|
-
chainInfo = chainFound;
|
|
300
|
-
} else {
|
|
301
|
-
throw new Error(`chain with id ${chainId} has no chainInfo associated with it`);
|
|
302
|
-
}
|
|
303
|
-
if (chainInfo.testnet) {
|
|
304
|
-
defaultTags.push('testnet');
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
let targetTags: string[] = actualChainConfig?.tags || defaultTags;
|
|
308
|
-
|
|
309
|
-
let networkScripts: string | string[] | undefined = targetConfig?.scripts;
|
|
310
|
-
|
|
311
|
-
// no default for publicInfo
|
|
312
|
-
const defaultPollingInterval = configFile?.defaultPollingInterval;
|
|
313
|
-
const pollingInterval = actualChainConfig?.pollingInterval;
|
|
314
|
-
const deterministicDeployment = actualChainConfig?.deterministicDeployment;
|
|
315
|
-
const properties = actualChainConfig?.properties;
|
|
316
|
-
|
|
317
|
-
let resolvedTargetConfig: TargetConfig;
|
|
318
|
-
|
|
319
|
-
if (!options.provider) {
|
|
320
|
-
let rpcURL = actualChainConfig?.rpcUrl;
|
|
321
|
-
if (!rpcURL) {
|
|
322
|
-
rpcURL = chainInfo.rpcUrls.default.http[0];
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
const fromEnv = process.env['ETH_NODE_URI_' + targetName];
|
|
326
|
-
let nodeUrl: string;
|
|
327
|
-
if (typeof fromEnv === 'string' && fromEnv) {
|
|
328
|
-
nodeUrl = fromEnv;
|
|
329
|
-
} else {
|
|
330
|
-
if (rpcURL) {
|
|
331
|
-
nodeUrl = rpcURL;
|
|
332
|
-
} else if (options?.ignoreMissingRPC) {
|
|
333
|
-
nodeUrl = '';
|
|
334
|
-
} else if (options.target === 'localhost') {
|
|
335
|
-
nodeUrl = 'http://127.0.0.1:8545';
|
|
336
|
-
} else {
|
|
337
|
-
console.error(`network "${options.target}" is not configured. Please add it to the rocketh.js/ts file`);
|
|
338
|
-
process.exit(1);
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
resolvedTargetConfig = {
|
|
343
|
-
nodeUrl,
|
|
344
|
-
name: targetName,
|
|
345
|
-
tags: targetTags,
|
|
346
|
-
fork,
|
|
347
|
-
deterministicDeployment,
|
|
348
|
-
scripts: networkScripts,
|
|
349
|
-
chainInfo,
|
|
350
|
-
pollingInterval,
|
|
351
|
-
properties,
|
|
352
|
-
};
|
|
353
|
-
} else {
|
|
354
|
-
resolvedTargetConfig = {
|
|
355
|
-
provider: options.provider as EIP1193ProviderWithoutEvents,
|
|
356
|
-
name: targetName,
|
|
357
|
-
tags: targetTags,
|
|
358
|
-
fork,
|
|
359
|
-
deterministicDeployment,
|
|
360
|
-
scripts: networkScripts,
|
|
361
|
-
chainInfo,
|
|
362
|
-
pollingInterval,
|
|
363
|
-
properties,
|
|
364
|
-
};
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
return {
|
|
368
|
-
target: resolvedTargetConfig,
|
|
369
|
-
deployments: options.deployments,
|
|
370
|
-
saveDeployments: options.saveDeployments,
|
|
371
|
-
scripts: options.scripts,
|
|
372
|
-
data: configFile?.data,
|
|
373
|
-
tags: typeof options.tags === 'undefined' ? undefined : options.tags.split(','),
|
|
374
|
-
logLevel: options.logLevel,
|
|
375
|
-
askBeforeProceeding: options.askBeforeProceeding,
|
|
376
|
-
reportGasUse: options.reportGasUse,
|
|
377
|
-
accounts: configFile?.accounts,
|
|
378
|
-
signerProtocols: configFile?.signerProtocols,
|
|
379
|
-
extra: options.extra,
|
|
380
|
-
defaultPollingInterval,
|
|
381
|
-
};
|
|
382
|
-
}
|
|
383
|
-
|
|
384
143
|
export async function readConfig<
|
|
385
144
|
NamedAccounts extends UnresolvedUnknownNamedAccounts = UnresolvedUnknownNamedAccounts,
|
|
386
|
-
Data extends UnresolvedNetworkSpecificData = UnresolvedNetworkSpecificData
|
|
387
|
-
|
|
388
|
-
>(options: ConfigOptions<Extra>): Promise<Config<NamedAccounts, Data>> {
|
|
145
|
+
Data extends UnresolvedNetworkSpecificData = UnresolvedNetworkSpecificData
|
|
146
|
+
>(): Promise<UserConfig> {
|
|
389
147
|
type ConfigFile = UserConfig<NamedAccounts, Data>;
|
|
390
148
|
let configFile: ConfigFile | undefined;
|
|
391
149
|
|
|
@@ -424,59 +182,109 @@ export async function readConfig<
|
|
|
424
182
|
configFile = moduleLoaded.config;
|
|
425
183
|
}
|
|
426
184
|
|
|
427
|
-
return
|
|
185
|
+
return configFile || {};
|
|
428
186
|
}
|
|
429
187
|
|
|
430
|
-
export
|
|
188
|
+
export function resolveConfig<
|
|
431
189
|
NamedAccounts extends UnresolvedUnknownNamedAccounts = UnresolvedUnknownNamedAccounts,
|
|
432
|
-
Data extends UnresolvedNetworkSpecificData = UnresolvedNetworkSpecificData
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
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;
|
|
436
214
|
}
|
|
437
215
|
|
|
438
|
-
export function
|
|
216
|
+
export async function readAndResolveConfig<
|
|
439
217
|
NamedAccounts extends UnresolvedUnknownNamedAccounts = UnresolvedUnknownNamedAccounts,
|
|
440
218
|
Data extends UnresolvedNetworkSpecificData = UnresolvedNetworkSpecificData
|
|
441
|
-
>(
|
|
442
|
-
const
|
|
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
|
-
|
|
479
|
-
};
|
|
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;
|
|
480
288
|
|
|
481
289
|
let scripts = ['deploy'];
|
|
482
290
|
if (config.scripts) {
|
|
@@ -487,38 +295,66 @@ export function resolveConfig<
|
|
|
487
295
|
}
|
|
488
296
|
}
|
|
489
297
|
|
|
490
|
-
if (
|
|
491
|
-
if (typeof
|
|
492
|
-
scripts = [
|
|
298
|
+
if (targetConfig?.scripts) {
|
|
299
|
+
if (typeof targetConfig.scripts === 'string') {
|
|
300
|
+
scripts = [targetConfig.scripts];
|
|
493
301
|
} else {
|
|
494
|
-
scripts =
|
|
302
|
+
scripts = targetConfig.scripts;
|
|
495
303
|
}
|
|
496
304
|
}
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
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
|
+
}
|
|
321
|
+
}
|
|
322
|
+
}
|
|
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,
|
|
501
340
|
scripts,
|
|
502
|
-
tags: config.tags || [],
|
|
503
|
-
targetTags: config.targetTags || [],
|
|
504
|
-
saveDeployments: config.saveDeployments,
|
|
505
|
-
accounts: config.accounts || ({} as NamedAccounts),
|
|
506
|
-
data: config.data || ({} as Data),
|
|
507
|
-
signerProtocols: config.signerProtocols || {},
|
|
508
|
-
extra: config.extra || {},
|
|
509
|
-
defaultPollingInterval,
|
|
510
341
|
};
|
|
511
|
-
return resolvedConfig;
|
|
512
342
|
}
|
|
513
343
|
|
|
514
344
|
export async function loadEnvironment<
|
|
515
345
|
NamedAccounts extends UnresolvedUnknownNamedAccounts = UnresolvedUnknownNamedAccounts,
|
|
516
346
|
Data extends UnresolvedNetworkSpecificData = UnresolvedNetworkSpecificData,
|
|
517
347
|
Extra extends Record<string, unknown> = Record<string, unknown>
|
|
518
|
-
>(
|
|
519
|
-
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);
|
|
520
353
|
// console.log(JSON.stringify(resolvedConfig, null, 2));
|
|
521
|
-
const {external, internal} = await createEnvironment(
|
|
354
|
+
const {external, internal} = await createEnvironment<NamedAccounts, Data, UnknownDeployments>(
|
|
355
|
+
userConfig,
|
|
356
|
+
resolvedExecutionParams
|
|
357
|
+
);
|
|
522
358
|
return external;
|
|
523
359
|
}
|
|
524
360
|
|
|
@@ -527,11 +363,35 @@ export async function loadAndExecuteDeployments<
|
|
|
527
363
|
Data extends UnresolvedNetworkSpecificData = UnresolvedNetworkSpecificData,
|
|
528
364
|
ArgumentsType = undefined,
|
|
529
365
|
Extra extends Record<string, unknown> = Record<string, unknown>
|
|
530
|
-
>(
|
|
531
|
-
|
|
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);
|
|
532
374
|
// console.log(JSON.stringify(options, null, 2));
|
|
533
375
|
// console.log(JSON.stringify(resolvedConfig, null, 2));
|
|
534
|
-
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);
|
|
535
395
|
}
|
|
536
396
|
|
|
537
397
|
export async function executeDeployScripts<
|
|
@@ -539,13 +399,14 @@ export async function executeDeployScripts<
|
|
|
539
399
|
Data extends UnresolvedNetworkSpecificData = UnresolvedNetworkSpecificData,
|
|
540
400
|
ArgumentsType = undefined
|
|
541
401
|
>(
|
|
542
|
-
|
|
402
|
+
userConfig: ResolvedUserConfig<NamedAccounts, Data>,
|
|
403
|
+
resolvedExecutionParams: ResolvedExecutionParams,
|
|
543
404
|
args?: ArgumentsType
|
|
544
405
|
): Promise<Environment<NamedAccounts, Data, UnknownDeployments>> {
|
|
545
|
-
setLogLevel(typeof
|
|
406
|
+
setLogLevel(typeof resolvedExecutionParams.logLevel === 'undefined' ? 0 : resolvedExecutionParams.logLevel);
|
|
546
407
|
|
|
547
408
|
let filepaths;
|
|
548
|
-
filepaths = traverseMultipleDirectory(
|
|
409
|
+
filepaths = traverseMultipleDirectory(resolvedExecutionParams.scripts);
|
|
549
410
|
filepaths = filepaths
|
|
550
411
|
.filter((v) => !path.basename(v).startsWith('_'))
|
|
551
412
|
.sort((a: string, b: string) => {
|
|
@@ -600,10 +461,10 @@ export async function executeDeployScripts<
|
|
|
600
461
|
}
|
|
601
462
|
}
|
|
602
463
|
|
|
603
|
-
if (
|
|
464
|
+
if (resolvedExecutionParams.tags !== undefined && resolvedExecutionParams.tags.length > 0) {
|
|
604
465
|
let found = false;
|
|
605
466
|
if (scriptTags !== undefined) {
|
|
606
|
-
for (const tagToFind of
|
|
467
|
+
for (const tagToFind of resolvedExecutionParams.tags) {
|
|
607
468
|
for (const tag of scriptTags) {
|
|
608
469
|
if (tag === tagToFind) {
|
|
609
470
|
scriptFilePaths.push(scriptFilePath);
|
|
@@ -621,7 +482,10 @@ export async function executeDeployScripts<
|
|
|
621
482
|
}
|
|
622
483
|
}
|
|
623
484
|
|
|
624
|
-
const {internal, external} = await createEnvironment(
|
|
485
|
+
const {internal, external} = await createEnvironment<NamedAccounts, Data, UnknownDeployments>(
|
|
486
|
+
userConfig,
|
|
487
|
+
resolvedExecutionParams
|
|
488
|
+
);
|
|
625
489
|
|
|
626
490
|
await internal.recoverTransactionsIfAny();
|
|
627
491
|
|
|
@@ -668,10 +532,10 @@ export async function executeDeployScripts<
|
|
|
668
532
|
recurseDependencies(scriptFilePath);
|
|
669
533
|
}
|
|
670
534
|
|
|
671
|
-
if (
|
|
535
|
+
if (resolvedExecutionParams.askBeforeProceeding) {
|
|
672
536
|
console.log(
|
|
673
|
-
`Network: ${external.
|
|
674
|
-
external.
|
|
537
|
+
`Network: ${external.name} \n \t Chain: ${external.network.chain.name} \n \t Tags: ${Object.keys(
|
|
538
|
+
external.tags
|
|
675
539
|
).join(',')}`
|
|
676
540
|
);
|
|
677
541
|
const gasPriceEstimate = await getRoughGasPriceEstimate(external.network.provider);
|
|
@@ -737,7 +601,7 @@ Do you want to proceed (note that gas price can change for each tx)`,
|
|
|
737
601
|
}
|
|
738
602
|
}
|
|
739
603
|
|
|
740
|
-
if (
|
|
604
|
+
if (resolvedExecutionParams.reportGasUse) {
|
|
741
605
|
const provider = external.network.provider;
|
|
742
606
|
const transactionHashes = provider.transactionHashes;
|
|
743
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;
|