@latticexyz/cli 2.0.0-alpha.94 → 2.0.0-foundry-js-c7b0289b

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.
Files changed (139) hide show
  1. package/dist/chunk-22IIKR4S.js +4 -0
  2. package/dist/chunk-22IIKR4S.js.map +1 -0
  3. package/dist/commands-UYAATBY6.js +27 -0
  4. package/dist/commands-UYAATBY6.js.map +1 -0
  5. package/dist/errors-XGN6V2Y3.js +2 -0
  6. package/dist/errors-XGN6V2Y3.js.map +1 -0
  7. package/dist/index.js +1 -0
  8. package/dist/index.js.map +1 -0
  9. package/dist/mud.js +2 -8340
  10. package/dist/mud.js.map +1 -0
  11. package/package.json +54 -46
  12. package/src/commands/deploy.ts +26 -0
  13. package/src/commands/dev-contracts.ts +114 -0
  14. package/src/commands/devnode.ts +7 -2
  15. package/src/commands/faucet.ts +1 -1
  16. package/src/commands/index.ts +19 -14
  17. package/src/commands/set-version.ts +103 -81
  18. package/src/commands/tablegen.ts +7 -5
  19. package/src/commands/test.ts +65 -0
  20. package/src/commands/trace.ts +118 -0
  21. package/src/commands/worldgen.ts +29 -28
  22. package/src/common.ts +1 -0
  23. package/src/debug.ts +3 -0
  24. package/src/deploy/assertNamespaceOwner.ts +42 -0
  25. package/src/deploy/common.ts +76 -0
  26. package/src/deploy/configToTables.ts +68 -0
  27. package/src/deploy/create2/README.md +9 -0
  28. package/src/deploy/create2/deployment.json +7 -0
  29. package/src/deploy/debug.ts +3 -0
  30. package/src/deploy/deploy.ts +108 -0
  31. package/src/deploy/deployWorld.ts +33 -0
  32. package/src/deploy/ensureContract.ts +61 -0
  33. package/src/deploy/ensureContractsDeployed.ts +25 -0
  34. package/src/deploy/ensureDeployer.ts +36 -0
  35. package/src/deploy/ensureFunctions.ts +86 -0
  36. package/src/deploy/ensureModules.ts +73 -0
  37. package/src/deploy/ensureSystems.ts +162 -0
  38. package/src/deploy/ensureTables.ts +65 -0
  39. package/src/deploy/ensureWorldFactory.ts +47 -0
  40. package/src/deploy/getFunctions.ts +58 -0
  41. package/src/deploy/getResourceAccess.ts +51 -0
  42. package/src/deploy/getResourceIds.ts +31 -0
  43. package/src/deploy/getSystems.ts +48 -0
  44. package/src/deploy/getTableValue.ts +30 -0
  45. package/src/deploy/getTables.ts +59 -0
  46. package/src/deploy/getWorldDeploy.ts +39 -0
  47. package/src/deploy/logsToWorldDeploy.ts +49 -0
  48. package/src/deploy/resolveConfig.ts +151 -0
  49. package/src/deploy/resourceLabel.ts +3 -0
  50. package/src/index.ts +1 -1
  51. package/src/modules.d.ts +11 -0
  52. package/src/mud.ts +38 -23
  53. package/src/mudPackages.ts +24 -0
  54. package/src/runDeploy.ts +128 -0
  55. package/src/utils/errors.ts +1 -1
  56. package/src/utils/getExistingContracts.ts +12 -0
  57. package/src/utils/modules/constants.ts +26 -0
  58. package/src/utils/printMUD.ts +14 -0
  59. package/src/utils/utils/getContractData.ts +32 -0
  60. package/src/utils/utils/postDeploy.ts +25 -0
  61. package/dist/chunk-6V563IAZ.js +0 -283
  62. package/dist/chunk-FPG73MVN.js +0 -71
  63. package/dist/chunk-L4YLJHLJ.js +0 -30
  64. package/dist/chunk-SKNB74MT.js +0 -726
  65. package/dist/chunk-T2YHSEJD.js +0 -3842
  66. package/dist/chunk-VQTZJIFF.js +0 -353
  67. package/dist/chunk-WZFXLDPK.js +0 -761
  68. package/dist/chunk-YL4GJLLL.js +0 -26139
  69. package/dist/index.d.ts +0 -2
  70. package/dist/mud.d.ts +0 -1
  71. package/dist/mud2.d.ts +0 -1
  72. package/dist/mud2.js +0 -25
  73. package/dist/render-solidity/index.d.ts +0 -171
  74. package/dist/render-solidity/index.js +0 -49
  75. package/dist/render-ts/index.d.ts +0 -26
  76. package/dist/render-ts/index.js +0 -14
  77. package/dist/utils/deprecated/index.d.ts +0 -76
  78. package/dist/utils/deprecated/index.js +0 -36
  79. package/dist/utils/index.d.ts +0 -88
  80. package/dist/utils/index.js +0 -39
  81. package/src/commands/deploy-v2.ts +0 -112
  82. package/src/commands/deprecated/bulkupload.ts +0 -50
  83. package/src/commands/deprecated/call-system.ts +0 -70
  84. package/src/commands/deprecated/codegen-libdeploy.ts +0 -29
  85. package/src/commands/deprecated/deploy-contracts.ts +0 -120
  86. package/src/commands/deprecated/index.ts +0 -22
  87. package/src/commands/deprecated/system-types.ts +0 -29
  88. package/src/commands/deprecated/test.ts +0 -53
  89. package/src/commands/deprecated/trace.ts +0 -81
  90. package/src/commands/deprecated/types.ts +0 -33
  91. package/src/commands/gas-report.ts +0 -219
  92. package/src/commands/test-v2.ts +0 -71
  93. package/src/commands/tsgen.ts +0 -33
  94. package/src/contracts/BulkUpload.sol +0 -174
  95. package/src/contracts/Deploy.sol +0 -23
  96. package/src/contracts/LibDeploy.ejs +0 -121
  97. package/src/contracts/LibDeploy.sol +0 -23
  98. package/src/contracts/LibDeployStub.sol +0 -23
  99. package/src/mud2.ts +0 -29
  100. package/src/render-solidity/common.ts +0 -138
  101. package/src/render-solidity/field.ts +0 -160
  102. package/src/render-solidity/index.ts +0 -10
  103. package/src/render-solidity/record.ts +0 -158
  104. package/src/render-solidity/renderSystemInterface.ts +0 -31
  105. package/src/render-solidity/renderTable.ts +0 -164
  106. package/src/render-solidity/renderTableIndex.ts +0 -15
  107. package/src/render-solidity/renderTypeHelpers.ts +0 -99
  108. package/src/render-solidity/renderTypes.ts +0 -19
  109. package/src/render-solidity/renderTypesFromConfig.ts +0 -13
  110. package/src/render-solidity/renderWorld.ts +0 -24
  111. package/src/render-solidity/tableOptions.ts +0 -107
  112. package/src/render-solidity/tablegen.ts +0 -35
  113. package/src/render-solidity/types.ts +0 -111
  114. package/src/render-solidity/userType.ts +0 -131
  115. package/src/render-solidity/worldgen.ts +0 -59
  116. package/src/render-ts/index.ts +0 -5
  117. package/src/render-ts/recsV1TableOptions.ts +0 -39
  118. package/src/render-ts/renderRecsV1Tables.ts +0 -31
  119. package/src/render-ts/schemaTypesToRecsTypeStrings.ts +0 -202
  120. package/src/render-ts/tsgen.ts +0 -12
  121. package/src/render-ts/types.ts +0 -13
  122. package/src/utils/contractToInterface.ts +0 -132
  123. package/src/utils/deploy-v2.ts +0 -518
  124. package/src/utils/deprecated/build.ts +0 -55
  125. package/src/utils/deprecated/codegen.ts +0 -42
  126. package/src/utils/deprecated/constants.ts +0 -2
  127. package/src/utils/deprecated/deploy.ts +0 -111
  128. package/src/utils/deprecated/exec.ts +0 -18
  129. package/src/utils/deprecated/findLog.ts +0 -8
  130. package/src/utils/deprecated/hsr.ts +0 -71
  131. package/src/utils/deprecated/ids.ts +0 -14
  132. package/src/utils/deprecated/index.ts +0 -8
  133. package/src/utils/deprecated/typegen.ts +0 -133
  134. package/src/utils/execLog.ts +0 -22
  135. package/src/utils/format.ts +0 -39
  136. package/src/utils/formatAndWrite.ts +0 -21
  137. package/src/utils/foundry.ts +0 -103
  138. package/src/utils/getChainId.ts +0 -10
  139. package/src/utils/index.ts +0 -5
