@latticexyz/cli 2.0.0-alpha.49 → 2.0.0-alpha.5

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 (82) hide show
  1. package/dist/chunk-6V563IAZ.js +283 -0
  2. package/dist/{chunk-ATAWDHWC.js → chunk-FPG73MVN.js} +5 -1
  3. package/dist/chunk-KJTPZOUH.js +3864 -0
  4. package/dist/{chunk-O6HOO6WA.js → chunk-L4YLJHLJ.js} +1 -9
  5. package/dist/{chunk-KPBNUPK6.js → chunk-SKNB74MT.js} +155 -159
  6. package/dist/chunk-VQTZJIFF.js +353 -0
  7. package/dist/{chunk-MXDV47JM.js → chunk-WZFXLDPK.js} +75 -24
  8. package/dist/chunk-YL4GJLLL.js +26139 -0
  9. package/dist/index.d.ts +2 -4
  10. package/dist/index.js +0 -22
  11. package/dist/mud.d.ts +1 -1
  12. package/dist/mud.js +319 -3971
  13. package/dist/mud2.d.ts +1 -0
  14. package/dist/mud2.js +25 -0
  15. package/dist/render-solidity/index.d.ts +3 -3
  16. package/dist/render-solidity/index.js +3 -4
  17. package/dist/render-ts/index.d.ts +2 -3
  18. package/dist/render-ts/index.js +3 -4
  19. package/dist/utils/deprecated/index.js +3 -3
  20. package/dist/utils/index.d.ts +9 -19
  21. package/dist/utils/index.js +7 -18
  22. package/package.json +19 -20
  23. package/src/commands/deploy-v2.ts +80 -64
  24. package/src/commands/deprecated/index.ts +22 -0
  25. package/src/commands/deprecated/test.ts +1 -1
  26. package/src/commands/gas-report.ts +54 -55
  27. package/src/commands/index.ts +2 -17
  28. package/src/commands/set-version.ts +39 -10
  29. package/src/commands/tablegen.ts +5 -5
  30. package/src/commands/test-v2.ts +71 -0
  31. package/src/commands/tsgen.ts +1 -1
  32. package/src/commands/worldgen.ts +5 -4
  33. package/src/contracts/BulkUpload.sol +13 -20
  34. package/src/contracts/Deploy.sol +3 -3
  35. package/src/contracts/LibDeploy.sol +1 -1
  36. package/src/contracts/LibDeployStub.sol +1 -1
  37. package/src/index.ts +1 -15
  38. package/src/mud.ts +4 -3
  39. package/src/mud2.ts +29 -0
  40. package/src/render-solidity/common.ts +4 -4
  41. package/src/render-solidity/field.ts +25 -2
  42. package/src/render-solidity/record.ts +14 -10
  43. package/src/render-solidity/renderSystemInterface.ts +4 -4
  44. package/src/render-solidity/renderTableIndex.ts +15 -0
  45. package/src/render-solidity/renderTypesFromConfig.ts +1 -1
  46. package/src/render-solidity/tableOptions.ts +2 -2
  47. package/src/render-solidity/tablegen.ts +13 -1
  48. package/src/render-solidity/types.ts +2 -1
  49. package/src/render-solidity/userType.ts +1 -2
  50. package/src/render-solidity/worldgen.ts +3 -3
  51. package/src/render-ts/recsV1TableOptions.ts +2 -2
  52. package/src/render-ts/renderRecsV1Tables.ts +2 -2
  53. package/src/render-ts/schemaTypesToRecsTypeStrings.ts +136 -136
  54. package/src/render-ts/tsgen.ts +1 -1
  55. package/src/render-ts/types.ts +1 -1
  56. package/src/utils/contractToInterface.ts +5 -3
  57. package/src/utils/deploy-v2.ts +85 -78
  58. package/src/utils/errors.ts +3 -34
  59. package/src/utils/foundry.ts +9 -0
  60. package/dist/chunk-5NC2OON2.js +0 -164
  61. package/dist/chunk-7GA2K5A6.js +0 -283
  62. package/dist/chunk-LPWKZQUI.js +0 -454
  63. package/dist/chunk-Q7D3SKYJ.js +0 -22908
  64. package/dist/chunk-SLIMIO4Z.js +0 -14358
  65. package/dist/config/index.d.ts +0 -408
  66. package/dist/config/index.js +0 -85
  67. package/dist/parseStoreConfig-899f574e.d.ts +0 -369
  68. package/src/config/commonSchemas.ts +0 -34
  69. package/src/config/dynamicResolution.ts +0 -49
  70. package/src/config/index.ts +0 -24
  71. package/src/config/loadConfig.ts +0 -39
  72. package/src/config/loadStoreConfig.ts +0 -18
  73. package/src/config/parseStoreConfig.test-d.ts +0 -40
  74. package/src/config/parseStoreConfig.ts +0 -314
  75. package/src/config/validation.ts +0 -163
  76. package/src/config/world/index.ts +0 -4
  77. package/src/config/world/loadWorldConfig.test-d.ts +0 -11
  78. package/src/config/world/loadWorldConfig.ts +0 -26
  79. package/src/config/world/parseWorldConfig.ts +0 -56
  80. package/src/config/world/resolveWorldConfig.ts +0 -80
  81. package/src/config/world/userTypes.ts +0 -74
  82. package/src/utils/typeUtils.ts +0 -17
