rocketh 0.15.0-testing.8 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +80 -0
- package/dist/cli.js +1 -1
- package/dist/cli.js.map +1 -1
- package/dist/environment/index.d.ts.map +1 -1
- package/dist/environment/index.js +28 -22
- package/dist/environment/index.js.map +1 -1
- package/dist/environment/utils/chains.d.ts +3 -1
- package/dist/environment/utils/chains.d.ts.map +1 -1
- package/dist/environment/utils/chains.js +4 -4
- package/dist/environment/utils/chains.js.map +1 -1
- package/dist/executor/index.d.ts +2 -3
- package/dist/executor/index.d.ts.map +1 -1
- package/dist/executor/index.js +59 -41
- package/dist/executor/index.js.map +1 -1
- package/dist/executor/setup.test.js +1 -1
- package/dist/executor/setup.test.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +36 -33
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/cli.ts +1 -1
- package/src/environment/index.ts +36 -23
- package/src/environment/utils/chains.ts +5 -5
- package/src/executor/index.ts +59 -53
- package/src/executor/setup.test.ts +1 -1
- package/src/index.ts +3 -2
- package/src/types.ts +34 -31
package/src/executor/index.ts
CHANGED
|
@@ -196,6 +196,8 @@ export function resolveConfig<
|
|
|
196
196
|
scripts: configFile?.scripts
|
|
197
197
|
? typeof configFile.scripts === 'string'
|
|
198
198
|
? [configFile.scripts]
|
|
199
|
+
: configFile.scripts.length == 0
|
|
200
|
+
? ['deploy']
|
|
199
201
|
: configFile.scripts
|
|
200
202
|
: ['deploy'],
|
|
201
203
|
};
|
|
@@ -219,15 +221,27 @@ export async function readAndResolveConfig<
|
|
|
219
221
|
return resolveConfig(configFile, overrides);
|
|
220
222
|
}
|
|
221
223
|
|
|
222
|
-
export async function
|
|
224
|
+
export async function getChainIdForEnvironment(
|
|
223
225
|
config: ResolvedUserConfig,
|
|
224
|
-
|
|
226
|
+
environmentName: string,
|
|
225
227
|
provider?: EIP1193ProviderWithoutEvents
|
|
226
228
|
) {
|
|
227
|
-
if (config?.
|
|
228
|
-
|
|
229
|
+
if (config?.environments?.[environmentName]?.chain) {
|
|
230
|
+
const chainAsNumber =
|
|
231
|
+
typeof config.environments[environmentName].chain === 'number'
|
|
232
|
+
? config.environments[environmentName].chain
|
|
233
|
+
: parseInt(config.environments[environmentName].chain);
|
|
234
|
+
if (!isNaN(chainAsNumber)) {
|
|
235
|
+
return chainAsNumber;
|
|
236
|
+
}
|
|
237
|
+
const chainFound = getChainByName(config.environments[environmentName].chain as string);
|
|
238
|
+
if (chainFound) {
|
|
239
|
+
return chainFound.id;
|
|
240
|
+
} else {
|
|
241
|
+
throw new Error(`environment ${environmentName} chain id cannot be found, specify it in the rocketh config`);
|
|
242
|
+
}
|
|
229
243
|
} else {
|
|
230
|
-
const chainFound = getChainByName(
|
|
244
|
+
const chainFound = getChainByName(environmentName);
|
|
231
245
|
if (chainFound) {
|
|
232
246
|
return chainFound.id;
|
|
233
247
|
} else {
|
|
@@ -235,22 +249,24 @@ export async function getChainIdForTarget(
|
|
|
235
249
|
const chainIdAsHex = await provider.request({method: 'eth_chainId'});
|
|
236
250
|
return Number(chainIdAsHex);
|
|
237
251
|
} else {
|
|
238
|
-
throw new Error(`
|
|
252
|
+
throw new Error(`environment ${environmentName} chain id cannot be found, specify it in the rocketh config`);
|
|
239
253
|
}
|
|
240
254
|
}
|
|
241
255
|
}
|
|
242
256
|
}
|
|
243
257
|
|
|
244
|
-
function
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
258
|
+
function getEnvironmentName(executionParams: ExecutionParams): {name: string; fork: boolean} {
|
|
259
|
+
const environmentProvided = executionParams.environment || (executionParams as any).network;
|
|
260
|
+
let environmentName = 'memory';
|
|
261
|
+
if (environmentProvided) {
|
|
262
|
+
if (typeof environmentProvided === 'string') {
|
|
263
|
+
environmentName = environmentProvided;
|
|
264
|
+
} else if ('fork' in environmentProvided) {
|
|
265
|
+
environmentName = environmentProvided.fork;
|
|
251
266
|
}
|
|
252
267
|
}
|
|
253
|
-
|
|
268
|
+
const fork = typeof environmentProvided !== 'string';
|
|
269
|
+
return {name: environmentName, fork};
|
|
254
270
|
}
|
|
255
271
|
|
|
256
272
|
export function resolveExecutionParams<Extra extends Record<string, unknown> = Record<string, unknown>>(
|
|
@@ -258,21 +274,20 @@ export function resolveExecutionParams<Extra extends Record<string, unknown> = R
|
|
|
258
274
|
executionParameters: ExecutionParams<Extra>,
|
|
259
275
|
chainId: number
|
|
260
276
|
): ResolvedExecutionParams<Extra> {
|
|
261
|
-
const
|
|
262
|
-
const fork = typeof targetProvided !== 'string';
|
|
263
|
-
let targetName = getTargetName(targetProvided);
|
|
277
|
+
const {name: environmentName, fork} = getEnvironmentName(executionParameters);
|
|
264
278
|
|
|
265
|
-
|
|
279
|
+
// TODO fork chainId resolution option to keep the network being used
|
|
280
|
+
let chainConfig: ChainConfig = getChainConfig(fork ? 31337 : chainId, config);
|
|
266
281
|
|
|
267
282
|
let chainInfo = chainConfig.info;
|
|
268
|
-
const
|
|
269
|
-
const actualChainConfig =
|
|
283
|
+
const environmentConfig = config?.environments?.[environmentName];
|
|
284
|
+
const actualChainConfig = environmentConfig?.overrides
|
|
270
285
|
? {
|
|
271
286
|
...chainConfig,
|
|
272
|
-
...
|
|
287
|
+
...environmentConfig.overrides,
|
|
273
288
|
properties: {
|
|
274
289
|
...chainConfig?.properties,
|
|
275
|
-
...
|
|
290
|
+
...environmentConfig.overrides.properties,
|
|
276
291
|
},
|
|
277
292
|
}
|
|
278
293
|
: chainConfig;
|
|
@@ -281,23 +296,23 @@ export function resolveExecutionParams<Extra extends Record<string, unknown> = R
|
|
|
281
296
|
chainInfo = {...chainInfo, properties: actualChainConfig.properties};
|
|
282
297
|
}
|
|
283
298
|
|
|
284
|
-
// let
|
|
285
|
-
const
|
|
299
|
+
// let environmentTags: string[] = actualChainConfig.tags.concat(environmentConfig?.tags); // TODO
|
|
300
|
+
const environmentTags = actualChainConfig.tags;
|
|
286
301
|
|
|
287
302
|
let scripts = ['deploy'];
|
|
288
303
|
if (config.scripts) {
|
|
289
304
|
if (typeof config.scripts === 'string') {
|
|
290
305
|
scripts = [config.scripts];
|
|
291
306
|
} else {
|
|
292
|
-
scripts = config.scripts;
|
|
307
|
+
scripts = [...config.scripts];
|
|
293
308
|
}
|
|
294
309
|
}
|
|
295
310
|
|
|
296
|
-
if (
|
|
297
|
-
if (typeof
|
|
298
|
-
scripts = [
|
|
311
|
+
if (environmentConfig?.scripts) {
|
|
312
|
+
if (typeof environmentConfig.scripts === 'string') {
|
|
313
|
+
scripts = [environmentConfig.scripts];
|
|
299
314
|
} else {
|
|
300
|
-
scripts =
|
|
315
|
+
scripts = [...environmentConfig.scripts];
|
|
301
316
|
}
|
|
302
317
|
}
|
|
303
318
|
|
|
@@ -310,7 +325,7 @@ export function resolveExecutionParams<Extra extends Record<string, unknown> = R
|
|
|
310
325
|
if (!executionParameters.provider) {
|
|
311
326
|
saveDeployments = true;
|
|
312
327
|
} else {
|
|
313
|
-
if (
|
|
328
|
+
if (environmentName === 'memory' || environmentName === 'hardhat' || environmentName === 'default') {
|
|
314
329
|
// networkTags['memory'] = true;
|
|
315
330
|
saveDeployments = false;
|
|
316
331
|
} else {
|
|
@@ -327,9 +342,9 @@ export function resolveExecutionParams<Extra extends Record<string, unknown> = R
|
|
|
327
342
|
reportGasUse: executionParameters.reportGasUse || false,
|
|
328
343
|
saveDeployments,
|
|
329
344
|
tags: executionParameters.tags || [],
|
|
330
|
-
|
|
331
|
-
name:
|
|
332
|
-
tags:
|
|
345
|
+
environment: {
|
|
346
|
+
name: environmentName,
|
|
347
|
+
tags: environmentTags,
|
|
333
348
|
fork,
|
|
334
349
|
deterministicDeployment: actualChainConfig.deterministicDeployment,
|
|
335
350
|
},
|
|
@@ -345,11 +360,8 @@ export async function loadEnvironment<
|
|
|
345
360
|
Extra extends Record<string, unknown> = Record<string, unknown>
|
|
346
361
|
>(executionParams: ExecutionParams<Extra>): Promise<Environment<NamedAccounts, Data, UnknownDeployments>> {
|
|
347
362
|
const userConfig = await readAndResolveConfig<NamedAccounts, Data>(executionParams.config);
|
|
348
|
-
const
|
|
349
|
-
|
|
350
|
-
getTargetName(executionParams.target),
|
|
351
|
-
executionParams.provider
|
|
352
|
-
);
|
|
363
|
+
const {name: environmentName, fork} = getEnvironmentName(executionParams);
|
|
364
|
+
const chainId = await getChainIdForEnvironment(userConfig, environmentName, executionParams.provider);
|
|
353
365
|
const resolvedExecutionParams = resolveExecutionParams(userConfig, executionParams, chainId);
|
|
354
366
|
// console.log(JSON.stringify(resolvedConfig, null, 2));
|
|
355
367
|
const {external, internal} = await createEnvironment<NamedAccounts, Data, UnknownDeployments>(
|
|
@@ -369,18 +381,15 @@ export async function loadAndExecuteDeployments<
|
|
|
369
381
|
args?: ArgumentsType
|
|
370
382
|
): Promise<Environment<NamedAccounts, Data, UnknownDeployments>> {
|
|
371
383
|
const userConfig = await readAndResolveConfig<NamedAccounts, Data>(executionParams.config);
|
|
372
|
-
const
|
|
373
|
-
|
|
374
|
-
getTargetName(executionParams.target),
|
|
375
|
-
executionParams.provider
|
|
376
|
-
);
|
|
384
|
+
const {name: environmentName, fork} = getEnvironmentName(executionParams);
|
|
385
|
+
const chainId = await getChainIdForEnvironment(userConfig, environmentName, executionParams.provider);
|
|
377
386
|
const resolvedExecutionParams = resolveExecutionParams(userConfig, executionParams, chainId);
|
|
378
387
|
// console.log(JSON.stringify(options, null, 2));
|
|
379
388
|
// console.log(JSON.stringify(resolvedConfig, null, 2));
|
|
380
|
-
return
|
|
389
|
+
return _executeDeployScripts<NamedAccounts, Data, ArgumentsType>(userConfig, resolvedExecutionParams, args);
|
|
381
390
|
}
|
|
382
391
|
|
|
383
|
-
export async function
|
|
392
|
+
export async function executeDeployScripts<
|
|
384
393
|
NamedAccounts extends UnresolvedUnknownNamedAccounts = UnresolvedUnknownNamedAccounts,
|
|
385
394
|
Data extends UnresolvedNetworkSpecificData = UnresolvedNetworkSpecificData,
|
|
386
395
|
ArgumentsType = undefined,
|
|
@@ -391,17 +400,14 @@ export async function executeDeployScriptsDirectly<
|
|
|
391
400
|
args?: ArgumentsType
|
|
392
401
|
): Promise<Environment<NamedAccounts, Data, UnknownDeployments>> {
|
|
393
402
|
executionParams = executionParams || {};
|
|
394
|
-
const resolveduserConfig = resolveConfig<NamedAccounts, Data>(userConfig);
|
|
395
|
-
const
|
|
396
|
-
|
|
397
|
-
getTargetName(executionParams.target),
|
|
398
|
-
executionParams.provider
|
|
399
|
-
);
|
|
403
|
+
const resolveduserConfig = resolveConfig<NamedAccounts, Data>(userConfig, executionParams.config);
|
|
404
|
+
const {name: environmentName, fork} = getEnvironmentName(executionParams);
|
|
405
|
+
const chainId = await getChainIdForEnvironment(resolveduserConfig, environmentName, executionParams.provider);
|
|
400
406
|
const resolvedExecutionParams = resolveExecutionParams(resolveduserConfig, executionParams, chainId);
|
|
401
|
-
return
|
|
407
|
+
return _executeDeployScripts<NamedAccounts, Data, ArgumentsType>(resolveduserConfig, resolvedExecutionParams, args);
|
|
402
408
|
}
|
|
403
409
|
|
|
404
|
-
|
|
410
|
+
async function _executeDeployScripts<
|
|
405
411
|
NamedAccounts extends UnresolvedUnknownNamedAccounts = UnresolvedUnknownNamedAccounts,
|
|
406
412
|
Data extends UnresolvedNetworkSpecificData = UnresolvedNetworkSpecificData,
|
|
407
413
|
ArgumentsType = undefined
|
|
@@ -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 environment: ${env.name}`);
|
|
138
138
|
const deployment = env.get('MyToken');
|
|
139
139
|
|
|
140
140
|
return true;
|
package/src/index.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
export {
|
|
2
2
|
setup,
|
|
3
3
|
loadAndExecuteDeployments,
|
|
4
|
-
|
|
4
|
+
executeDeployScripts,
|
|
5
5
|
readAndResolveConfig,
|
|
6
6
|
enhanceEnvIfNeeded,
|
|
7
7
|
loadEnvironment,
|
|
8
8
|
} from './executor/index.js';
|
|
9
9
|
|
|
10
|
-
export {getChainConfig} from './environment/utils/chains.js';
|
|
10
|
+
export {getChainConfig, chainByCanonicalName} from './environment/utils/chains.js';
|
|
11
11
|
export * from './types.js';
|
|
12
12
|
export {loadDeployments} from './environment/deployments.js';
|
|
13
13
|
export {mergeArtifacts} from './environment/utils/artifacts.js';
|
|
14
14
|
export {getGasPriceEstimate, getRoughGasPriceEstimate} from './utils/eth.js';
|
|
15
|
+
export {bigIntToStringReplacer} from './utils/json.js';
|
package/src/types.ts
CHANGED
|
@@ -158,7 +158,7 @@ export type ChainInfo = {
|
|
|
158
158
|
/** Flag for test networks */
|
|
159
159
|
testnet?: boolean | undefined;
|
|
160
160
|
|
|
161
|
-
chainType
|
|
161
|
+
chainType?: 'zksync' | 'op-stack' | 'celo' | 'default';
|
|
162
162
|
|
|
163
163
|
genesisHash?: string;
|
|
164
164
|
|
|
@@ -223,31 +223,31 @@ export type DeterministicDeploymentInfo =
|
|
|
223
223
|
};
|
|
224
224
|
|
|
225
225
|
export type ChainUserConfig = {
|
|
226
|
-
rpcUrl?: string;
|
|
227
|
-
tags?: string[];
|
|
228
|
-
deterministicDeployment?: DeterministicDeploymentInfo;
|
|
229
|
-
info?: ChainInfo;
|
|
230
|
-
pollingInterval?: number;
|
|
231
|
-
properties?: Record<string, JSONTypePlusBigInt>;
|
|
226
|
+
readonly rpcUrl?: string;
|
|
227
|
+
readonly tags?: readonly string[];
|
|
228
|
+
readonly deterministicDeployment?: DeterministicDeploymentInfo;
|
|
229
|
+
readonly info?: ChainInfo;
|
|
230
|
+
readonly pollingInterval?: number;
|
|
231
|
+
readonly properties?: Record<string, JSONTypePlusBigInt>;
|
|
232
232
|
};
|
|
233
233
|
|
|
234
234
|
export type ChainConfig = {
|
|
235
|
-
rpcUrl: string;
|
|
236
|
-
tags: string[];
|
|
237
|
-
deterministicDeployment: DeterministicDeploymentInfo;
|
|
238
|
-
info: ChainInfo;
|
|
239
|
-
pollingInterval: number;
|
|
240
|
-
properties: Record<string, JSONTypePlusBigInt>;
|
|
235
|
+
readonly rpcUrl: string;
|
|
236
|
+
readonly tags: readonly string[];
|
|
237
|
+
readonly deterministicDeployment: DeterministicDeploymentInfo;
|
|
238
|
+
readonly info: ChainInfo;
|
|
239
|
+
readonly pollingInterval: number;
|
|
240
|
+
readonly properties: Record<string, JSONTypePlusBigInt>;
|
|
241
241
|
};
|
|
242
242
|
|
|
243
|
-
export type
|
|
244
|
-
|
|
245
|
-
scripts?: string | string[];
|
|
246
|
-
overrides
|
|
243
|
+
export type DeploymentEnvironmentConfig = {
|
|
244
|
+
readonly chain?: string | number;
|
|
245
|
+
readonly scripts?: string | readonly string[];
|
|
246
|
+
readonly overrides?: Omit<ChainUserConfig, 'info'>;
|
|
247
247
|
};
|
|
248
248
|
|
|
249
249
|
export type Chains = {
|
|
250
|
-
[idOrName: number | string]: ChainUserConfig;
|
|
250
|
+
readonly [idOrName: number | string]: ChainUserConfig;
|
|
251
251
|
};
|
|
252
252
|
|
|
253
253
|
export type SignerProtocolFunction = (protocolString: string) => Promise<Signer>;
|
|
@@ -259,27 +259,27 @@ export type UserConfig<
|
|
|
259
259
|
NamedAccounts extends UnresolvedUnknownNamedAccounts = UnresolvedUnknownNamedAccounts,
|
|
260
260
|
Data extends UnresolvedNetworkSpecificData = UnresolvedNetworkSpecificData
|
|
261
261
|
> = {
|
|
262
|
-
|
|
263
|
-
chains?: Chains;
|
|
264
|
-
deployments?: string;
|
|
265
|
-
scripts?: string | string[];
|
|
266
|
-
accounts?: NamedAccounts;
|
|
267
|
-
data?: Data;
|
|
268
|
-
signerProtocols?: Record<string, SignerProtocolFunction>;
|
|
269
|
-
defaultPollingInterval?: number;
|
|
262
|
+
readonly environments?: {readonly [name: string]: DeploymentEnvironmentConfig};
|
|
263
|
+
readonly chains?: Chains;
|
|
264
|
+
readonly deployments?: string;
|
|
265
|
+
readonly scripts?: string | readonly string[];
|
|
266
|
+
readonly accounts?: NamedAccounts;
|
|
267
|
+
readonly data?: Data;
|
|
268
|
+
readonly signerProtocols?: Record<string, SignerProtocolFunction>;
|
|
269
|
+
readonly defaultPollingInterval?: number;
|
|
270
270
|
};
|
|
271
271
|
|
|
272
272
|
export type ResolvedUserConfig<
|
|
273
273
|
NamedAccounts extends UnresolvedUnknownNamedAccounts = UnresolvedUnknownNamedAccounts,
|
|
274
274
|
Data extends UnresolvedNetworkSpecificData = UnresolvedNetworkSpecificData
|
|
275
275
|
> = UserConfig & {
|
|
276
|
-
deployments: string;
|
|
277
|
-
scripts: string[];
|
|
278
|
-
defaultPollingInterval: number;
|
|
276
|
+
readonly deployments: string;
|
|
277
|
+
readonly scripts: readonly string[];
|
|
278
|
+
readonly defaultPollingInterval: number;
|
|
279
279
|
};
|
|
280
280
|
|
|
281
281
|
export type ExecutionParams<Extra extends Record<string, unknown> = Record<string, unknown>> = {
|
|
282
|
-
|
|
282
|
+
environment?: string | {fork: string};
|
|
283
283
|
tags?: string[];
|
|
284
284
|
saveDeployments?: boolean;
|
|
285
285
|
askBeforeProceeding?: boolean;
|
|
@@ -504,7 +504,7 @@ export type ResolvedNamedSigners<T extends UnknownNamedAccounts> = {
|
|
|
504
504
|
export type UnknownDeploymentsAcrossNetworks = Record<string, UnknownDeployments>;
|
|
505
505
|
|
|
506
506
|
export type ResolvedExecutionParams<Extra extends Record<string, unknown> = Record<string, unknown>> = {
|
|
507
|
-
readonly
|
|
507
|
+
readonly environment: {
|
|
508
508
|
readonly name: string;
|
|
509
509
|
readonly tags: readonly string[];
|
|
510
510
|
readonly fork?: boolean;
|
|
@@ -529,6 +529,9 @@ export interface Environment<
|
|
|
529
529
|
Extra extends Record<string, unknown> = Record<string, unknown>
|
|
530
530
|
> {
|
|
531
531
|
readonly name: string;
|
|
532
|
+
readonly context: {
|
|
533
|
+
readonly saveDeployments: boolean;
|
|
534
|
+
};
|
|
532
535
|
readonly tags: {readonly [tag: string]: boolean};
|
|
533
536
|
readonly network: {
|
|
534
537
|
readonly chain: Chain;
|