rocketh 0.9.2 → 0.10.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/dist/cli.cjs CHANGED
@@ -95,9 +95,9 @@ function stringToJSON(str) {
95
95
  // src/environment/deployments.ts
96
96
  var import_node_path2 = __toESM(require("path"), 1);
97
97
  var import_node_fs2 = __toESM(require("fs"), 1);
98
- function loadDeployments(deploymentsPath, subPath, onlyABIAndAddress, expectedChain) {
98
+ function loadDeployments(deploymentsPath, networkName, onlyABIAndAddress, expectedChain) {
99
99
  const deploymentsFound = {};
100
- const deployPath = import_node_path2.default.join(deploymentsPath, subPath);
100
+ const deployPath = import_node_path2.default.join(deploymentsPath, networkName);
101
101
  let filesStats;
102
102
  try {
103
103
  filesStats = traverse(deployPath, void 0, void 0, (name) => !name.startsWith(".") && name !== "solcInputs");
@@ -119,7 +119,7 @@ function loadDeployments(deploymentsPath, subPath, onlyABIAndAddress, expectedCh
119
119
  genesisHash = chainData.genesisHash;
120
120
  } else {
121
121
  throw new Error(
122
- `A '.chain' or '.chainId' file is expected to be present in the deployment folder for network ${subPath}`
122
+ `A '.chain' or '.chainId' file is expected to be present in the deployment folder for network ${networkName}`
123
123
  );
124
124
  }
125
125
  }
@@ -401,8 +401,8 @@ function displayTransaction(transaction) {
401
401
  return `(gasPrice: ${BigInt(transaction.gasPrice).toString()})`;
402
402
  }
403
403
  }
404
- async function createEnvironment(config2, providedContext) {
405
- const provider = "provider" in config2 ? config2.provider : new import_eip_1193_jsonrpc_provider.JSONRPCHTTPProvider(config2.nodeUrl);
404
+ async function createEnvironment(config, providedContext) {
405
+ const provider = "provider" in config.network ? config.network.provider : new import_eip_1193_jsonrpc_provider.JSONRPCHTTPProvider(config.network.nodeUrl);
406
406
  const transport = (0, import_viem.custom)(provider);
407
407
  const viemClient = (0, import_viem.createPublicClient)({ transport });
408
408
  const chainId = (await viemClient.getChainId()).toString();
@@ -414,23 +414,29 @@ async function createEnvironment(config2, providedContext) {
414
414
  }
415
415
  let networkName;
416
416
  let saveDeployments;
417
- let tags = {};
418
- if ("nodeUrl" in config2) {
419
- networkName = config2.networkName;
417
+ let networkTags = {};
418
+ for (const networkTag of config.network.tags) {
419
+ networkTags[networkTag] = true;
420
+ }
421
+ if ("nodeUrl" in config) {
422
+ networkName = config.network.name;
420
423
  saveDeployments = true;
421
424
  } else {
422
- if (config2.networkName) {
423
- networkName = config2.networkName;
425
+ if (config.network.name) {
426
+ networkName = config.network.name;
424
427
  } else {
425
428
  networkName = "memory";
426
429
  }
427
430
  if (networkName === "memory" || networkName === "hardhat") {
428
- tags["memory"] = true;
431
+ networkTags["memory"] = true;
429
432
  saveDeployments = false;
430
433
  } else {
431
434
  saveDeployments = true;
432
435
  }
433
436
  }
437
+ if (config.saveDeployments !== void 0) {
438
+ saveDeployments = config.saveDeployments;
439
+ }
434
440
  const resolvedAccounts = {};
435
441
  const accountCache = {};
436
442
  async function getAccount(name, accounts, accountDef) {
@@ -510,15 +516,21 @@ async function createEnvironment(config2, providedContext) {
510
516
  artifacts: providedContext.artifacts,
511
517
  network: {
512
518
  name: networkName,
519
+ fork: config.network.fork,
513
520
  saveDeployments,
514
- tags
521
+ tags: networkTags
515
522
  }
516
523
  };
517
- const { deployments } = loadDeployments(config2.deployments, context.network.name, false, {
518
- chainId,
519
- genesisHash,
520
- deleteDeploymentsIfDifferentGenesisHash: true
521
- });
524
+ const { deployments } = loadDeployments(
525
+ config.deployments,
526
+ context.network.name,
527
+ false,
528
+ context.network.fork ? void 0 : {
529
+ chainId,
530
+ genesisHash,
531
+ deleteDeploymentsIfDifferentGenesisHash: true
532
+ }
533
+ );
522
534
  const namedAccounts = {};
523
535
  const namedSigners = {};
524
536
  const addressSigners = {};
@@ -530,7 +542,7 @@ async function createEnvironment(config2, providedContext) {
530
542
  namedSigners[name] = namedSigner;
531
543
  }
532
544
  const perliminaryEnvironment = {
533
- config: config2,
545
+ config,
534
546
  deployments,
535
547
  accounts: namedAccounts,
536
548
  signers: namedSigners,
@@ -544,7 +556,7 @@ async function createEnvironment(config2, providedContext) {
544
556
  }
545
557
  };
546
558
  function ensureDeploymentFolder() {
547
- const folderPath = import_node_path3.default.join(config2.deployments, context.network.name);
559
+ const folderPath = import_node_path3.default.join(config.deployments, context.network.name);
548
560
  import_node_fs3.default.mkdirSync(folderPath, { recursive: true });
549
561
  const chainFilepath = import_node_path3.default.join(folderPath, ".chain");
550
562
  if (!import_node_fs3.default.existsSync(chainFilepath)) {
@@ -874,24 +886,55 @@ async function createEnvironment(config2, providedContext) {
874
886
  if (!process.env["ROCKETH_SKIP_ESBUILD"]) {
875
887
  require("esbuild-register/dist/node").register();
876
888
  }
877
- function readConfig(options2, extra) {
889
+ function readConfig(options2) {
878
890
  let configFile;
879
891
  try {
880
892
  const configString = import_node_fs4.default.readFileSync("./rocketh.json", "utf-8");
881
893
  configFile = JSON.parse(configString);
882
894
  } catch {
883
895
  }
884
- let nodeUrl;
896
+ if (configFile) {
897
+ if (!options2.deployments && configFile.deployments) {
898
+ options2.deployments = configFile.deployments;
899
+ }
900
+ if (!options2.scripts && configFile.scripts) {
901
+ options2.scripts = configFile.scripts;
902
+ }
903
+ }
885
904
  const fromEnv = process.env["ETH_NODE_URI_" + options2.network];
886
- if (typeof fromEnv === "string") {
887
- nodeUrl = fromEnv;
888
- } else {
889
- if (configFile) {
890
- const network = configFile.networks && configFile.networks[options2.network];
891
- if (network) {
892
- nodeUrl = network.rpcUrl;
905
+ const fork = typeof options2.network !== "string";
906
+ let networkName = "memory";
907
+ if (options2.network) {
908
+ if (typeof options2.network === "string") {
909
+ networkName = options2.network;
910
+ } else if ("fork" in options2.network) {
911
+ networkName = options2.network.fork;
912
+ }
913
+ }
914
+ let networkTags = configFile?.networks && configFile?.networks[networkName]?.tags || [];
915
+ if (!options2.provider) {
916
+ let nodeUrl;
917
+ if (typeof fromEnv === "string") {
918
+ nodeUrl = fromEnv;
919
+ } else {
920
+ if (configFile) {
921
+ const network = configFile.networks && configFile.networks[networkName];
922
+ if (network && network.rpcUrl) {
923
+ nodeUrl = network.rpcUrl;
924
+ } else {
925
+ if (options2?.ignoreMissingRPC) {
926
+ nodeUrl = "";
927
+ } else {
928
+ if (options2.network === "localhost") {
929
+ nodeUrl = "http://127.0.0.1:8545";
930
+ } else {
931
+ logger.error(`network "${options2.network}" is not configured. Please add it to the rocketh.json file`);
932
+ process.exit(1);
933
+ }
934
+ }
935
+ }
893
936
  } else {
894
- if (extra?.ignoreMissingRPC) {
937
+ if (options2?.ignoreMissingRPC) {
895
938
  nodeUrl = "";
896
939
  } else {
897
940
  if (options2.network === "localhost") {
@@ -902,45 +945,60 @@ function readConfig(options2, extra) {
902
945
  }
903
946
  }
904
947
  }
905
- } else {
906
- if (extra?.ignoreMissingRPC) {
907
- nodeUrl = "";
908
- } else {
909
- if (options2.network === "localhost") {
910
- nodeUrl = "http://127.0.0.1:8545";
911
- } else {
912
- logger.error(`network "${options2.network}" is not configured. Please add it to the rocketh.json file`);
913
- process.exit(1);
914
- }
915
- }
916
948
  }
949
+ return {
950
+ network: {
951
+ nodeUrl,
952
+ name: networkName,
953
+ tags: networkTags,
954
+ fork
955
+ },
956
+ deployments: options2.deployments,
957
+ saveDeployments: options2.saveDeployments,
958
+ scripts: options2.scripts,
959
+ tags: typeof options2.tags === "undefined" ? void 0 : options2.tags.split(","),
960
+ logLevel: options2.logLevel
961
+ };
962
+ } else {
963
+ return {
964
+ network: {
965
+ provider: options2.provider,
966
+ name: networkName,
967
+ tags: networkTags,
968
+ fork
969
+ },
970
+ deployments: options2.deployments,
971
+ saveDeployments: options2.saveDeployments,
972
+ scripts: options2.scripts,
973
+ tags: typeof options2.tags === "undefined" ? void 0 : options2.tags.split(","),
974
+ logLevel: options2.logLevel
975
+ };
917
976
  }
918
- return {
919
- nodeUrl,
920
- networkName: options2.network,
921
- deployments: options2.deployments,
922
- scripts: options2.scripts,
923
- tags: typeof options2.tags === "undefined" ? void 0 : options2.tags.split(",")
924
- };
925
977
  }
926
- function resolveConfig(config2) {
978
+ function readAndResolveConfig(options2) {
979
+ return resolveConfig(readConfig(options2));
980
+ }
981
+ function resolveConfig(config) {
927
982
  const resolvedConfig = {
928
- ...config2,
929
- networkName: config2.networkName || "memory",
930
- deployments: config2.deployments || "deployments",
931
- scripts: config2.scripts || "deploy",
932
- tags: config2.tags || []
983
+ ...config,
984
+ network: config.network,
985
+ // TODO default to || {name: 'memory'....}
986
+ deployments: config.deployments || "deployments",
987
+ scripts: config.scripts || "deploy",
988
+ tags: config.tags || [],
989
+ networkTags: config.networkTags || [],
990
+ saveDeployments: config.saveDeployments
933
991
  };
934
992
  return resolvedConfig;
935
993
  }
936
- async function loadAndExecuteDeployments(config2, args) {
937
- const resolvedConfig = resolveConfig(config2);
994
+ async function loadAndExecuteDeployments(options2, args) {
995
+ const resolvedConfig = readAndResolveConfig(options2);
938
996
  return executeDeployScripts(resolvedConfig, args);
939
997
  }
940
- async function executeDeployScripts(config2, args) {
941
- setLogLevel(typeof config2.logLevel === "undefined" ? 0 : config2.logLevel);
998
+ async function executeDeployScripts(config, args) {
999
+ setLogLevel(typeof config.logLevel === "undefined" ? 0 : config.logLevel);
942
1000
  let filepaths;
943
- filepaths = traverseMultipleDirectory([config2.scripts]);
1001
+ filepaths = traverseMultipleDirectory([config.scripts]);
944
1002
  filepaths = filepaths.filter((v) => !import_node_path4.default.basename(v).startsWith("_")).sort((a, b) => {
945
1003
  if (a < b) {
946
1004
  return -1;
@@ -992,10 +1050,10 @@ async function executeDeployScripts(config2, args) {
992
1050
  bag.push(scriptFilePath);
993
1051
  }
994
1052
  }
995
- if (config2.tags !== void 0 && config2.tags.length > 0) {
1053
+ if (config.tags !== void 0 && config.tags.length > 0) {
996
1054
  let found = false;
997
1055
  if (scriptTags !== void 0) {
998
- for (const tagToFind of config2.tags) {
1056
+ for (const tagToFind of config.tags) {
999
1057
  for (const tag of scriptTags) {
1000
1058
  if (tag === tagToFind) {
1001
1059
  scriptFilePaths.push(scriptFilePath);
@@ -1015,7 +1073,7 @@ async function executeDeployScripts(config2, args) {
1015
1073
  if (!providedContext) {
1016
1074
  throw new Error(`no context loaded`);
1017
1075
  }
1018
- const { internal, external } = await createEnvironment(config2, providedContext);
1076
+ const { internal, external } = await createEnvironment(config, providedContext);
1019
1077
  await internal.recoverTransactionsIfAny();
1020
1078
  const scriptsRegisteredToRun = {};
1021
1079
  const scriptsToRun = [];
@@ -1079,7 +1137,7 @@ async function executeDeployScripts(config2, args) {
1079
1137
  throw e;
1080
1138
  }
1081
1139
  if (result && typeof result === "boolean") {
1082
- const deploymentFolderPath = config2.deployments;
1140
+ const deploymentFolderPath = config.deployments;
1083
1141
  }
1084
1142
  }
1085
1143
  }
@@ -1092,7 +1150,7 @@ var import_commander = require("commander");
1092
1150
  // package.json
1093
1151
  var package_default = {
1094
1152
  name: "rocketh",
1095
- version: "0.9.1",
1153
+ version: "0.10.0",
1096
1154
  description: "deploy smart contract on ethereum-compatible networks",
1097
1155
  publishConfig: {
1098
1156
  access: "public"
@@ -1142,6 +1200,5 @@ var commandName = package_default.name;
1142
1200
  var program = new import_commander.Command();
1143
1201
  program.name(commandName).version(package_default.version).usage(`${commandName}`).description("execute deploy scripts and store the deployments").option("-s, --scripts <value>", "path the folder containing the deploy scripts to execute").option("-t, --tags <value>", "comma separated list of tags to execute").option("-d, --deployments <value>", "folder where deployments are saved").requiredOption("-n, --network <value>", "network context to use").parse(process.argv);
1144
1202
  var options = program.opts();
1145
- var config = readConfig(options);
1146
- loadAndExecuteDeployments({ ...config, logLevel: 1 });
1203
+ loadAndExecuteDeployments({ ...options, logLevel: 1 });
1147
1204
  //# sourceMappingURL=cli.cjs.map