@latticexyz/cli 2.0.0-alpha.94 → 2.0.0-main-0d434816

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 (100) hide show
  1. package/dist/chunk-LFIOIY67.js +30 -0
  2. package/dist/chunk-LFIOIY67.js.map +1 -0
  3. package/dist/index.js +2 -0
  4. package/dist/index.js.map +1 -0
  5. package/dist/mud.js +15 -8340
  6. package/dist/mud.js.map +1 -0
  7. package/package.json +45 -43
  8. package/src/commands/deploy.ts +49 -0
  9. package/src/commands/dev-contracts.ts +176 -0
  10. package/src/commands/devnode.ts +7 -2
  11. package/src/commands/faucet.ts +1 -1
  12. package/src/commands/index.ts +18 -13
  13. package/src/commands/set-version.ts +38 -10
  14. package/src/commands/tablegen.ts +5 -4
  15. package/src/commands/{test-v2.ts → test.ts} +5 -6
  16. package/src/commands/trace.ts +108 -0
  17. package/src/commands/tsgen.ts +4 -3
  18. package/src/commands/worldgen.ts +29 -28
  19. package/src/index.ts +2 -1
  20. package/src/modules.d.ts +11 -0
  21. package/src/mud.ts +10 -4
  22. package/src/render-ts/recsV1TableOptions.ts +4 -4
  23. package/src/render-ts/renderRecsV1Tables.ts +3 -3
  24. package/src/render-ts/schemaTypesToRecsTypeStrings.ts +33 -33
  25. package/src/render-ts/tsgen.ts +4 -4
  26. package/src/utils/{deploy-v2.ts → deploy.ts} +207 -123
  27. package/src/utils/deployHandler.ts +87 -0
  28. package/src/utils/errors.ts +1 -1
  29. package/src/utils/getExistingContracts.ts +12 -0
  30. package/src/utils/index.ts +7 -5
  31. package/src/utils/printMUD.ts +14 -0
  32. package/src/utils/worldtypes.ts +21 -0
  33. package/dist/chunk-6V563IAZ.js +0 -283
  34. package/dist/chunk-FPG73MVN.js +0 -71
  35. package/dist/chunk-L4YLJHLJ.js +0 -30
  36. package/dist/chunk-SKNB74MT.js +0 -726
  37. package/dist/chunk-T2YHSEJD.js +0 -3842
  38. package/dist/chunk-VQTZJIFF.js +0 -353
  39. package/dist/chunk-WZFXLDPK.js +0 -761
  40. package/dist/chunk-YL4GJLLL.js +0 -26139
  41. package/dist/index.d.ts +0 -2
  42. package/dist/mud.d.ts +0 -1
  43. package/dist/mud2.d.ts +0 -1
  44. package/dist/mud2.js +0 -25
  45. package/dist/render-solidity/index.d.ts +0 -171
  46. package/dist/render-solidity/index.js +0 -49
  47. package/dist/render-ts/index.d.ts +0 -26
  48. package/dist/render-ts/index.js +0 -14
  49. package/dist/utils/deprecated/index.d.ts +0 -76
  50. package/dist/utils/deprecated/index.js +0 -36
  51. package/dist/utils/index.d.ts +0 -88
  52. package/dist/utils/index.js +0 -39
  53. package/src/commands/deploy-v2.ts +0 -112
  54. package/src/commands/deprecated/bulkupload.ts +0 -50
  55. package/src/commands/deprecated/call-system.ts +0 -70
  56. package/src/commands/deprecated/codegen-libdeploy.ts +0 -29
  57. package/src/commands/deprecated/deploy-contracts.ts +0 -120
  58. package/src/commands/deprecated/index.ts +0 -22
  59. package/src/commands/deprecated/system-types.ts +0 -29
  60. package/src/commands/deprecated/test.ts +0 -53
  61. package/src/commands/deprecated/trace.ts +0 -81
  62. package/src/commands/deprecated/types.ts +0 -33
  63. package/src/commands/gas-report.ts +0 -219
  64. package/src/contracts/BulkUpload.sol +0 -174
  65. package/src/contracts/Deploy.sol +0 -23
  66. package/src/contracts/LibDeploy.ejs +0 -121
  67. package/src/contracts/LibDeploy.sol +0 -23
  68. package/src/contracts/LibDeployStub.sol +0 -23
  69. package/src/mud2.ts +0 -29
  70. package/src/render-solidity/common.ts +0 -138
  71. package/src/render-solidity/field.ts +0 -160
  72. package/src/render-solidity/index.ts +0 -10
  73. package/src/render-solidity/record.ts +0 -158
  74. package/src/render-solidity/renderSystemInterface.ts +0 -31
  75. package/src/render-solidity/renderTable.ts +0 -164
  76. package/src/render-solidity/renderTableIndex.ts +0 -15
  77. package/src/render-solidity/renderTypeHelpers.ts +0 -99
  78. package/src/render-solidity/renderTypes.ts +0 -19
  79. package/src/render-solidity/renderTypesFromConfig.ts +0 -13
  80. package/src/render-solidity/renderWorld.ts +0 -24
  81. package/src/render-solidity/tableOptions.ts +0 -107
  82. package/src/render-solidity/tablegen.ts +0 -35
  83. package/src/render-solidity/types.ts +0 -111
  84. package/src/render-solidity/userType.ts +0 -131
  85. package/src/render-solidity/worldgen.ts +0 -59
  86. package/src/utils/contractToInterface.ts +0 -132
  87. package/src/utils/deprecated/build.ts +0 -55
  88. package/src/utils/deprecated/codegen.ts +0 -42
  89. package/src/utils/deprecated/constants.ts +0 -2
  90. package/src/utils/deprecated/deploy.ts +0 -111
  91. package/src/utils/deprecated/exec.ts +0 -18
  92. package/src/utils/deprecated/findLog.ts +0 -8
  93. package/src/utils/deprecated/hsr.ts +0 -71
  94. package/src/utils/deprecated/ids.ts +0 -14
  95. package/src/utils/deprecated/index.ts +0 -8
  96. package/src/utils/deprecated/typegen.ts +0 -133
  97. package/src/utils/execLog.ts +0 -22
  98. package/src/utils/format.ts +0 -39
  99. package/src/utils/formatAndWrite.ts +0 -21
  100. package/src/utils/foundry.ts +0 -103
