rocketh 0.15.0-testing.9 → 0.15.1

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.
@@ -221,15 +221,27 @@ export async function readAndResolveConfig<
221
221
  return resolveConfig(configFile, overrides);
222
222
  }
223
223
 
224
- export async function getChainIdForTarget(
224
+ export async function getChainIdForEnvironment(
225
225
  config: ResolvedUserConfig,
226
- targetName: string,
226
+ environmentName: string,
227
227
  provider?: EIP1193ProviderWithoutEvents
228
228
  ) {
229
- if (config?.targets?.[targetName]?.chainId) {
230
- return config.targets[targetName].chainId;
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
+ }
231
243
  } else {
232
- const chainFound = getChainByName(targetName);
244
+ const chainFound = getChainByName(environmentName);
233
245
  if (chainFound) {
234
246
  return chainFound.id;
235
247
  } else {
@@ -237,24 +249,24 @@ export async function getChainIdForTarget(
237
249
  const chainIdAsHex = await provider.request({method: 'eth_chainId'});
238
250
  return Number(chainIdAsHex);
239
251
  } else {
240
- throw new Error(`target ${targetName} chain id cannot be found, specify it in the rocketh config`);
252
+ throw new Error(`environment ${environmentName} chain id cannot be found, specify it in the rocketh config`);
241
253
  }
242
254
  }
243
255
  }
244
256
  }
245
257
 
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;
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;
254
266
  }
255
267
  }
256
- const fork = typeof targetProvided !== 'string';
257
- return {name: targetName, fork};
268
+ const fork = typeof environmentProvided !== 'string';
269
+ return {name: environmentName, fork};
258
270
  }
259
271
 
260
272
  export function resolveExecutionParams<Extra extends Record<string, unknown> = Record<string, unknown>>(
@@ -262,19 +274,20 @@ export function resolveExecutionParams<Extra extends Record<string, unknown> = R
262
274
  executionParameters: ExecutionParams<Extra>,
263
275
  chainId: number
264
276
  ): ResolvedExecutionParams<Extra> {
265
- const {name: targetName, fork} = getTargetName(executionParameters);
277
+ const {name: environmentName, fork} = getEnvironmentName(executionParameters);
266
278
 
267
- let chainConfig: ChainConfig = getChainConfig(chainId, config);
279
+ // TODO fork chainId resolution option to keep the network being used
280
+ let chainConfig: ChainConfig = getChainConfig(fork ? 31337 : chainId, config);
268
281
 
269
282
  let chainInfo = chainConfig.info;
270
- const targetConfig = config?.targets?.[targetName];
271
- const actualChainConfig = targetConfig?.overrides
283
+ const environmentConfig = config?.environments?.[environmentName];
284
+ const actualChainConfig = environmentConfig?.overrides
272
285
  ? {
273
286
  ...chainConfig,
274
- ...targetConfig.overrides,
287
+ ...environmentConfig.overrides,
275
288
  properties: {
276
289
  ...chainConfig?.properties,
277
- ...targetConfig.overrides.properties,
290
+ ...environmentConfig.overrides.properties,
278
291
  },
279
292
  }
280
293
  : chainConfig;
@@ -283,23 +296,23 @@ export function resolveExecutionParams<Extra extends Record<string, unknown> = R
283
296
  chainInfo = {...chainInfo, properties: actualChainConfig.properties};
284
297
  }
285
298
 
286
- // let targetTags: string[] = actualChainConfig.tags.concat(targetConfig?.tags); // TODO
287
- const targetTags = actualChainConfig.tags;
299
+ // let environmentTags: string[] = actualChainConfig.tags.concat(environmentConfig?.tags); // TODO
300
+ const environmentTags = actualChainConfig.tags;
288
301
 
289
302
  let scripts = ['deploy'];
290
303
  if (config.scripts) {
291
304
  if (typeof config.scripts === 'string') {
292
305
  scripts = [config.scripts];
293
306
  } else {
294
- scripts = config.scripts;
307
+ scripts = [...config.scripts];
295
308
  }
296
309
  }
297
310
 
