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