rocketh 0.15.0-testing.1 → 0.15.0-testing.11
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 +154 -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 +205 -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,110 @@ 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
|
+
// TODO fork chainId resolution option to keep the network being used
|
|
268
|
+
let chainConfig: ChainConfig = getChainConfig(fork ? 31337 : chainId, config);
|
|
269
|
+
|
|
270
|
+
let chainInfo = chainConfig.info;
|
|
271
|
+
const targetConfig = config?.targets?.[targetName];
|
|
272
|
+
const actualChainConfig = targetConfig?.overrides
|
|
273
|
+
? {
|
|
274
|
+
...chainConfig,
|
|
275
|
+
...targetConfig.overrides,
|
|
276
|
+
properties: {
|
|
277
|
+
...chainConfig?.properties,
|
|
278
|
+
...targetConfig.overrides.properties,
|
|
279
|
+
},
|
|
280
|
+
}
|
|
281
|
+
: chainConfig;
|
|
282
|
+
|
|
283
|
+
if (actualChainConfig?.properties) {
|
|
284
|
+
chainInfo = {...chainInfo, properties: actualChainConfig.properties};
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
// let targetTags: string[] = actualChainConfig.tags.concat(targetConfig?.tags); // TODO
|
|
288
|
+
const targetTags = actualChainConfig.tags;
|
|
480
289
|
|
|
481
290
|
let scripts = ['deploy'];
|
|
482
291
|
if (config.scripts) {
|
|
@@ -487,38 +296,66 @@ export function resolveConfig<
|
|
|
487
296
|
}
|
|
488
297
|
}
|
|
489
298
|
|
|
490
|
-
if (
|
|
491
|
-
if (typeof
|
|
492
|
-
scripts = [
|
|
299
|
+
if (targetConfig?.scripts) {
|
|
300
|
+
if (typeof targetConfig.scripts === 'string') {
|
|
301
|
+
scripts = [targetConfig.scripts];
|
|
493
302
|
} else {
|
|
494
|
-
scripts =
|
|
303
|
+
scripts = targetConfig.scripts;
|
|
495
304
|
}
|
|
496
305
|
}
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
306
|
+
|
|
307
|
+
const provider =
|
|
308
|
+
executionParameters.provider || (new JSONRPCHTTPProvider(actualChainConfig.rpcUrl) as EIP1193ProviderWithoutEvents);
|
|
309
|
+
|
|
310
|
+
let saveDeployments = executionParameters.saveDeployments;
|
|
311
|
+
|
|
312
|
+
if (saveDeployments === undefined) {
|
|
313
|
+
if (!executionParameters.provider) {
|
|
314
|
+
saveDeployments = true;
|
|
315
|
+
} else {
|
|
316
|
+
if (targetName === 'memory' || targetName === 'hardhat' || targetName === 'default') {
|
|
317
|
+
// networkTags['memory'] = true;
|
|
318
|
+
saveDeployments = false;
|
|
319
|
+
} else {
|
|
320
|
+
saveDeployments = true;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
return {
|
|
326
|
+
askBeforeProceeding: executionParameters.askBeforeProceeding || false,
|
|
327
|
+
chain: chainInfo,
|
|
328
|
+
logLevel: executionParameters.logLevel || 0, // TODO
|
|
329
|
+
pollingInterval: actualChainConfig.pollingInterval,
|
|
330
|
+
reportGasUse: executionParameters.reportGasUse || false,
|
|
331
|
+
saveDeployments,
|
|
332
|
+
tags: executionParameters.tags || [],
|
|
333
|
+
target: {
|
|
334
|
+
name: targetName,
|
|
335
|
+
tags: targetTags,
|
|
336
|
+
fork,
|
|
337
|
+
deterministicDeployment: actualChainConfig.deterministicDeployment,
|
|
338
|
+
},
|
|
339
|
+
extra: executionParameters.extra,
|
|
340
|
+
provider,
|
|
501
341
|
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
342
|
};
|
|
511
|
-
return resolvedConfig;
|
|
512
343
|
}
|
|
513
344
|
|
|
514
345
|
export async function loadEnvironment<
|
|
515
346
|
NamedAccounts extends UnresolvedUnknownNamedAccounts = UnresolvedUnknownNamedAccounts,
|
|
516
347
|
Data extends UnresolvedNetworkSpecificData = UnresolvedNetworkSpecificData,
|
|
517
348
|
Extra extends Record<string, unknown> = Record<string, unknown>
|
|
518
|
-
>(
|
|
519
|
-
const
|
|
349
|
+
>(executionParams: ExecutionParams<Extra>): Promise<Environment<NamedAccounts, Data, UnknownDeployments>> {
|
|
350
|
+
const userConfig = await readAndResolveConfig<NamedAccounts, Data>(executionParams.config);
|
|
351
|
+
const {name: targetName, fork} = getTargetName(executionParams);
|
|
352
|
+
const chainId = await getChainIdForTarget(userConfig, targetName, executionParams.provider);
|
|
353
|
+
const resolvedExecutionParams = resolveExecutionParams(userConfig, executionParams, chainId);
|
|
520
354
|
// console.log(JSON.stringify(resolvedConfig, null, 2));
|
|
521
|
-
const {external, internal} = await createEnvironment(
|
|
355
|
+
const {external, internal} = await createEnvironment<NamedAccounts, Data, UnknownDeployments>(
|
|
356
|
+
userConfig,
|
|
357
|
+
resolvedExecutionParams
|
|
358
|
+
);
|
|
522
359
|
return external;
|
|
523
360
|
}
|
|
524
361
|
|
|
@@ -527,11 +364,35 @@ export async function loadAndExecuteDeployments<
|
|
|
527
364
|
Data extends UnresolvedNetworkSpecificData = UnresolvedNetworkSpecificData,
|
|
528
365
|
ArgumentsType = undefined,
|
|
529
366
|
Extra extends Record<string, unknown> = Record<string, unknown>
|
|
530
|
-
>(
|
|
531
|
-
|
|
367
|
+
>(
|
|
368
|
+
executionParams: ExecutionParams<Extra>,
|
|
369
|
+
args?: ArgumentsType
|
|
370
|
+
): Promise<Environment<NamedAccounts, Data, UnknownDeployments>> {
|
|
371
|
+
const userConfig = await readAndResolveConfig<NamedAccounts, Data>(executionParams.config);
|
|
372
|
+
const {name: targetName, fork} = getTargetName(executionParams);
|
|
373
|
+
const chainId = await getChainIdForTarget(userConfig, targetName, executionParams.provider);
|
|
374
|
+
const resolvedExecutionParams = resolveExecutionParams(userConfig, executionParams, chainId);
|
|
532
375
|
// console.log(JSON.stringify(options, null, 2));
|
|
533
376
|
// console.log(JSON.stringify(resolvedConfig, null, 2));
|
|
534
|
-
return executeDeployScripts<NamedAccounts, Data, ArgumentsType>(
|
|
377
|
+
return executeDeployScripts<NamedAccounts, Data, ArgumentsType>(userConfig, resolvedExecutionParams, args);
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
export async function executeDeployScriptsDirectly<
|
|
381
|
+
NamedAccounts extends UnresolvedUnknownNamedAccounts = UnresolvedUnknownNamedAccounts,
|
|
382
|
+
Data extends UnresolvedNetworkSpecificData = UnresolvedNetworkSpecificData,
|
|
383
|
+
ArgumentsType = undefined,
|
|
384
|
+
Extra extends Record<string, unknown> = Record<string, unknown>
|
|
385
|
+
>(
|
|
386
|
+
userConfig: UserConfig,
|
|
387
|
+
executionParams?: ExecutionParams<Extra>,
|
|
388
|
+
args?: ArgumentsType
|
|
389
|
+
): Promise<Environment<NamedAccounts, Data, UnknownDeployments>> {
|
|
390
|
+
executionParams = executionParams || {};
|
|
391
|
+
const resolveduserConfig = resolveConfig<NamedAccounts, Data>(userConfig);
|
|
392
|
+
const {name: targetName, fork} = getTargetName(executionParams);
|
|
393
|
+
const chainId = await getChainIdForTarget(resolveduserConfig, targetName, executionParams.provider);
|
|
394
|
+
const resolvedExecutionParams = resolveExecutionParams(resolveduserConfig, executionParams, chainId);
|
|
395
|
+
return executeDeployScripts<NamedAccounts, Data, ArgumentsType>(resolveduserConfig, resolvedExecutionParams, args);
|
|
535
396
|
}
|
|
536
397
|
|
|
537
398
|
export async function executeDeployScripts<
|
|
@@ -539,13 +400,14 @@ export async function executeDeployScripts<
|
|
|
539
400
|
Data extends UnresolvedNetworkSpecificData = UnresolvedNetworkSpecificData,
|
|
540
401
|
ArgumentsType = undefined
|
|
541
402
|
>(
|
|
542
|
-
|
|
403
|
+
userConfig: ResolvedUserConfig<NamedAccounts, Data>,
|
|
404
|
+
resolvedExecutionParams: ResolvedExecutionParams,
|
|
543
405
|
args?: ArgumentsType
|
|
544
406
|
): Promise<Environment<NamedAccounts, Data, UnknownDeployments>> {
|
|
545
|
-
setLogLevel(typeof
|
|
407
|
+
setLogLevel(typeof resolvedExecutionParams.logLevel === 'undefined' ? 0 : resolvedExecutionParams.logLevel);
|
|
546
408
|
|
|
547
409
|
let filepaths;
|
|
548
|
-
filepaths = traverseMultipleDirectory(
|
|
410
|
+
filepaths = traverseMultipleDirectory(resolvedExecutionParams.scripts);
|
|
549
411
|
filepaths = filepaths
|
|
550
412
|
.filter((v) => !path.basename(v).startsWith('_'))
|
|
551
413
|
.sort((a: string, b: string) => {
|
|
@@ -600,10 +462,10 @@ export async function executeDeployScripts<
|
|
|
600
462
|
}
|
|
601
463
|
}
|
|
602
464
|
|
|
603
|
-
if (
|
|
465
|
+
if (resolvedExecutionParams.tags !== undefined && resolvedExecutionParams.tags.length > 0) {
|
|
604
466
|
let found = false;
|
|
605
467
|
if (scriptTags !== undefined) {
|
|
606
|
-
for (const tagToFind of
|
|
468
|
+
for (const tagToFind of resolvedExecutionParams.tags) {
|
|
607
469
|
for (const tag of scriptTags) {
|
|
608
470
|
if (tag === tagToFind) {
|
|
609
471
|
scriptFilePaths.push(scriptFilePath);
|
|
@@ -621,7 +483,10 @@ export async function executeDeployScripts<
|
|
|
621
483
|
}
|
|
622
484
|
}
|
|
623
485
|
|
|
624
|
-
const {internal, external} = await createEnvironment(
|
|
486
|
+
const {internal, external} = await createEnvironment<NamedAccounts, Data, UnknownDeployments>(
|
|
487
|
+
userConfig,
|
|
488
|
+
resolvedExecutionParams
|
|
489
|
+
);
|
|
625
490
|
|
|
626
491
|
await internal.recoverTransactionsIfAny();
|
|
627
492
|
|
|
@@ -668,10 +533,10 @@ export async function executeDeployScripts<
|
|
|
668
533
|
recurseDependencies(scriptFilePath);
|
|
669
534
|
}
|
|
670
535
|
|
|
671
|
-
if (
|
|
536
|
+
if (resolvedExecutionParams.askBeforeProceeding) {
|
|
672
537
|
console.log(
|
|
673
|
-
`Network: ${external.
|
|
674
|
-
external.
|
|
538
|
+
`Network: ${external.name} \n \t Chain: ${external.network.chain.name} \n \t Tags: ${Object.keys(
|
|
539
|
+
external.tags
|
|
675
540
|
).join(',')}`
|
|
676
541
|
);
|
|
677
542
|
const gasPriceEstimate = await getRoughGasPriceEstimate(external.network.provider);
|
|
@@ -737,7 +602,7 @@ Do you want to proceed (note that gas price can change for each tx)`,
|
|
|
737
602
|
}
|
|
738
603
|
}
|
|
739
604
|
|
|
740
|
-
if (
|
|
605
|
+
if (resolvedExecutionParams.reportGasUse) {
|
|
741
606
|
const provider = external.network.provider;
|
|
742
607
|
const transactionHashes = provider.transactionHashes;
|
|
743
608
|
|
|
@@ -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;
|