@@ -1,111 +0,0 @@
1
- import { constants, Wallet } from "ethers";
2
- import { generateLibDeploy, resetLibDeploy } from "./codegen.js";
3
- import { findLog } from "./findLog.js";
4
- import { generateTypes } from "./typegen.js";
5
- import { execa } from "execa";
6
- import { StaticJsonRpcProvider } from "@ethersproject/providers";
7
- import path from "path";
8
-
9
- const contractsDirectory = new URL("../src/contracts", import.meta.url).pathname;
10
-
11
- /**
12
- * Deploy world, components and systems from deploy.json
13
- * @param deployerPrivateKey private key of deployer
14
- * @param rpc rpc url
15
- * @param worldAddress optional, address of existing world
16
- * @param reuseComponents optional, reuse existing components
17
- * @returns address of deployed world
18
- */
19
- export async function deploy(
20
- deployerPrivateKey?: string,
21
- rpc = "http://localhost:8545",
22
- worldAddress?: string,
23
- reuseComponents?: boolean,
24
- gasPrice?: number
25
- ) {
26
- const address = deployerPrivateKey ? new Wallet(deployerPrivateKey).address : constants.AddressZero;
27
-
28
- if (gasPrice == null) {
29
- try {
30
- console.log("Fetching gas price...");
31
- const provider = new StaticJsonRpcProvider(rpc, { name: "AnyNetwork", chainId: 1234 });
32
- gasPrice = (await provider.getGasPrice()).toNumber() * 1.3; // 30% multiplier for faster inclusion
33
- console.log("Gas price:", gasPrice);
34
- } catch (e) {
35
- console.log("Could not fetch gas price");
36
- }
37
- }
38
-
39
- const child = execa(
40
- "forge",
41
- [
42
- "script",
43
- path.join(contractsDirectory, "/Deploy.sol"),
44
- "--target-contract",
45
- "Deploy",
46
- "-vvv",
47
- ...(!deployerPrivateKey ? [] : ["--broadcast", "--private-keys", deployerPrivateKey]),
48
- "--sig",
49
- "broadcastDeploy(address,address,bool)",
50
- address, // Deployer
51
- worldAddress || constants.AddressZero, // World address (0 = deploy a new world)
52
- reuseComponents ? "true" : "false", // Reuse components?
53
- "--fork-url",
54
- rpc,
55
- ...(gasPrice != null ? ["--with-gas-price", String(Math.round(gasPrice))] : []),
56
- ],
57
- { stdio: ["inherit", "pipe", "pipe"] }
58
- );
59
-
60
- child.stderr?.on("data", (data) => console.log("stderr:", data.toString()));
61
- child.stdout?.on("data", (data) => console.log(data.toString()));
62
-
63
- // Extract world address from deploy script
64
- const lines = (await child).stdout?.split("\n");
65
- const deployedWorldAddress = findLog(lines, "world: address");
66
- const initialBlockNumber = findLog(lines, "initialBlockNumber: uint256");
67
-
68
- return { child: await child, deployedWorldAddress, initialBlockNumber };
69
- }
70
-
71
- export type DeployOptions = {
72
- config: string;
73
- deployerPrivateKey?: string;
74
- worldAddress?: string;
75
- rpc: string;
76
- systems?: string | string[];
77
- reuseComponents?: boolean;
78
- clear?: boolean;
79
- gasPrice?: number;
80
- };
81
-
82
- export async function generateAndDeploy(args: DeployOptions) {
83
- let libDeployPath: string | undefined;
84
- let deployedWorldAddress: string | undefined;
85
- let initialBlockNumber: string | undefined;
86
-
87
- try {
88
- // Generate LibDeploy
89
- libDeployPath = await generateLibDeploy(args.config, contractsDirectory, args.systems);
90
-
91
- // Build and generate fresh types
92
- await generateTypes(undefined, "./types", { clear: args.clear });
93
-
94
- // Call deploy script
95
- const result = await deploy(
96
- args.deployerPrivateKey,
97
- args.rpc,
98
- args.worldAddress,
99
- Boolean(args.reuseComponents),
100
- args.gasPrice
101
- );
102
- deployedWorldAddress = result.deployedWorldAddress;
103
- initialBlockNumber = result.initialBlockNumber;
104
- } finally {
105
- // Remove generated LibDeploy
106
- console.log("Cleaning up deployment script");
107
- if (libDeployPath) await resetLibDeploy(contractsDirectory);
108
- }
109
-
110
- return { deployedWorldAddress, initialBlockNumber };
111
- }
@@ -1,18 +0,0 @@
1
- import { execa } from "execa";
2
-
3
- /**
4
- * Wrapper for execa that logs the full command.
5
- * @param command - The program/script to execute.
6
- * @param options - Arguments to pass to `command` on execution.
7
- * @returns A [`child_process` instance](https://nodejs.org/api/child_process.html#child_process_class_childprocess), which is enhanced to also be a `Promise` for a result `Object` with `stdout` and `stderr` properties.
8
- */
9
- export function execLog(command: string, options: string[]) {
10
- console.log("Cmd:");
11
- console.log([command, ...options].join(" "));
12
-
13
- // TODO piping outputs and doing custom logging would be better for readability
14
- // (see https://github.com/latticexyz/mud/issues/446)
15
- return execa(command, options, {
16
- stdio: ["inherit", "inherit", "inherit"],
17
- });
18
- }
@@ -1,8 +0,0 @@
1
- export function findLog(deployLogLines: string[], log: string): string {
2
- for (const logLine of deployLogLines) {
3
- if (logLine.includes(log)) {
4
- return logLine.split(log)[1].trim();
5
- }
6
- }
7
- throw new Error("Can not find log");
8
- }
@@ -1,71 +0,0 @@
1
- import chokidar from "chokidar";
2
- import { readFileSync } from "fs";
3
-
4
- const ImportsRegex = new RegExp(/(?<=import ").*(?=";)|(?<=from ").*(?=";)/g);
5
-
6
- /**
7
- * Extract file imports from a given file
8
- * @param path File to extracts imports from
9
- * @returns Array of imported filenames
10
- */
11
- function extractImports(path: string): string[] {
12
- const content = readFileSync(path).toString();
13
- const regexResult = [...content.matchAll(ImportsRegex)]
14
- .map((match) => match[0])
15
- .map((path) => path.split("/").at(-1)!);
16
- return regexResult;
17
- }
18
-
19
- function findDependencies(
20
- file: string,
21
- dependencyGraph: { [file: string]: string[] },
22
- visited: string[] = []
23
- ): string[] {
24
- const dependencies = dependencyGraph[file] ?? [];
25
- const subDependencies = dependencies.flatMap((d) => {
26
- if (visited.includes(d)) {
27
- console.warn("Circular dependency detected: ", d, dependencyGraph[d]);
28
- return [];
29
- }
30
- return findDependencies(d, dependencyGraph, [...visited, d]);
31
- });
32
- return [...new Set([...dependencies, ...subDependencies])];
33
- }
34
-
35
- // Hot System Replacement
36
- export function hsr(root: string, replaceSystems: (systems: string[]) => Promise<unknown>) {
37
- const dependencyGraph: { [file: string]: string[] } = {};
38
- const systems = new Set<string>();
39
-
40
- console.log("Watching system file changes...");
41
-
42
- chokidar.watch(root).on("all", async (event, path) => {
43
- console.log(`[${event}]: ${path}`);
44
-
45
- // Find changed file
46
- const changedFile = path.split("/").at(-1)!;
47
-
48
- if (["add", "change"].includes(event)) {
49
- // Construct dependency graph based in file imports
50
- const imports = extractImports(path);
51
- for (const importedFile of imports) {
52
- dependencyGraph[importedFile] ??= [];
53
- dependencyGraph[importedFile].push(changedFile);
54
- }
55
-
56
- // Track system files
57
- if (path.includes("systems") && path.includes(".sol")) systems.add(changedFile);
58
- }
59
-
60
- if (event === "change") {
61
- // Find all files depending on the changed file
62
- const dependencies = findDependencies(changedFile, dependencyGraph);
63
- const changedSystems = [
64
- ...new Set([changedFile, ...dependencies].filter((f) => systems.has(f)).map((f) => f.replace(".sol", ""))),
65
- ];
66
- console.log("Systems to replace", changedSystems);
67
- if (changedSystems.length > 0) await replaceSystems(changedSystems);
68
- console.log("Watching system file changes...");
69
- }
70
- });
71
- }
@@ -1,14 +0,0 @@
1
- import { keccak256 as keccak256Bytes, toUtf8Bytes } from "ethers/lib/utils.js";
2
- import { readFileSync } from "fs";
3
-
4
- export const IDregex = new RegExp(/(?<=uint256 constant ID = uint256\(keccak256\(")(.*)(?="\))/);
5
-
6
- export function extractIdFromFile(path: string): string | null {
7
- const content = readFileSync(path).toString();
8
- const regexResult = IDregex.exec(content);
9
- return regexResult && regexResult[0];
10
- }
11
-
12
- export function keccak256(data: string) {
13
- return keccak256Bytes(toUtf8Bytes(data));
14
- }
@@ -1,8 +0,0 @@
1
- export * from "./exec.js";
2
- export * from "./ids.js";
3
- export * from "./codegen.js";
4
- export * from "./deploy.js";
5
- export * from "./hsr.js";
6
- export * from "./findLog.js";
7
- export * from "./typegen.js";
8
- export * from "./build.js";
@@ -1,133 +0,0 @@
1
- import { runTypeChain, glob as typechainGlob } from "typechain";
2
- import glob from "glob";
3
- import { extractIdFromFile } from "./ids.js";
4
- import { rmSync, writeFileSync } from "fs";
5
- import path from "path";
6
- import { filterAbi, forgeBuild } from "./build.js";
7
- import { getOutDirectory, getSrcDirectory } from "../foundry.js";
8
- import { systemsDir } from "./constants.js";
9
-
10
- export async function generateAbiTypes(
11
- inputDir: string,
12
- outputDir: string,
13
- options?: { clear?: boolean; cwd?: string }
14
- ) {
15
- if (options?.clear) {
16
- console.log("Clearing typechain output directory", outputDir);
17
- rmSync(outputDir, { recursive: true, force: true });
18
- }
19
-
20
- const cwd = options?.cwd ?? process.cwd();
21
-
22
- const allFiles = typechainGlob(cwd, [`${inputDir}/**/+([a-zA-Z0-9_]).json`]);
23
-
24
- const result = await runTypeChain({
25
- cwd,
26
- filesToProcess: allFiles,
27
- allFiles,
28
- outDir: outputDir,
29
- target: "ethers-v5",
30
- });
31
-
32
- console.log(`Successfully generated ${result.filesGenerated} files`);
33
- }
34
-
35
- export async function generateSystemTypes(outputDir: string, options?: { clear?: boolean }) {
36
- if (options?.clear) {
37
- console.log("Clearing system type output files", outputDir);
38
- rmSync(path.join(outputDir, "/SystemTypes.ts"), { force: true });
39
- rmSync(path.join(outputDir, "/SystemAbis.mts"), { force: true });
40
- rmSync(path.join(outputDir, "/SystemAbis.mjs"), { force: true });
41
- rmSync(path.join(outputDir, "/SystemMappings.ts"), { force: true });
42
- }
43
-
44
- let abis: string[] = [];
45
- let systems: string[] = [];
46
- let ids: string[] = [];
47
- let typePaths: string[] = [];
48
-
49
- const srcDir = await getSrcDirectory();
50
- const systemsPath = path.join(srcDir, systemsDir, "*.sol");
51
-
52
- const matches = glob.sync(systemsPath);
53
-
54
- systems = matches.map((path) => {
55
- const fragments = path.split("/");
56
- return fragments[fragments.length - 1].split(".sol")[0];
57
- });
58
-
59
- ids = matches.map((path, index) => {
60
- const id = extractIdFromFile(path);
61
- if (!id) {
62
- console.log("Path:", path);
63
- console.log("ID:", id);
64
- throw new Error(
65
- "No ID found for" +
66
- matches[index] +
67
- ". Make sure your system source file includes a ID definition (uint256 constant ID = uint256(keccak256(<ID>));)"
68
- );
69
- }
70
- return id;
71
- });
72
-
73
- abis = systems.map((system) => `../abi/${system}.json`);
74
-
75
- typePaths = systems.map((system) => `./ethers-contracts/${system}.ts`);
76
-
77
- console.log("Matches", systems);
78
- console.log("Solidity", ids);
79
- console.log("Type paths", typePaths);
80
- console.log("ABIs", abis);
81
-
82
- const SystemMappings = `// Autogenerated using mud system-types
83
- export const systemToId = {
84
- ${systems.map((system, index) => ` ${system}: "${ids[index]}",`).join("\n")}
85
- };
86
-
87
- export const idToSystem = {
88
- ${ids.map((id, index) => ` "${id}": "${systems[index]}",`).join("\n")}
89
- };
90
- `;
91
-
92
- const SystemTypes = `// Autogenerated using mud system-types
93
- ${typePaths.map((path, index) => `import { ${systems[index]} } from "${path.replace(".ts", "")}";`).join("\n")}
94
-
95
- export type SystemTypes = {
96
- ${systems.map((system, index) => ` "${ids[index]}": ${system};`).join("\n")}
97
- };
98
- `;
99
-
100
- const SystemAbis = `// Autogenerated using mud system-types
101
- ${abis.map((path, index) => `import ${systems[index]} from "${path}";`).join("\n")}
102
-
103
- export const SystemAbis = {
104
- ${systems.map((system, index) => ` "${ids[index]}": ${system}.abi,`).join("\n")}
105
- };
106
- `;
107
-
108
- console.log("Generating files:");
109
- console.log("SystemTypes.ts", SystemTypes);
110
- console.log("SystemAbis.mts", SystemAbis);
111
- console.log("SystemMappings.ts", SystemMappings);
112
-
113
- writeFileSync(`${outputDir}/SystemTypes.ts`, SystemTypes);
114
- writeFileSync(`${outputDir}/SystemAbis.mts`, SystemAbis);
115
- writeFileSync(`${outputDir}/SystemAbis.mjs`, SystemAbis);
116
- writeFileSync(`${outputDir}/SystemMappings.ts`, SystemMappings);
117
- }
118
-
119
- /**
120
- * @param abiDir If not provided, the contracts are built and abis are exported to ./abi
121
- */
122
- export async function generateTypes(abiDir?: string, outputDir = "./types", options?: { clear?: boolean }) {
123
- if (!abiDir) {
124
- console.log("Compiling contracts");
125
- const buildOutput = await getOutDirectory();
126
- abiDir = "./abi";
127
- await forgeBuild(options);
128
- filterAbi(buildOutput, abiDir);
129
- }
130
-
131
- await generateAbiTypes(abiDir, path.join(outputDir, "ethers-contracts"), options);
132
- await generateSystemTypes(outputDir, options);
133
- }
@@ -1,22 +0,0 @@
1
- import chalk from "chalk";
2
- import { execa, Options } from "execa";
3
-
4
- /**
5
- * Executes the given command, returns the stdout, and logs the command to the console.
6
- * Throws an error if the command fails.
7
- * @param command The command to execute
8
- * @param args The arguments to pass to the command
9
- * @returns The stdout of the command
10
- */
11
- export async function execLog(command: string, args: string[], options?: Options<string>): Promise<string> {
12
- const commandString = `${command} ${args.join(" ")}`;
13
- try {
14
- console.log(chalk.gray(`running "${commandString}"`));
15
- const { stdout } = await execa(command, args, { stdout: "pipe", stderr: "pipe", ...options });
16
- return stdout;
17
- } catch (error: any) {
18
- let errorMessage = error?.stderr || error?.message || "";
19
- errorMessage += chalk.red(`\nError running "${commandString}"`);
20
- throw new Error(errorMessage);
21
- }
22
- }
@@ -1,39 +0,0 @@
1
- import chalk from "chalk";
2
- import prettier from "prettier";
3
- import prettierPluginSolidity from "prettier-plugin-solidity";
4
-
5
- export async function formatSolidity(content: string, prettierConfigPath?: string) {
6
- let config;
7
- if (prettierConfigPath) {
8
- config = await prettier.resolveConfig(prettierConfigPath);
9
- }
10
- try {
11
- return prettier.format(content, {
12
- plugins: [prettierPluginSolidity],
13
- parser: "solidity-parse",
14
-
15
- printWidth: 120,
16
- semi: true,
17
- tabWidth: 2,
18
- useTabs: false,
19
- bracketSpacing: true,
20
-
21
- ...config,
22
- });
23
- } catch (error) {
24
- let message;
25
- if (error instanceof Error) {
26
- message = error.message;
27
- } else {
28
- message = error;
29
- }
30
- console.log(chalk.yellow(`Error during output formatting: ${message}`));
31
- return content;
32
- }
33
- }
34
-
35
- export async function formatTypescript(content: string) {
36
- return prettier.format(content, {
37
- parser: "typescript",
38
- });
39
- }
@@ -1,21 +0,0 @@
1
- import { mkdirSync, writeFileSync } from "fs";
2
- import { dirname } from "path";
3
- import { formatSolidity, formatTypescript } from "./format.js";
4
-
5
- export async function formatAndWriteSolidity(output: string, fullOutputPath: string, logPrefix: string) {
6
- const formattedOutput = await formatSolidity(output);
7
-
8
- mkdirSync(dirname(fullOutputPath), { recursive: true });
9
-
10
- writeFileSync(fullOutputPath, formattedOutput);
11
- console.log(`${logPrefix}: ${fullOutputPath}`);
12
- }
13
-
14
- export async function formatAndWriteTypescript(output: string, fullOutputPath: string, logPrefix: string) {
15
- const formattedOutput = await formatTypescript(output);
16
-
17
- mkdirSync(dirname(fullOutputPath), { recursive: true });
18
-
19
- writeFileSync(fullOutputPath, formattedOutput);
20
- console.log(`${logPrefix}: ${fullOutputPath}`);
21
- }
@@ -1,103 +0,0 @@
1
- import { execa, Options } from "execa";
2
- import { execLog } from "./execLog.js";
3
-
4
- export interface ForgeConfig {
5
- // project
6
- src: string;
7
- test: string;
8
- script: string;
9
- out: string;
10
- libs: string[];
11
- eth_rpc_url: string | null;
12
-
13
- // all unspecified keys (this interface is far from comprehensive)
14
- [key: string]: unknown;
15
- }
16
-
17
- /**
18
- * Get forge config as a parsed json object.
19
- */
20
- export async function getForgeConfig(profile?: string) {
21
- const { stdout } = await execa("forge", ["config", "--json"], {
22
- stdio: ["inherit", "pipe", "pipe"],
23
- env: { FOUNDRY_PROFILE: profile },
24
- });
25
-
26
- return JSON.parse(stdout) as ForgeConfig;
27
- }
28
-
29
- /**
30
- * Get the value of "src" from forge config.
31
- * The path to the contract sources relative to the root of the project.
32
- */
33
- export async function getSrcDirectory(profile?: string) {
34
- return (await getForgeConfig(profile)).src;
35
- }
36
-
37
- /**
38
- * Get the value of "script" from forge config.
39
- * The path to the contract sources relative to the root of the project.
40
- */
41
- export async function getScriptDirectory(profile?: string) {
42
- return (await getForgeConfig(profile)).script;
43
- }
44
-
45
- /**
46
- * Get the value of "test" from forge config.
47
- * The path to the test contract sources relative to the root of the project.
48
- */
49
- export async function getTestDirectory(profile?: string) {
50
- return (await getForgeConfig(profile)).test;
51
- }
52
-
53
- /**
54
- * Get the value of "out" from forge config.
55
- * The path to put contract artifacts in, relative to the root of the project.
56
- */
57
- export async function getOutDirectory(profile?: string) {
58
- return (await getForgeConfig(profile)).out;
59
- }
60
-
61
- /**
62
- * Get the value of "eth_rpc_url" from forge config, default to "http://127.0.0.1:8545"
63
- * @param profile The foundry profile to use
64
- * @returns The rpc url
65
- */
66
- export async function getRpcUrl(profile?: string) {
67
- return (await getForgeConfig(profile)).eth_rpc_url || "http://127.0.0.1:8545";
68
- }
69
-
70
- /**
71
- * Execute a forge command
72
- * @param args The arguments to pass to forge
73
- * @param options { profile?: The foundry profile to use; silent?: If true, nothing will be logged to the console }
74
- */
75
- export async function forge(args: string[], options?: { profile?: string; silent?: boolean }): Promise<void> {
76
- const execOptions: Options<string> = {
77
- env: { FOUNDRY_PROFILE: options?.profile },
78
- stdout: "inherit",
79
- stderr: "pipe",
80
- };
81
-
82
- await (options?.silent ? execa("forge", args, execOptions) : execLog("forge", args, execOptions));
83
- }
84
-
85
- /**
86
- * Execute a cast command
87
- * @param args The arguments to pass to cast
88
- * @returns Stdout of the command
89
- */
90
- export async function cast(args: string[], options?: { profile?: string }): Promise<string> {
91
- return execLog("cast", args, {
92
- env: { FOUNDRY_PROFILE: options?.profile },
93
- });
94
- }
95
-
96
- /**
97
- * Start an anvil chain
98
- * @param args The arguments to pass to anvil
99
- * @returns Stdout of the command
100
- */
101
- export async function anvil(args: string[]): Promise<string> {
102
- return execLog("anvil", args);
103
- }
@@ -1,10 +0,0 @@
1
- import { ethers } from "ethers";
2
-
3
- // TODO: Use viem's getChainId
4
- export async function getChainId(rpc: string) {
5
- const { result: chainId } = await ethers.utils.fetchJson(
6
- rpc,
7
- '{ "id": 42, "jsonrpc": "2.0", "method": "eth_chainId", "params": [ ] }'
8
- );
9
- return Number(chainId);
10
- }
@@ -1,5 +0,0 @@
1
- export * from "./errors.js";
2
- export * from "./foundry.js";
3
- export * from "./format.js";
4
- export * from "./formatAndWrite.js";
5
- export * from "./deploy-v2.js";