@latticexyz/cli 1.41.0 → 1.41.1-alpha.41

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 (53) hide show
  1. package/dist/{chunk-GR245KYP.js → chunk-J4DJQNIC.js} +679 -133
  2. package/dist/chunk-O57QENJ6.js +23039 -0
  3. package/dist/config/index.d.ts +610 -296
  4. package/dist/config/index.js +49 -26
  5. package/dist/index.d.ts +2 -110
  6. package/dist/index.js +9 -50
  7. package/dist/mud.js +937 -57
  8. package/dist/utils/index.d.ts +92 -4
  9. package/dist/utils/index.js +2 -3
  10. package/package.json +10 -9
  11. package/src/commands/deploy-v2.ts +11 -15
  12. package/src/commands/index.ts +2 -0
  13. package/src/commands/worldgen.ts +55 -0
  14. package/src/config/commonSchemas.ts +11 -13
  15. package/src/config/dynamicResolution.ts +49 -0
  16. package/src/config/index.ts +15 -3
  17. package/src/config/loadStoreConfig.ts +1 -1
  18. package/src/config/parseStoreConfig.test-d.ts +31 -5
  19. package/src/config/parseStoreConfig.ts +218 -78
  20. package/src/config/validation.ts +25 -0
  21. package/src/config/world/index.ts +4 -0
  22. package/src/config/{loadWorldConfig.test-d.ts → world/loadWorldConfig.test-d.ts} +3 -3
  23. package/src/config/world/loadWorldConfig.ts +26 -0
  24. package/src/config/world/parseWorldConfig.ts +55 -0
  25. package/src/config/world/resolveWorldConfig.ts +80 -0
  26. package/src/config/world/userTypes.ts +72 -0
  27. package/src/index.ts +4 -6
  28. package/src/render-solidity/common.ts +51 -6
  29. package/src/render-solidity/field.ts +40 -44
  30. package/src/render-solidity/index.ts +5 -1
  31. package/src/render-solidity/record.ts +56 -73
  32. package/src/render-solidity/renderSystemInterface.ts +31 -0
  33. package/src/render-solidity/renderTable.ts +98 -70
  34. package/src/render-solidity/renderTypeHelpers.ts +99 -0
  35. package/src/render-solidity/renderTypesFromConfig.ts +2 -2
  36. package/src/render-solidity/renderWorld.ts +24 -0
  37. package/src/render-solidity/{renderTablesFromConfig.ts → tableOptions.ts} +28 -30
  38. package/src/render-solidity/tablegen.ts +20 -22
  39. package/src/render-solidity/types.ts +39 -5
  40. package/src/render-solidity/userType.ts +80 -48
  41. package/src/render-solidity/worldgen.ts +60 -0
  42. package/src/utils/contractToInterface.ts +130 -0
  43. package/src/utils/deploy-v2.ts +268 -101
  44. package/src/utils/formatAndWrite.ts +12 -0
  45. package/src/utils/getChainId.ts +10 -0
  46. package/src/utils/typeUtils.ts +17 -0
  47. package/dist/chunk-AER7UDD4.js +0 -0
  48. package/dist/chunk-XRS7KWBZ.js +0 -547
  49. package/dist/chunk-YZATC2M3.js +0 -397
  50. package/dist/chunk-ZYDMYSTH.js +0 -1178
  51. package/dist/deploy-v2-b7b3207d.d.ts +0 -92
  52. package/src/config/loadWorldConfig.ts +0 -178
  53. package/src/constants.ts +0 -1