package/dist/mud2.d.ts ADDED
@@ -0,0 +1 @@
1
+ #!/usr/bin/env node
package/dist/mud2.js ADDED
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ commands
4
+ } from "./chunk-KJTPZOUH.js";
5
+ import {
6
+ logError
7
+ } from "./chunk-YL4GJLLL.js";
8
+ import "./chunk-VQTZJIFF.js";
9
+ import "./chunk-FPG73MVN.js";
10
+ import "./chunk-WZFXLDPK.js";
11
+ import "./chunk-6V563IAZ.js";
12
+ import "./chunk-SKNB74MT.js";
13
+ import "./chunk-L4YLJHLJ.js";
14
+
15
+ // src/mud2.ts
16
+ import yargs from "yargs";
17
+ import { hideBin } from "yargs/helpers";
18
+ import * as dotenv from "dotenv";
19
+ dotenv.config();
20
+ yargs(hideBin(process.argv)).scriptName("mud").command(commands).strict().fail((msg, err) => {
21
+ console.log("");
22
+ logError(err);
23
+ console.log("");
24
+ process.exit(1);
25
+ }).alias({ h: "help" }).argv;
@@ -1,6 +1,5 @@
1
- import { a as StoreConfig } from '../parseStoreConfig-899f574e.js';
1
+ import { StoreConfig } from '@latticexyz/config';
2
2
  import { SchemaType } from '@latticexyz/schema-type';
3
- import 'zod';
4
3
 