298
- if (targetConfig?.scripts) {
299
- if (typeof targetConfig.scripts === 'string') {
300
- scripts = [targetConfig.scripts];
311
+ if (environmentConfig?.scripts) {
312
+ if (typeof environmentConfig.scripts === 'string') {
313
+ scripts = [environmentConfig.scripts];
301
314
  } else {
302
- scripts = targetConfig.scripts;
315
+ scripts = [...environmentConfig.scripts];
303
316
  }
304
317
  }
305
318
 
@@ -312,7 +325,7 @@ export function resolveExecutionParams<Extra extends Record<string, unknown> = R
312
325
  if (!executionParameters.provider) {
313
326
  saveDeployments = true;
314
327
  } else {
315
- if (targetName === 'memory' || targetName === 'hardhat' || targetName === 'default') {
328
+ if (environmentName === 'memory' || environmentName === 'hardhat' || environmentName === 'default') {
316
329
  // networkTags['memory'] = true;
317
330
  saveDeployments = false;
318
331
  } else {
@@ -329,9 +342,9 @@ export function resolveExecutionParams<Extra extends Record<string, unknown> = R
329
342
  reportGasUse: executionParameters.reportGasUse || false,
330
343
  saveDeployments,
331
344
  tags: executionParameters.tags || [],
332
- target: {
333
- name: targetName,
334
- tags: targetTags,
345
+ environment: {
346
+ name: environmentName,
347
+ tags: environmentTags,
335
348
  fork,
336
349
  deterministicDeployment: actualChainConfig.deterministicDeployment,
337
350
  },
@@ -347,8 +360,8 @@ export async function loadEnvironment<
347
360
  Extra extends Record<string, unknown> = Record<string, unknown>
348
361
  >(executionParams: ExecutionParams<Extra>): Promise<Environment<NamedAccounts, Data, UnknownDeployments>> {
349
362
  const userConfig = await readAndResolveConfig<NamedAccounts, Data>(executionParams.config);
350
- const {name: targetName, fork} = getTargetName(executionParams);
351
- const chainId = await getChainIdForTarget(userConfig, targetName, executionParams.provider);
363
+ const {name: environmentName, fork} = getEnvironmentName(executionParams);
364
+ const chainId = await getChainIdForEnvironment(userConfig, environmentName, executionParams.provider);
352
365
  const resolvedExecutionParams = resolveExecutionParams(userConfig, executionParams, chainId);
353
366
  // console.log(JSON.stringify(resolvedConfig, null, 2));
354
367
  const {external, internal} = await createEnvironment<NamedAccounts, Data, UnknownDeployments>(
@@ -368,15 +381,15 @@ export async function loadAndExecuteDeployments<
368
381
  args?: ArgumentsType
369
382
  ): Promise<Environment<NamedAccounts, Data, UnknownDeployments>> {
370
383
  const userConfig = await readAndResolveConfig<NamedAccounts, Data>(executionParams.config);
371
- const {name: targetName, fork} = getTargetName(executionParams);
372
- const chainId = await getChainIdForTarget(userConfig, targetName, executionParams.provider);
384
+ const {name: environmentName, fork} = getEnvironmentName(executionParams);
385
+ const chainId = await getChainIdForEnvironment(userConfig, environmentName, executionParams.provider);
373
386
  const resolvedExecutionParams = resolveExecutionParams(userConfig, executionParams, chainId);
374
387
  // console.log(JSON.stringify(options, null, 2));
375
388
  // console.log(JSON.stringify(resolvedConfig, null, 2));
376
- return executeDeployScripts<NamedAccounts, Data, ArgumentsType>(userConfig, resolvedExecutionParams, args);
389
+ return _executeDeployScripts<NamedAccounts, Data, ArgumentsType>(userConfig, resolvedExecutionParams, args);
377
390
  }
378
391
 
379
- export async function executeDeployScriptsDirectly<
392
+ export async function executeDeployScripts<
380
393
  NamedAccounts extends UnresolvedUnknownNamedAccounts = UnresolvedUnknownNamedAccounts,
381
394
  Data extends UnresolvedNetworkSpecificData = UnresolvedNetworkSpecificData,
382
395
  ArgumentsType = undefined,
@@ -387,14 +400,14 @@ export async function executeDeployScriptsDirectly<
387
400
  args?: ArgumentsType
388
401
  ): Promise<Environment<NamedAccounts, Data, UnknownDeployments>> {
389
402
  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);
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);
393
406
  const resolvedExecutionParams = resolveExecutionParams(resolveduserConfig, executionParams, chainId);
394
- return executeDeployScripts<NamedAccounts, Data, ArgumentsType>(resolveduserConfig, resolvedExecutionParams, args);
407
+ return _executeDeployScripts<NamedAccounts, Data, ArgumentsType>(resolveduserConfig, resolvedExecutionParams, args);
395
408
  }
396
409
 
397
- export async function executeDeployScripts<
410
+ async function _executeDeployScripts<
398
411
  NamedAccounts extends UnresolvedUnknownNamedAccounts = UnresolvedUnknownNamedAccounts,
399
412
  Data extends UnresolvedNetworkSpecificData = UnresolvedNetworkSpecificData,
400
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 target: ${env.name}`);
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
- executeDeployScriptsDirectly,
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: 'zksync' | 'op-stack' | 'celo' | 'default';
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 DeploymentTargetConfig = {
244
- chainId: number;
245
- scripts?: string | string[];
246
- overrides: Omit<ChainUserConfig, 'info'>;
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
- targets?: {[name: string]: DeploymentTargetConfig};
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
- target?: string | {fork: string};
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 target: {
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;