@@ -1,92 +0,0 @@
1
- import { ZodError, z } from 'zod';
2
- import { ValidationError } from 'zod-validation-error';
3
- import { MUDConfig } from './config/index.js';
4
-
5
- declare function fromZodErrorCustom(error: ZodError, prefix: string): ValidationError;
6
- declare class NotInsideProjectError extends Error {
7
- name: string;
8
- message: string;
9
- }
10
- declare class NotESMConfigError extends Error {
11
- name: string;
12
- message: string;
13
- }
14
- declare class MUDError extends Error {
15
- name: string;
16
- }
17
- declare function UnrecognizedSystemErrorFactory(path: string[], systemName: string): z.ZodError<any>;
18
- declare function logError(error: unknown): void;
19
-
20
- interface ForgeConfig {
21
- src: string;
22
- test: string;
23
- script: string;
24
- out: string;
25
- libs: string[];
26
- eth_rpc_url: string | null;
27
- [key: string]: unknown;
28
- }
29
- /**
30
- * Get forge config as a parsed json object.
31
- */
32
- declare function getForgeConfig(profile?: string): Promise<ForgeConfig>;
33
- /**
34
- * Get the value of "src" from forge config.
35
- * The path to the contract sources relative to the root of the project.
36
- */
37
- declare function getSrcDirectory(profile?: string): Promise<string>;
38
- /**
39
- * Get the value of "script" from forge config.
40
- * The path to the contract sources relative to the root of the project.
41
- */
42
- declare function getScriptDirectory(profile?: string): Promise<string>;
43
- /**
44
- * Get the value of "test" from forge config.
45
- * The path to the test contract sources relative to the root of the project.
46
- */
47
- declare function getTestDirectory(profile?: string): Promise<string>;
48
- /**
49
- * Get the value of "out" from forge config.
50
- * The path to put contract artifacts in, relative to the root of the project.
51
- */
52
- declare function getOutDirectory(profile?: string): Promise<string>;
53
- /**
54
- * Get the value of "eth_rpc_url" from forge config, default to "http://127.0.0.1:8545"
55
- * @param profile The foundry profile to use
56
- * @returns The rpc url
57
- */
58
- declare function getRpcUrl(profile?: string): Promise<string>;
59
- /**
60
- * Execute a forge command
61
- * @param args The arguments to pass to forge
62
- * @param options { profile?: The foundry profile to use; silent?: If true, nothing will be logged to the console }
63
- */
64
- declare function forge(args: string[], options?: {
65
- profile?: string;
66
- silent?: boolean;
67
- }): Promise<void>;
68
- /**
69
- * Execute a cast command
70
- * @param args The arguments to pass to cast
71
- * @returns Stdout of the command
72
- */
73
- declare function cast(args: string[], options?: {
74
- profile?: string;
75
- }): Promise<string>;
76
-
77
- declare function formatSolidity(content: string, prettierConfigPath?: string): Promise<string>;
78
-
79
- interface DeployConfig {
80
- profile?: string;
81
- rpc: string;
82
- privateKey: string;
83
- priorityFeeMultiplier: number;
84
- }
85
- interface DeploymentInfo {
86
- blockNumber: number;
87
- worldAddress: string;
88
- rpc: string;
89
- }
90
- declare function deploy(mudConfig: MUDConfig, deployConfig: DeployConfig): Promise<DeploymentInfo>;
91
-
92
- export { DeployConfig as D, ForgeConfig as F, MUDError as M, NotInsideProjectError as N, UnrecognizedSystemErrorFactory as U, NotESMConfigError as a, getSrcDirectory as b, getScriptDirectory as c, getTestDirectory as d, getOutDirectory as e, fromZodErrorCustom as f, getForgeConfig as g, getRpcUrl as h, forge as i, cast as j, formatSolidity as k, logError as l, DeploymentInfo as m, deploy as n };
@@ -1,178 +0,0 @@
1
- import { z, ZodError } from "zod";
2
- import { fromZodErrorCustom, UnrecognizedSystemErrorFactory } from "../utils/errors.js";
3
- import { BaseRoute, EthereumAddress, ObjectName } from "./commonSchemas.js";
4
- import { loadConfig } from "./loadConfig.js";
5
-
6
- const SystemName = ObjectName;
7
- const SystemRoute = BaseRoute.optional();
8
- const SystemAccessList = z.array(SystemName.or(EthereumAddress)).default([]);
9
-
10
- // The system config is a combination of a route config and access config
11
- const SystemConfig = z.intersection(
12
- z.object({
13
- route: SystemRoute,
14
- }),
15
- z.discriminatedUnion("openAccess", [
16
- z.object({
17
- openAccess: z.literal(true),
18
- }),
19
- z.object({
20
- openAccess: z.literal(false),
21
- accessList: SystemAccessList,
22
- }),
23
- ])
24
- );
25
-
26
- // The parsed world config is the result of parsing the user config
27
- export const WorldConfig = z.object({
28
- baseRoute: BaseRoute.default(""),
29
- worldContractName: z.string().optional(),
30
- overrideSystems: z.record(SystemName, SystemConfig).default({}),
31
- excludeSystems: z.array(SystemName).default([]),
32
- postDeployScript: z.string().default("PostDeploy"),
33
- deploymentInfoDirectory: z.string().default("."),
34
- });
35
-
36
- /**
37
- * Resolves the system config by combining the default and overridden system configs,
38
- * @param systemName name of the system
39
- * @param config optional SystemConfig object, if none is provided the default config is used
40
- * @param existingContracts optional list of existing contract names, used to validate system names in the access list. If not provided, no validation is performed.
41
- * @returns ResolvedSystemConfig object
42
- * Default value for route is `/${systemName}`
43
- * Default value for openAccess is true
44
- * Default value for accessListAddresses is []
45
- * Default value for accessListSystems is []
46
- */
47
- export function resolveSystemConfig(systemName: string, config?: SystemUserConfig, existingContracts?: string[]) {
48
- const route = config?.route ?? `/${systemName}`;
49
- const openAccess = config?.openAccess ?? true;
50
- const accessListAddresses: string[] = [];
51
- const accessListSystems: string[] = [];
52
- const accessList = config && !config.openAccess ? config.accessList : [];
53
-
54
- // Split the access list into addresses and system names
55
- for (const accessListItem of accessList) {
56
- if (accessListItem.startsWith("0x")) {
57
- accessListAddresses.push(accessListItem);
58
- } else {
59
- // Validate every system refers to an existing system contract
60
- if (existingContracts && !existingContracts.includes(accessListItem)) {
61
- throw UnrecognizedSystemErrorFactory(["overrideSystems", systemName, "accessList"], accessListItem);
62
- }
63
- accessListSystems.push(accessListItem);
64
- }
65
- }
66
-
67
- return { route, openAccess, accessListAddresses, accessListSystems };
68
- }
69
-
70
- /**
71
- * Resolves the world config by combining the default and overridden system configs,
72
- * filtering out excluded systems, validate system names refer to existing contracts, and
73
- * splitting the access list into addresses and system names.
74
- */
75
- export function resolveWorldConfig(config: ParsedWorldConfig, existingContracts?: string[]) {
76
- // Include contract names ending in "System", but not the base "System" contract
77
- const defaultSystemNames = existingContracts?.filter((name) => name.endsWith("System") && name !== "System") ?? [];
78
- const overriddenSystemNames = Object.keys(config.overrideSystems);
79
-
80
- // Validate every key in overrideSystems refers to an existing system contract (and is not called "World")
81
- if (existingContracts) {
82
- for (const systemName of overriddenSystemNames) {
83
- if (!existingContracts.includes(systemName) || systemName === "World") {
84
- throw UnrecognizedSystemErrorFactory(["overrideSystems", systemName], systemName);
85
- }
86
- }
87
- }
88
-
89
- // Combine the default and overridden system names and filter out excluded systems
90
- const systemNames = [...new Set([...defaultSystemNames, ...overriddenSystemNames])].filter(
91
- (name) => !config.excludeSystems.includes(name)
92
- );
93
-
94
- // Resolve the config
95
- const resolvedSystems: Record<string, ResolvedSystemConfig> = systemNames.reduce((acc, systemName) => {
96
- return {
97
- ...acc,
98
- [systemName]: resolveSystemConfig(systemName, config.overrideSystems[systemName], existingContracts),
99
- };
100
- }, {});
101
-
102
- const { overrideSystems, excludeSystems, ...otherConfig } = config;
103
- return { ...otherConfig, systems: resolvedSystems };
104
- }
105
-
106
- /**
107
- * Loads and resolves the world config.
108
- * @param configPath Path to load the config from. Defaults to "mud.config.mts" or "mud.config.ts"
109
- * @param existingContracts Optional list of existing contract names to validate system names against. If not provided, no validation is performed. Contract names ending in `System` will be added to the config with default values.
110
- * @returns Promise of ResolvedWorldConfig object
111
- */
112
- export async function loadWorldConfig(configPath?: string, existingContracts?: string[]) {
113
- const config = await loadConfig(configPath);
114
-
115
- try {
116
- const parsedConfig = WorldConfig.parse(config);
117
- return resolveWorldConfig(parsedConfig, existingContracts);
118
- } catch (error) {
119
- if (error instanceof ZodError) {
120
- throw fromZodErrorCustom(error, "WorldConfig Validation Error");
121
- } else {
122
- throw error;
123
- }
124
- }
125
- }
126
-
127
- export async function parseWorldConfig(config: unknown) {
128
- return WorldConfig.parse(config);
129
- }
130
-
131
- // zod doesn't preserve doc comments
132
- export type SystemUserConfig =
133
- | {
134
- /** The system will be deployed at `baseRoute + route` */
135
- route?: string;
136
- } & (
137
- | {
138
- /** If openAccess is true, any address can call the system */
139
- openAccess: true;
140
- }
141
- | {
142
- /** If openAccess is false, only the addresses or systems in `access` can call the system */
143
- openAccess: false;
144
- /** An array of addresses or system names that can access the system */
145
- accessList: string[];
146
- }
147
- );
148
-
149
- // zod doesn't preserve doc comments
150
- export interface WorldUserConfig {
151
- /** The base route to register tables and systems at. Defaults to the root route (empty string) */
152
- baseRoute?: string;
153
- /** The name of the World contract to deploy. If no name is provided, a vanilla World is deployed */
154
- worldContractName?: string;
155
- /**
156
- * Contracts named *System will be deployed by default
157
- * as public systems at `baseRoute/ContractName`, unless overridden
158
- *
159
- * The key is the system name (capitalized).
160
- * The value is a SystemConfig object.
161
- */
162
- overrideSystems?: Record<string, SystemUserConfig>;
163
- /** Systems to exclude from automatic deployment */
164
- excludeSystems?: string[];
165
- /**
166
- * Script to execute after the deployment is complete (Default "PostDeploy").
167
- * Script must be placed in the forge scripts directory (see foundry.toml) and have a ".s.sol" extension.
168
- */
169
- postDeployScript?: string;
170
- /** Directory to write the deployment info to (Default ".") */
171
- deploymentInfoDirectory?: string;
172
- }
173
-
174
- export type ParsedWorldConfig = z.output<typeof WorldConfig>;
175
-
176
- export type ResolvedSystemConfig = ReturnType<typeof resolveSystemConfig>;
177
-
178
- export type ResolvedWorldConfig = ReturnType<typeof resolveWorldConfig>;
package/src/constants.ts DELETED
@@ -1 +0,0 @@
1
- export const deploymentInfoFilenamePrefix = "mud-deployment-";