package/dist/index.d.ts DELETED
@@ -1,2 +0,0 @@
1
-
2
- export { }
package/dist/mud.d.ts DELETED
@@ -1 +0,0 @@
1
- #!/usr/bin/env node
package/dist/mud2.d.ts DELETED
@@ -1 +0,0 @@
1
- #!/usr/bin/env node
package/dist/mud2.js DELETED
@@ -1,25 +0,0 @@
1
- #!/usr/bin/env node
2
- import {
3
- commands
4
- } from "./chunk-T2YHSEJD.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,171 +0,0 @@
1
- import { StoreConfig } from '@latticexyz/config';
2
- import { SchemaType } from '@latticexyz/schema-type';
3
-
4
- interface RenderTableOptions {
5
- /** List of symbols to import, and their file paths */
6
- imports: ImportDatum[];
7
- /** Name of the library to render. */
8
- libraryName: string;
9
- /** Name of the struct to render. If undefined, struct and its methods aren't rendered. */
10
- structName?: string;
11
- /** Data used to statically registed the table. If undefined, all methods receive `_tableId` as an argument. */
12
- staticResourceData?: StaticResourceData;
13
- /** Path for store package imports */
14
- storeImportPath: string;
15
- primaryKeys: RenderTablePrimaryKey[];
16
- fields: RenderTableField[];
17
- staticFields: RenderTableStaticField[];
18
- dynamicFields: RenderTableDynamicField[];
19
- /** Whether to render get/set methods for the whole record */
20
- withRecordMethods: boolean;
21
- /** Whether to render additional methods that accept a manual `IStore` argument */
22
- storeArgument: boolean;
23
- }
24
- interface ImportDatum {
25
- symbol: string;
26
- fromPath: string;
27
- usedInPath: string;
28
- }
29
- interface StaticResourceData {
30
- /** Name of the table id constant to render. */
31
- tableIdName: string;
32
- namespace: string;
33
- name: string;
34
- }
35
- interface RenderTableType {
36
- typeId: string;
37
- typeWithLocation: string;
38
- /** The name of the enum element in SchemaType to use for schema registration (e.g. "UINT256_ARRAY") */
39
- enumName: string;
40
- staticByteLength: number;
41
- isDynamic: boolean;
42
- /** Empty for internal types. Custom `wrap` method for user defined types. */
43
- typeWrap: string;
44
- /** Empty for internal types. Custom `unwrap` method for user defined types. */
45
- typeUnwrap: string;
46
- /** Data to generate the custom wrapper and unwrapper if necessary. */
47
- typeWrappingData?: RenderTableTypeWrappingData;
48
- /** Same as typeId for internal types. The underlying `typeId` for user defined types. */
49
- internalTypeId: string;
50
- }
51
- type RenderTableTypeWrappingData = {
52
- kind: "staticArray";
53
- elementType: string;
54
- staticLength: number;
55
- };
56
- interface RenderTablePrimaryKey extends RenderTableType {
57
- name: string;
58
- isDynamic: false;
59
- }
60
- interface RenderTableStaticField extends RenderTableField {
61
- isDynamic: false;
62
- }
63
- interface RenderTableDynamicField extends RenderTableField {
64
- isDynamic: true;
65
- }
66
- interface RenderTableField extends RenderTableType {
67
- arrayElement: RenderTableType | undefined;
68
- name: string;
69
- methodNameSuffix: string;
70
- }
71
- interface RenderTypesOptions {
72
- /** List of enums to render */
73
- enums: RenderTypesEnum[];
74
- }
75
- interface RenderTypesEnum {
76
- name: string;
77
- memberNames: string[];
78
- }
79
- interface RenderSystemInterfaceOptions {
80
- /** List of symbols to import, and their file paths */
81
- imports: ImportDatum[];
82
- name: string;
83
- functionPrefix: string;
84
- functions: RenderSystemInterfaceFunction[];
85
- }
86
- interface RenderSystemInterfaceFunction {
87
- name: string;
88
- parameters: string[];
89
- stateMutability: string;
90
- returnParameters: string[];
91
- }
92
- interface RenderWorldOptions {
93
- /** List of symbols to import, and their file paths */
94
- imports: ImportDatum[];
95
- /** Name of the interface to render */
96
- interfaceName: string;
97
- /** Path for store package imports */
98
- storeImportPath: string;
99
- /** Path for world package imports */
100
- worldImportPath: string;
101
- }
102
-
103
- declare const renderedSolidityHeader = "// SPDX-License-Identifier: MIT\npragma solidity >=0.8.0;\n\n/* Autogenerated file. Do not edit manually. */";
104
- /**
105
- * Renders a list of lines
106
- */
107
- declare function renderList<T>(list: T[], renderItem: (item: T, index: number) => string): string;
108
- /**
109
- * Renders a comma-separated list of arguments for solidity functions, ignoring empty and undefined ones
110
- */
111
- declare function renderArguments(args: (string | undefined)[]): string;
112
- declare function renderCommonData({ staticResourceData, primaryKeys, }: Pick<RenderTableOptions, "staticResourceData" | "primaryKeys">): {
113
- _tableId: string;
114
- _typedTableId: string;
115
- _keyArgs: string;
116
- _typedKeyArgs: string;
117
- _primaryKeysDefinition: string;
118
- };
119
- /** For 2 paths which are relative to a common root, create a relative import path from one to another */
120
- declare function solidityRelativeImportPath(fromPath: string, usedInPath: string): string;
121
- /**
122
- * Aggregates, deduplicates and renders imports for symbols per path.
123
- * Identical symbols from different paths are NOT handled, they should be checked before rendering.
124
- */
125
- declare function renderImports(imports: ImportDatum[]): string;
126
- declare function renderWithStore(storeArgument: boolean, callback: (_typedStore: string | undefined, _store: string, _commentSuffix: string, _untypedStore: string | undefined) => string): string;
127
- declare function renderTableId(staticResourceData: StaticResourceData): {
128
- hardcodedTableId: string;
129
- tableIdDefinition: string;
130
- };
131
-
132
- declare function renderFieldMethods(options: RenderTableOptions): string;
133
- declare function renderEncodeField(field: RenderTableField): string;
134
- declare function renderDecodeValueType(field: RenderTableType, offset: number): string;
135
-
136
- declare function renderRecordMethods(options: RenderTableOptions): string;
137
-
138
- declare function renderTable(options: RenderTableOptions): string;
139
-
140
- declare function renderTypes(options: RenderTypesOptions): string;
141
-
142
- declare function renderTypesFromConfig(config: StoreConfig): string;
143
-
144
- declare function tablegen(config: StoreConfig, outputBaseDirectory: string): Promise<void>;
145
-
146
- interface TableOptions {
147
- outputPath: string;
148
- tableName: string;
149
- renderOptions: RenderTableOptions;
150
- }
151
- declare function getTableOptions(config: StoreConfig): TableOptions[];
152
-
153
- type UserTypeInfo = ReturnType<typeof getUserTypeInfo>;
154
- /**
155
- * Resolve an abi or user type into a SchemaType
156
- */
157
- declare function resolveAbiOrUserType(abiOrUserType: string, config: StoreConfig): {
158
- schemaType: SchemaType;
159
- renderTableType: RenderTableType;
160
- };
161
- /**
162
- * Get the required import for SchemaType|userType (`undefined` means that no import is required)
163
- */
164
- declare function importForAbiOrUserType(abiOrUserType: string, usedInDirectory: string, config: StoreConfig): ImportDatum | undefined;
165
- declare function getSchemaTypeInfo(schemaType: SchemaType): RenderTableType;
166
- declare function getUserTypeInfo(userType: string, config: StoreConfig): {
167
- schemaType: SchemaType;
168
- renderTableType: RenderTableType;
169
- };
170
-
171
- export { ImportDatum, RenderSystemInterfaceFunction, RenderSystemInterfaceOptions, RenderTableDynamicField, RenderTableField, RenderTableOptions, RenderTablePrimaryKey, RenderTableStaticField, RenderTableType, RenderTableTypeWrappingData, RenderTypesEnum, RenderTypesOptions, RenderWorldOptions, StaticResourceData, TableOptions, UserTypeInfo, getSchemaTypeInfo, getTableOptions, getUserTypeInfo, importForAbiOrUserType, renderArguments, renderCommonData, renderDecodeValueType, renderEncodeField, renderFieldMethods, renderImports, renderList, renderRecordMethods, renderTable, renderTableId, renderTypes, renderTypesFromConfig, renderWithStore, renderedSolidityHeader, resolveAbiOrUserType, solidityRelativeImportPath, tablegen };
@@ -1,49 +0,0 @@
1
- import {
2
- getTableOptions,
3
- renderArguments,
4
- renderCommonData,
5
- renderDecodeValueType,
6
- renderEncodeField,
7
- renderFieldMethods,
8
- renderImports,
9
- renderList,
10
- renderRecordMethods,
11
- renderTable,
12
- renderTableId,
13
- renderTypes,
14
- renderTypesFromConfig,
15
- renderWithStore,
16
- renderedSolidityHeader,
17
- solidityRelativeImportPath,
18
- tablegen
19
- } from "../chunk-WZFXLDPK.js";
20
- import {
21
- getSchemaTypeInfo,
22
- getUserTypeInfo,
23
- importForAbiOrUserType,
24
- resolveAbiOrUserType
25
- } from "../chunk-SKNB74MT.js";
26
- import "../chunk-L4YLJHLJ.js";
27
- export {
28
- getSchemaTypeInfo,
29
- getTableOptions,
30
- getUserTypeInfo,
31
- importForAbiOrUserType,
32
- renderArguments,
33
- renderCommonData,
34
- renderDecodeValueType,
35
- renderEncodeField,
36
- renderFieldMethods,
37
- renderImports,
38
- renderList,
39
- renderRecordMethods,
40
- renderTable,
41
- renderTableId,
42
- renderTypes,
43
- renderTypesFromConfig,
44
- renderWithStore,
45
- renderedSolidityHeader,
46
- resolveAbiOrUserType,
47
- solidityRelativeImportPath,
48
- tablegen
49
- };
@@ -1,26 +0,0 @@
1
- import { StoreConfig } from '@latticexyz/config';
2
- import { SchemaType } from '@latticexyz/schema-type';
3
-
4
- interface RecsV1TableOptions {
5
- tables: {
6
- tableName: string;
7
- fields: {
8
- recsTypeString: string;
9
- name: string;
10
- }[];
11
- staticResourceData: {
12
- namespace: string;
13
- name: string;
14
- };
15
- }[];
16
- }
17
-
18
- declare function getRecsV1TableOptions(config: StoreConfig): RecsV1TableOptions;
19
-
20
- declare function renderRecsV1Tables(options: RecsV1TableOptions): string;
21
-
22
- declare const schemaTypesToRecsTypeStrings: Record<SchemaType, string>;
23
-
24
- declare function tsgen(config: StoreConfig, outDirectory: string): Promise<void>;
25
-
26
- export { RecsV1TableOptions, getRecsV1TableOptions, renderRecsV1Tables, schemaTypesToRecsTypeStrings, tsgen };
@@ -1,14 +0,0 @@
1
- import {
2
- getRecsV1TableOptions,
3
- renderRecsV1Tables,
4
- schemaTypesToRecsTypeStrings,
5
- tsgen
6
- } from "../chunk-6V563IAZ.js";
7
- import "../chunk-SKNB74MT.js";
8
- import "../chunk-L4YLJHLJ.js";
9
- export {
10
- getRecsV1TableOptions,
11
- renderRecsV1Tables,
12
- schemaTypesToRecsTypeStrings,
13
- tsgen
14
- };
@@ -1,76 +0,0 @@
1
- import * as 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
- declare function execLog(command: string, options: string[]): execa.ExecaChildProcess<string>;
10
-
11
- declare const IDregex: RegExp;
12
- declare function extractIdFromFile(path: string): string | null;
13
- declare function keccak256(data: string): string;
14
-
15
- /**
16
- * Generate LibDeploy.sol from deploy.json
17
- * @param configPath path to deploy.json
18
- * @param out output directory for LibDeploy.sol
19
- * @param systems optional, only generate deploy code for the given systems
20
- * @returns path to generated LibDeploy.sol
21
- */
22
- declare function generateLibDeploy(configPath: string, out: string, systems?: string | string[]): Promise<string>;
23
- declare function resetLibDeploy(out: string): Promise<void>;
24
-
25
- /**
26
- * Deploy world, components and systems from deploy.json
27
- * @param deployerPrivateKey private key of deployer
28
- * @param rpc rpc url
29
- * @param worldAddress optional, address of existing world
30
- * @param reuseComponents optional, reuse existing components
31
- * @returns address of deployed world
32
- */
33
- declare function deploy(deployerPrivateKey?: string, rpc?: string, worldAddress?: string, reuseComponents?: boolean, gasPrice?: number): Promise<{
34
- child: execa.ExecaReturnValue<string>;
35
- deployedWorldAddress: string;
36
- initialBlockNumber: string;
37
- }>;
38
- type DeployOptions = {
39
- config: string;
40
- deployerPrivateKey?: string;
41
- worldAddress?: string;
42
- rpc: string;
43
- systems?: string | string[];
44
- reuseComponents?: boolean;
45
- clear?: boolean;
46
- gasPrice?: number;
47
- };
48
- declare function generateAndDeploy(args: DeployOptions): Promise<{
49
- deployedWorldAddress: string;
50
- initialBlockNumber: string;
51
- }>;
52
-
53
- declare function hsr(root: string, replaceSystems: (systems: string[]) => Promise<unknown>): void;
54
-
55
- declare function findLog(deployLogLines: string[], log: string): string;
56
-
57
- declare function generateAbiTypes(inputDir: string, outputDir: string, options?: {
58
- clear?: boolean;
59
- cwd?: string;
60
- }): Promise<void>;
61
- declare function generateSystemTypes(outputDir: string, options?: {
62
- clear?: boolean;
63
- }): Promise<void>;
64
- /**
65
- * @param abiDir If not provided, the contracts are built and abis are exported to ./abi
66
- */
67
- declare function generateTypes(abiDir?: string, outputDir?: string, options?: {
68
- clear?: boolean;
69
- }): Promise<void>;
70
-
71
- declare function forgeBuild(options?: {
72
- clear?: boolean;
73
- }): Promise<string>;
74
- declare function filterAbi(abiIn?: string, abiOut?: string, exclude?: string[]): void;
75
-
76
- export { DeployOptions, IDregex, deploy, execLog, extractIdFromFile, filterAbi, findLog, forgeBuild, generateAbiTypes, generateAndDeploy, generateLibDeploy, generateSystemTypes, generateTypes, hsr, keccak256, resetLibDeploy };
@@ -1,36 +0,0 @@
1
- import {
2
- IDregex,
3
- deploy,
4
- execLog,
5
- extractIdFromFile,
6
- filterAbi,
7
- findLog,
8
- forgeBuild,
9
- generateAbiTypes,
10
- generateAndDeploy,
11
- generateLibDeploy,
12
- generateSystemTypes,
13
- generateTypes,
14
- hsr,
15
- keccak256,
16
- resetLibDeploy
17
- } from "../../chunk-VQTZJIFF.js";
18
- import "../../chunk-FPG73MVN.js";
19
- import "../../chunk-L4YLJHLJ.js";
20
- export {
21
- IDregex,
22
- deploy,
23
- execLog,
24
- extractIdFromFile,
25
- filterAbi,
26
- findLog,
27
- forgeBuild,
28
- generateAbiTypes,
29
- generateAndDeploy,
30
- generateLibDeploy,
31
- generateSystemTypes,
32
- generateTypes,
33
- hsr,
34
- keccak256,
35
- resetLibDeploy
36
- };
@@ -1,88 +0,0 @@
1
- import { MUDConfig } from '@latticexyz/config';
2
-
3
- declare function logError(error: unknown): void;
4
-
5
- interface ForgeConfig {
6
- src: string;
7
- test: string;
8
- script: string;
9
- out: string;
10
- libs: string[];
11
- eth_rpc_url: string | null;
12
- [key: string]: unknown;
13
- }
14
- /**
15
- * Get forge config as a parsed json object.
16
- */
17
- declare function getForgeConfig(profile?: string): Promise<ForgeConfig>;
18
- /**
19
- * Get the value of "src" from forge config.
20
- * The path to the contract sources relative to the root of the project.
21
- */
22
- declare function getSrcDirectory(profile?: string): Promise<string>;
23
- /**
24
- * Get the value of "script" from forge config.
25
- * The path to the contract sources relative to the root of the project.
26
- */
27
- declare function getScriptDirectory(profile?: string): Promise<string>;
28
- /**
29
- * Get the value of "test" from forge config.
30
- * The path to the test contract sources relative to the root of the project.
31
- */
32
- declare function getTestDirectory(profile?: string): Promise<string>;
33
- /**
34
- * Get the value of "out" from forge config.
35
- * The path to put contract artifacts in, relative to the root of the project.
36
- */
37
- declare function getOutDirectory(profile?: string): Promise<string>;
38
- /**
39
- * Get the value of "eth_rpc_url" from forge config, default to "http://127.0.0.1:8545"
40
- * @param profile The foundry profile to use
41
- * @returns The rpc url
42
- */
43
- declare function getRpcUrl(profile?: string): Promise<string>;
44
- /**
45
- * Execute a forge command
46
- * @param args The arguments to pass to forge
47
- * @param options { profile?: The foundry profile to use; silent?: If true, nothing will be logged to the console }
48
- */
49
- declare function forge(args: string[], options?: {
50
- profile?: string;
51
- silent?: boolean;
52
- }): Promise<void>;
53
- /**
54
- * Execute a cast command
55
- * @param args The arguments to pass to cast
56
- * @returns Stdout of the command
57
- */
58
- declare function cast(args: string[], options?: {
59
- profile?: string;
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>;
67
-
68
- declare function formatSolidity(content: string, prettierConfigPath?: string): Promise<string>;
69
- declare function formatTypescript(content: string): Promise<string>;
70
-
71
- declare function formatAndWriteSolidity(output: string, fullOutputPath: string, logPrefix: string): Promise<void>;
72
- declare function formatAndWriteTypescript(output: string, fullOutputPath: string, logPrefix: string): Promise<void>;
73
-
74
- interface DeployConfig {
75
- profile?: string;
76
- rpc: string;
77
- privateKey: string;
78
- priorityFeeMultiplier: number;
79
- debug?: boolean;
80
- worldAddress?: string;
81
- }
82
- interface DeploymentInfo {
83
- blockNumber: number;
84
- worldAddress: string;
85
- }
86
- declare function deploy(mudConfig: MUDConfig, deployConfig: DeployConfig): Promise<DeploymentInfo>;
87
-
88
- export { DeployConfig, DeploymentInfo, ForgeConfig, anvil, cast, deploy, forge, formatAndWriteSolidity, formatAndWriteTypescript, formatSolidity, formatTypescript, getForgeConfig, getOutDirectory, getRpcUrl, getScriptDirectory, getSrcDirectory, getTestDirectory, logError };
@@ -1,39 +0,0 @@
1
- import {
2
- deploy,
3
- logError
4
- } from "../chunk-YL4GJLLL.js";
5
- import {
6
- anvil,
7
- cast,
8
- forge,
9
- getForgeConfig,
10
- getOutDirectory,
11
- getRpcUrl,
12
- getScriptDirectory,
13
- getSrcDirectory,
14
- getTestDirectory
15
- } from "../chunk-FPG73MVN.js";
16
- import {
17
- formatAndWriteSolidity,
18
- formatAndWriteTypescript,
19
- formatSolidity,
20
- formatTypescript
21
- } from "../chunk-SKNB74MT.js";
22
- import "../chunk-L4YLJHLJ.js";
23
- export {
24
- anvil,
25
- cast,
26
- deploy,
27
- forge,
28
- formatAndWriteSolidity,
29
- formatAndWriteTypescript,
30
- formatSolidity,
31
- formatTypescript,
32
- getForgeConfig,
33
- getOutDirectory,
34
- getRpcUrl,
35
- getScriptDirectory,
36
- getSrcDirectory,
37
- getTestDirectory,
38
- logError
39
- };
@@ -1,112 +0,0 @@
1
- import chalk from "chalk";
2
- import glob from "glob";
3
- import path, { basename } from "path";
4
- import type { CommandModule, Options } from "yargs";
5
- import { loadStoreConfig, loadWorldConfig } from "@latticexyz/config";
6
- import { MUDError } from "@latticexyz/config";
7
- import { deploy } from "../utils/deploy-v2.js";
8
- import { logError } from "../utils/errors.js";
9
- import { forge, getRpcUrl, getSrcDirectory } from "../utils/foundry.js";
10
- import { mkdirSync, writeFileSync } from "fs";
11
- import { getChainId } from "../utils/getChainId.js";
12
-
13
- export type DeployOptions = {
14
- configPath?: string;
15
- printConfig?: boolean;
16
- profile?: string;
17
- priorityFeeMultiplier: number;
18
- clean?: boolean;
19
- debug?: boolean;
20
- saveDeployment?: boolean;
21
- rpc?: string;
22
- worldAddress?: string;
23
- srcDir?: string;
24
- };
25
-
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,
36
- },
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) {
79
- // Write deployment result to file (latest and timestamp)
80
- const chainId = await getChainId(rpc);
81
- const outputDir = path.join(mudConfig.deploysDirectory, chainId.toString());
82
- mkdirSync(outputDir, { recursive: true });
83
- writeFileSync(path.join(outputDir, "latest.json"), JSON.stringify(deploymentInfo, null, 2));
84
- writeFileSync(path.join(outputDir, Date.now() + ".json"), JSON.stringify(deploymentInfo, null, 2));
85
-
86
- console.log(chalk.bgGreen(chalk.whiteBright(`\n Deployment result (written to ${outputDir}): \n`)));
87
- }
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);
108
- process.exit(0);
109
- },
110
- };
111
-
112
- export default commandModule;