5
4
  interface RenderTableOptions {
6
5
  /** List of symbols to import, and their file paths */
@@ -31,7 +30,7 @@ interface StaticResourceData {
31
30
  /** Name of the table id constant to render. */
32
31
  tableIdName: string;
33
32
  namespace: string;
34
- fileSelector: string;
33
+ name: string;
35
34
  }
36
35
  interface RenderTableType {
37
36
  typeId: string;
@@ -87,6 +86,7 @@ interface RenderSystemInterfaceOptions {
87
86
  interface RenderSystemInterfaceFunction {
88
87
  name: string;
89
88
  parameters: string[];
89
+ stateMutability: string;
90
90
  returnParameters: string[];
91
91
  }
92
92
  interface RenderWorldOptions {
@@ -16,15 +16,14 @@ import {
16
16
  renderedSolidityHeader,
17
17
  solidityRelativeImportPath,
18
18
  tablegen
19
- } from "../chunk-MXDV47JM.js";
19
+ } from "../chunk-WZFXLDPK.js";
20
20
  import {
21
21
  getSchemaTypeInfo,
22
22
  getUserTypeInfo,
23
23
  importForAbiOrUserType,
24
24
  resolveAbiOrUserType
25
- } from "../chunk-5NC2OON2.js";
26
- import "../chunk-KPBNUPK6.js";
27
- import "../chunk-O6HOO6WA.js";
25
+ } from "../chunk-SKNB74MT.js";
26
+ import "../chunk-L4YLJHLJ.js";
28
27
  export {
29
28
  getSchemaTypeInfo,
30
29
  getTableOptions,
@@ -1,6 +1,5 @@
1
- import { a as StoreConfig } from '../parseStoreConfig-899f574e.js';
1
+ import { StoreConfig } from '@latticexyz/config';
2
2
  import { SchemaType } from '@latticexyz/schema-type';
3
- import 'zod';
4
3
 
5
4
  interface RecsV1TableOptions {
6
5
  tables: {
@@ -11,7 +10,7 @@ interface RecsV1TableOptions {
11
10
  }[];
12
11
  staticResourceData: {
13
12
  namespace: string;
14
- fileSelector: string;
13
+ name: string;
15
14
  };
16
15
  }[];
17
16
  }
@@ -3,10 +3,9 @@ import {
3
3
  renderRecsV1Tables,
4
4
  schemaTypesToRecsTypeStrings,
5
5
  tsgen
6
- } from "../chunk-7GA2K5A6.js";
7
- import "../chunk-5NC2OON2.js";
8
- import "../chunk-KPBNUPK6.js";
9
- import "../chunk-O6HOO6WA.js";
6
+ } from "../chunk-6V563IAZ.js";
7
+ import "../chunk-SKNB74MT.js";
8
+ import "../chunk-L4YLJHLJ.js";
10
9
  export {
11
10
  getRecsV1TableOptions,
12
11
  renderRecsV1Tables,
@@ -14,9 +14,9 @@ import {
14
14
  hsr,
15
15
  keccak256,
16
16
  resetLibDeploy
17
- } from "../../chunk-SLIMIO4Z.js";
18
- import "../../chunk-ATAWDHWC.js";
19
- import "../../chunk-O6HOO6WA.js";
17
+ } from "../../chunk-VQTZJIFF.js";
18
+ import "../../chunk-FPG73MVN.js";
19
+ import "../../chunk-L4YLJHLJ.js";
20
20
  export {
21
21
  IDregex,
22
22
  deploy,
@@ -1,22 +1,5 @@
1
- import { ZodError, z } from 'zod';
2
- import { ValidationError } from 'zod-validation-error';
3
- import { MUDConfig } from '../config/index.js';
4
- import '../parseStoreConfig-899f574e.js';
5
- import '@latticexyz/schema-type';
1
+ import { MUDConfig } from '@latticexyz/config';
6
2
 
7
- declare function fromZodErrorCustom(error: ZodError, prefix: string): ValidationError;
8
- declare class NotInsideProjectError extends Error {
9
- name: string;
10
- message: string;
11
- }
12
- declare class NotESMConfigError extends Error {
13
- name: string;
14
- message: string;
15
- }
16
- declare class MUDError extends Error {
17
- name: string;
18
- }
19
- declare function UnrecognizedSystemErrorFactory(path: string[], systemName: string): z.ZodError<any>;
20
3
  declare function logError(error: unknown): void;
21
4
 
22
5
  interface ForgeConfig {
@@ -75,6 +58,12 @@ declare function forge(args: string[], options?: {
75
58
  declare function cast(args: string[], options?: {
76
59
  profile?: string;
77
60
  }): Promise<string>;
61
+ /**
62
+ * Start an anvil chain
63
+ * @param args The arguments to pass to anvil
64
+ * @returns Stdout of the command
65
+ */
66
+ declare function anvil(args: string[]): Promise<string>;
78
67
 
79
68
  declare function formatSolidity(content: string, prettierConfigPath?: string): Promise<string>;
80
69
  declare function formatTypescript(content: string): Promise<string>;
@@ -88,6 +77,7 @@ interface DeployConfig {
88
77
  privateKey: string;
89
78
  priorityFeeMultiplier: number;
90
79
  debug?: boolean;
80
+ worldAddress?: string;
91
81
  }
92
82
  interface DeploymentInfo {
93
83
  blockNumber: number;
@@ -95,4 +85,4 @@ interface DeploymentInfo {
95
85
  }
96
86
  declare function deploy(mudConfig: MUDConfig, deployConfig: DeployConfig): Promise<DeploymentInfo>;
97
87
 
98
- export { DeployConfig, DeploymentInfo, ForgeConfig, MUDError, NotESMConfigError, NotInsideProjectError, UnrecognizedSystemErrorFactory, cast, deploy, forge, formatAndWriteSolidity, formatAndWriteTypescript, formatSolidity, formatTypescript, fromZodErrorCustom, getForgeConfig, getOutDirectory, getRpcUrl, getScriptDirectory, getSrcDirectory, getTestDirectory, logError };
88
+ export { DeployConfig, DeploymentInfo, ForgeConfig, anvil, cast, deploy, forge, formatAndWriteSolidity, formatAndWriteTypescript, formatSolidity, formatTypescript, getForgeConfig, getOutDirectory, getRpcUrl, getScriptDirectory, getSrcDirectory, getTestDirectory, logError };
@@ -1,15 +1,9 @@
1
1
  import {
2
- deploy
3
- } from "../chunk-Q7D3SKYJ.js";
4
- import {
5
- MUDError,
6
- NotESMConfigError,
7
- NotInsideProjectError,
8
- UnrecognizedSystemErrorFactory,
9
- fromZodErrorCustom,
2
+ deploy,
10
3
  logError
11
- } from "../chunk-LPWKZQUI.js";
4
+ } from "../chunk-YL4GJLLL.js";
12
5
  import {
6
+ anvil,
13
7
  cast,
14
8
  forge,
15
9
  getForgeConfig,
@@ -18,20 +12,16 @@ import {
18
12
  getScriptDirectory,
19
13
  getSrcDirectory,
20
14
  getTestDirectory
21
- } from "../chunk-ATAWDHWC.js";
15
+ } from "../chunk-FPG73MVN.js";
22
16
  import {
23
17
  formatAndWriteSolidity,
24
18
  formatAndWriteTypescript,
25
19
  formatSolidity,
26
20
  formatTypescript
27
- } from "../chunk-5NC2OON2.js";
28
- import "../chunk-KPBNUPK6.js";
29
- import "../chunk-O6HOO6WA.js";
21
+ } from "../chunk-SKNB74MT.js";
22
+ import "../chunk-L4YLJHLJ.js";
30
23
  export {
31
- MUDError,
32
- NotESMConfigError,
33
- NotInsideProjectError,
34
- UnrecognizedSystemErrorFactory,
24
+ anvil,
35
25
  cast,
36
26
  deploy,
37
27
  forge,
@@ -39,7 +29,6 @@ export {
39
29
  formatAndWriteTypescript,
40
30
  formatSolidity,
41
31
  formatTypescript,
42
- fromZodErrorCustom,
43
32
  getForgeConfig,
44
33
  getOutDirectory,
45
34
  getRpcUrl,
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "@latticexyz/cli",
3
- "version": "2.0.0-alpha.49+7d06c1b5",
3
+ "version": "2.0.0-alpha.5+01167ab3",
4
4
  "description": "Command line interface for mud",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "type": "module",
8
8
  "license": "MIT",
9
9
  "bin": {
10
- "mud": "./dist/mud.js"
10
+ "mud": "./dist/mud.js",
11
+ "mud2": "./dist/mud2.js"
11
12
  },
12
13
  "repository": {
13
14
  "type": "git",
@@ -15,37 +16,38 @@
15
16
  "directory": "packages/cli"
16
17
  },
17
18
  "scripts": {
18
- "prepare": "yarn build && chmod u+x git-install.sh",
19
- "codegen": "ts-node --esm --files ./scripts/codegen.ts",
19
+ "codegen": "tsx ./scripts/codegen.ts",
20
20
  "lint": "eslint . --ext .ts",
21
21
  "dev": "tsup --watch",
22
22
  "build": "tsup",
23
- "link": "yarn link",
24
- "test": "vitest typecheck --run && yarn test:contracts",
25
- "test:contracts": "yarn codegen && forge test",
26
- "git:install": "bash git-install.sh",
23
+ "test": "tsc --noEmit && pnpm test:contracts",
24
+ "test:contracts": "pnpm codegen && forge test",
27
25
  "release": "npm publish --access=public"
28
26
  },
29
27
  "devDependencies": {
30
- "@latticexyz/store": "^2.0.0-alpha.49+7d06c1b5",
31
28
  "@types/ejs": "^3.1.1",
32
29
  "@types/glob": "^7.2.0",
33
30
  "@types/node": "^17.0.34",
34
31
  "@types/openurl": "^1.0.0",
35
32
  "@types/yargs": "^17.0.10",
36
- "esbuild": "^0.15.16",
37
33
  "tsup": "^6.6.3",
34
+ "tsx": "^3.12.6",
38
35
  "vitest": "^0.29.8"
39
36
  },
40
37
  "dependencies": {
38
+ "@ethersproject/abi": "^5.7.0",
39
+ "@ethersproject/providers": "^5.7.2",
41
40
  "@improbable-eng/grpc-web": "^0.15.0",
42
41
  "@improbable-eng/grpc-web-node-http-transport": "^0.15.0",
43
- "@latticexyz/schema-type": "^2.0.0-alpha.49+7d06c1b5",
44
- "@latticexyz/services": "^2.0.0-alpha.49+7d06c1b5",
45
- "@latticexyz/solecs": "^2.0.0-alpha.49+7d06c1b5",
46
- "@latticexyz/std-contracts": "^2.0.0-alpha.49+7d06c1b5",
42
+ "@latticexyz/config": "2.0.0-alpha.5+01167ab3",
43
+ "@latticexyz/schema-type": "2.0.0-alpha.5+01167ab3",
44
+ "@latticexyz/services": "2.0.0-alpha.5+01167ab3",
45
+ "@latticexyz/solecs": "2.0.0-alpha.5+01167ab3",
46
+ "@latticexyz/std-contracts": "2.0.0-alpha.5+01167ab3",
47
+ "@latticexyz/store": "2.0.0-alpha.5+01167ab3",
48
+ "@latticexyz/world": "2.0.0-alpha.5+01167ab3",
47
49
  "@solidity-parser/parser": "^0.16.0",
48
- "@typechain/ethers-v5": "^10.1.1",
50
+ "@typechain/ethers-v5": "^10.2.0",
49
51
  "chalk": "^5.0.1",
50
52
  "chokidar": "^3.5.3",
51
53
  "dotenv": "^16.0.3",
@@ -53,7 +55,6 @@
53
55
  "ejs": "^3.1.8",
54
56
  "ethers": "^5.7.2",
55
57
  "execa": "^7.0.0",
56
- "find-up": "^6.3.0",
57
58
  "forge-std": "https://github.com/foundry-rs/forge-std.git#b4f121555729b3afb3c5ffccb62ff4b6e2818fd3",
58
59
  "glob": "^8.0.3",
59
60
  "nice-grpc-web": "^2.0.1",
@@ -61,14 +62,12 @@
61
62
  "path": "^0.12.7",
62
63
  "prettier": "^2.8.4",
63
64
  "prettier-plugin-solidity": "^1.1.2",
64
- "solmate": "https://github.com/Rari-Capital/solmate.git#9cf1428245074e39090dceacb0c28b1f684f584c",
65
65
  "table": "^6.8.1",
66
- "ts-node": "^10.9.1",
67
66
  "typechain": "^8.1.1",
68
67
  "typescript": "^4.9.5",
69
68
  "yargs": "^17.7.1",
70
69
  "zod": "^3.21.4",
71
- "zod-validation-error": "^1.0.1"
70
+ "zod-validation-error": "^1.3.0"
72
71
  },
73
- "gitHead": "7d06c1b5cf00df627000c907e78f60d3cd2415cd"
72
+ "gitHead": "01167ab366c9e677fd84161401c07e44066f5f03"
74
73
  }
@@ -1,80 +1,81 @@
1
1
  import chalk from "chalk";
2
2
  import glob from "glob";
3
3
  import path, { basename } from "path";
4
- import type { CommandModule } from "yargs";
5
- import { loadWorldConfig } from "../config/world/index.js";
4
+ import type { CommandModule, Options } from "yargs";
5
+ import { loadStoreConfig, loadWorldConfig } from "@latticexyz/config";
6
+ import { MUDError } from "@latticexyz/config";
6
7
  import { deploy } from "../utils/deploy-v2.js";
7
- import { logError, MUDError } from "../utils/errors.js";
8
+ import { logError } from "../utils/errors.js";
8
9
  import { forge, getRpcUrl, getSrcDirectory } from "../utils/foundry.js";
9
10
  import { mkdirSync, writeFileSync } from "fs";
10
- import { loadStoreConfig } from "../config/loadStoreConfig.js";
11
11
  import { getChainId } from "../utils/getChainId.js";
12
12
 
13
- type Options = {
13
+ export type DeployOptions = {
14
14
  configPath?: string;
15
15
  printConfig?: boolean;
16
16
  profile?: string;
17
- privateKey: string;
18
17
  priorityFeeMultiplier: number;
19
18
  clean?: boolean;
20
19
  debug?: boolean;
20
+ saveDeployment?: boolean;
21
+ rpc?: string;
22
+ worldAddress?: string;
23
+ srcDir?: string;
21
24
  };
22
25
 
23
- const commandModule: CommandModule<Options, Options> = {
24
- command: "deploy-v2",
25
-
26
- describe: "Deploy MUD v2 contracts",
27
-
28
- builder(yargs) {
29
- return yargs.options({
30
- configPath: { type: "string", desc: "Path to the config file" },
31
- clean: { type: "boolean", desc: "Remove the build forge artifacts and cache directories before building" },
32
- printConfig: { type: "boolean", desc: "Print the resolved config" },
33
- profile: { type: "string", desc: "The foundry profile to use" },
34
- debug: { type: "boolean", desc: "Print debug logs, like full error messages" },
35
- priorityFeeMultiplier: {
36
- type: "number",
37
- desc: "Multiply the estimated priority fee by the provided factor",
38
- default: 1,
39
- },
40
- });
26
+ export const yDeployOptions = {
27
+ configPath: { type: "string", desc: "Path to the config file" },
28
+ clean: { type: "boolean", desc: "Remove the build forge artifacts and cache directories before building" },
29
+ printConfig: { type: "boolean", desc: "Print the resolved config" },
30
+ profile: { type: "string", desc: "The foundry profile to use" },
31
+ debug: { type: "boolean", desc: "Print debug logs, like full error messages" },
32
+ priorityFeeMultiplier: {
33
+ type: "number",
34
+ desc: "Multiply the estimated priority fee by the provided factor",
35
+ default: 1,
41
36
  },
42
-
43
- async handler(args) {
44
- args.profile = args.profile ?? process.env.FOUNDRY_PROFILE;
45
- const { configPath, printConfig, profile, clean } = args;
46
-
47
- const rpc = await getRpcUrl(profile);
48
- console.log(
49
- chalk.bgBlue(
50
- chalk.whiteBright(`\n Deploying MUD v2 contracts${profile ? " with profile " + profile : ""} to RPC ${rpc} \n`)
51
- )
52
- );
53
-
54
- if (clean) await forge(["clean"], { profile });
55
-
56
- // Run forge build
57
- await forge(["build"], { profile });
58
-
59
- // Get a list of all contract names
60
- const srcDir = await getSrcDirectory();
61
- const existingContracts = glob
62
- .sync(`${srcDir}/**/*.sol`)
63
- // Get the basename of the file
64
- .map((path) => basename(path, ".sol"));
65
-
66
- // Load and resolve the config
67
- const worldConfig = await loadWorldConfig(configPath, existingContracts);
68
- const storeConfig = await loadStoreConfig(configPath);
69
- const mudConfig = { ...worldConfig, ...storeConfig };
70
-
71
- if (printConfig) console.log(chalk.green("\nResolved config:\n"), JSON.stringify(mudConfig, null, 2));
72
-
73
- try {
74
- const privateKey = process.env.PRIVATE_KEY;
75
- if (!privateKey) throw new MUDError("Missing PRIVATE_KEY environment variable");
76
- const deploymentInfo = await deploy(mudConfig, { ...args, rpc, privateKey });
77
-
37
+ saveDeployment: { type: "boolean", desc: "Save the deployment info to a file", default: true },
38
+ rpc: { type: "string", desc: "The RPC URL to use. Defaults to the RPC url from the local foundry.toml" },
39
+ worldAddress: { type: "string", desc: "Deploy to an existing World at the given address" },
40
+ srcDir: { type: "string", desc: "Source directory. Defaults to foundry src directory." },
41
+ } satisfies Record<keyof DeployOptions, Options>;
42
+
43
+ export async function deployHandler(args: Parameters<(typeof commandModule)["handler"]>[0]) {
44
+ args.profile = args.profile ?? process.env.FOUNDRY_PROFILE;
45
+ const { configPath, printConfig, profile, clean } = args;
46
+
47
+ const rpc = args.rpc ?? (await getRpcUrl(profile));
48
+ console.log(
49
+ chalk.bgBlue(
50
+ chalk.whiteBright(`\n Deploying MUD v2 contracts${profile ? " with profile " + profile : ""} to RPC ${rpc} \n`)
51
+ )
52
+ );
53
+
54
+ if (clean) await forge(["clean"], { profile });
55
+
56
+ // Run forge build
57
+ await forge(["build"], { profile });
58
+
59
+ // Get a list of all contract names
60
+ const srcDir = args?.srcDir ?? (await getSrcDirectory());
61
+ const existingContracts = glob
62
+ .sync(`${srcDir}/**/*.sol`)
63
+ // Get the basename of the file
64
+ .map((path) => basename(path, ".sol"));
65
+
66
+ // Load and resolve the config
67
+ const worldConfig = await loadWorldConfig(configPath, existingContracts);
68
+ const storeConfig = await loadStoreConfig(configPath);
69
+ const mudConfig = { ...worldConfig, ...storeConfig };
70
+
71
+ if (printConfig) console.log(chalk.green("\nResolved config:\n"), JSON.stringify(mudConfig, null, 2));
72
+
73
+ try {
74
+ const privateKey = process.env.PRIVATE_KEY;
75
+ if (!privateKey) throw new MUDError("Missing PRIVATE_KEY environment variable");
76
+ const deploymentInfo = await deploy(mudConfig, { ...args, rpc, privateKey });
77
+
78
+ if (args.saveDeployment) {
78
79
  // Write deployment result to file (latest and timestamp)
79
80
  const chainId = await getChainId(rpc);
80
81
  const outputDir = path.join(mudConfig.deploysDirectory, chainId.toString());
@@ -83,12 +84,27 @@ const commandModule: CommandModule<Options, Options> = {
83
84
  writeFileSync(path.join(outputDir, Date.now() + ".json"), JSON.stringify(deploymentInfo, null, 2));
84
85
 
85
86
  console.log(chalk.bgGreen(chalk.whiteBright(`\n Deployment result (written to ${outputDir}): \n`)));
86
- console.log(deploymentInfo);
87
- } catch (error: any) {
88
- logError(error);
89
- process.exit(1);
90
87
  }
91
88
 
89
+ console.log(deploymentInfo);
90
+ return deploymentInfo;
91
+ } catch (error: any) {
92
+ logError(error);
93
+ process.exit(1);
94
+ }
95
+ }
96
+
97
+ const commandModule: CommandModule<DeployOptions, DeployOptions> = {
98
+ command: "deploy-v2",
99
+
100
+ describe: "Deploy MUD v2 contracts",
101
+
102
+ builder(yargs) {
103
+ return yargs.options(yDeployOptions);
104
+ },
105
+
106
+ async handler(args) {
107
+ await deployHandler(args);
92
108
  process.exit(0);
93
109
  },
94
110
  };
@@ -0,0 +1,22 @@
1
+ import { CommandModule } from "yargs";
2
+
3
+ import bulkupload from "./bulkupload.js";
4
+ import callSystem from "./call-system.js";
5
+ import codegenLibdeploy from "./codegen-libdeploy.js";
6
+ import deployContracts from "./deploy-contracts.js";
7
+ import systemTypes from "./system-types.js";
8
+ import test from "./test.js";
9
+ import trace from "./trace.js";
10
+ import types from "./types.js";
11
+
12
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- Each command has different options
13
+ export const commands: CommandModule<any, any>[] = [
14
+ bulkupload,
15
+ callSystem,
16
+ deployContracts,
17
+ codegenLibdeploy,
18
+ systemTypes,
19
+ test,
20
+ trace,
21
+ types,
22
+ ];
@@ -43,7 +43,7 @@ const commandModule: CommandModule<Options, Options> = {
43
43
  });
44
44
 
45
45
  await child;
46
-
46
+
47
47
  // Reset LibDeploy.sol
48
48
  console.log("Reset LibDeploy.sol");
49
49
  await resetLibDeploy(testDir);