@latticexyz/cli 2.0.0-main-257a0afc → 2.0.0-march-19-skystrife-playtest-f0a343b1

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 (45) hide show
  1. package/dist/commands-RZOPG5RM.js +27 -0
  2. package/dist/commands-RZOPG5RM.js.map +1 -0
  3. package/dist/mud.js +1 -1
  4. package/dist/mud.js.map +1 -1
  5. package/package.json +15 -17
  6. package/src/commands/deploy.ts +1 -1
  7. package/src/commands/dev-contracts.ts +1 -4
  8. package/src/commands/set-version.ts +1 -1
  9. package/src/commands/trace.ts +1 -1
  10. package/src/deploy/assertNamespaceOwner.ts +42 -0
  11. package/src/deploy/common.ts +2 -44
  12. package/src/deploy/configToTables.ts +3 -5
  13. package/src/deploy/create2/README.md +0 -4
  14. package/src/deploy/create2/deployment.json +1 -2
  15. package/src/deploy/deploy.ts +18 -43
  16. package/src/deploy/deployWorld.ts +4 -9
  17. package/src/deploy/ensureContract.ts +7 -12
  18. package/src/deploy/ensureContractsDeployed.ts +1 -9
  19. package/src/deploy/ensureDeployer.ts +22 -61
  20. package/src/deploy/ensureFunctions.ts +5 -5
  21. package/src/deploy/ensureModules.ts +10 -16
  22. package/src/deploy/ensureSystems.ts +83 -108
  23. package/src/deploy/ensureTables.ts +8 -7
  24. package/src/deploy/ensureWorldFactory.ts +37 -95
  25. package/src/deploy/getFunctions.ts +4 -4
  26. package/src/deploy/getResourceAccess.ts +2 -2
  27. package/src/deploy/getSystems.ts +7 -6
  28. package/src/deploy/getTables.ts +1 -1
  29. package/src/deploy/logsToWorldDeploy.ts +1 -1
  30. package/src/deploy/resolveConfig.ts +55 -52
  31. package/src/deploy/resourceLabel.ts +3 -0
  32. package/src/mud.ts +1 -1
  33. package/src/mudPackages.ts +1 -1
  34. package/src/runDeploy.ts +7 -34
  35. package/src/utils/{defaultModuleContracts.ts → modules/constants.ts} +0 -4
  36. package/src/utils/printMUD.ts +1 -1
  37. package/src/utils/{getContractData.ts → utils/getContractData.ts} +5 -11
  38. package/src/utils/{postDeploy.ts → utils/postDeploy.ts} +2 -2
  39. package/dist/commands-22M65L4E.js +0 -36
  40. package/dist/commands-22M65L4E.js.map +0 -1
  41. package/src/deploy/createPrepareDeploy.ts +0 -28
  42. package/src/deploy/ensureNamespaceOwner.ts +0 -71
  43. package/src/deploy/findLibraries.ts +0 -36
  44. package/src/deploy/orderByDependencies.ts +0 -12
  45. package/src/utils/findPlaceholders.ts +0 -27
@@ -29,7 +29,7 @@ export async function ensureFunctions({
29
29
  "found",
30
30
  wrongSystem.length,
31
31
  "functions already registered but pointing at a different system ID:",
32
- wrongSystem.map((func) => func.signature).join(", "),
32
+ wrongSystem.map((func) => func.signature).join(", ")
33
33
  );
34
34
  }
35
35
  }
@@ -50,7 +50,7 @@ export async function ensureFunctions({
50
50
  abi: worldAbi,
51
51
  // TODO: replace with batchCall (https://github.com/latticexyz/mud/issues/1645)
52
52
  functionName: "registerRootFunctionSelector",
53
- args: [func.systemId, func.systemFunctionSignature, func.systemFunctionSignature],
53
+ args: [func.systemId, func.systemFunctionSignature, func.systemFunctionSelector],
54
54
  }),
55
55
  {
56
56
  retries: 3,
@@ -59,7 +59,7 @@ export async function ensureFunctions({
59
59
  debug(`failed to register function ${func.signature}, retrying in ${delay}ms...`);
60
60
  await wait(delay);
61
61
  },
62
- },
62
+ }
63
63
  );
64
64
  }
65
65
  return pRetry(
@@ -79,8 +79,8 @@ export async function ensureFunctions({
79
79
  debug(`failed to register function ${func.signature}, retrying in ${delay}ms...`);
80
80
  await wait(delay);
81
81
  },
82
- },
82
+ }
83
83
  );
84
- }),
84
+ })
85
85
  );
86
86
  }
@@ -1,21 +1,17 @@
1
- import { Client, Transport, Chain, Account, Hex, BaseError } from "viem";
1
+ import { Client, Transport, Chain, Account, Hex, BaseError, getAddress } from "viem";
2
2
  import { writeContract } from "@latticexyz/common";
3
- import { Library, Module, WorldDeploy, worldAbi } from "./common";
3
+ import { Module, WorldDeploy, worldAbi } from "./common";
4
4
  import { debug } from "./debug";
5
- import { isDefined, wait } from "@latticexyz/common/utils";
5
+ import { isDefined, uniqueBy, wait } from "@latticexyz/common/utils";
6
6
  import pRetry from "p-retry";
7
7
  import { ensureContractsDeployed } from "./ensureContractsDeployed";
8
8
 
9
9
  export async function ensureModules({
10
10
  client,
11
- deployerAddress,
12
- libraries,
13
11
  worldDeploy,
14
12
  modules,
15
13
  }: {
16
14
  readonly client: Client<Transport, Chain | undefined, Account>;
17
- readonly deployerAddress: Hex;
18
- readonly libraries: readonly Library[];
19
15
  readonly worldDeploy: WorldDeploy;
20
16
  readonly modules: readonly Module[];
21
17
  }): Promise<readonly Hex[]> {
@@ -23,9 +19,8 @@ export async function ensureModules({
23
19
 
24
20
  await ensureContractsDeployed({
25
21
  client,
26
- deployerAddress,
27
- contracts: modules.map((mod) => ({
28
- bytecode: mod.prepareDeploy(deployerAddress, libraries).bytecode,
22
+ contracts: uniqueBy(modules, (mod) => getAddress(mod.address)).map((mod) => ({
23
+ bytecode: mod.bytecode,
29
24
  deployedBytecodeSize: mod.deployedBytecodeSize,
30
25
  label: `${mod.name} module`,
31
26
  })),
@@ -38,7 +33,6 @@ export async function ensureModules({
38
33
  pRetry(
39
34
  async () => {
40
35
  try {
41
- const moduleAddress = mod.prepareDeploy(deployerAddress, libraries).address;
42
36
  return mod.installAsRoot
43
37
  ? await writeContract(client, {
44
38
  chain: client.chain ?? null,
@@ -46,7 +40,7 @@ export async function ensureModules({
46
40
  abi: worldAbi,
47
41
  // TODO: replace with batchCall (https://github.com/latticexyz/mud/issues/1645)
48
42
  functionName: "installRootModule",
49
- args: [moduleAddress, mod.installData],
43
+ args: [mod.address, mod.installData],
50
44
  })
51
45
  : await writeContract(client, {
52
46
  chain: client.chain ?? null,
@@ -54,7 +48,7 @@ export async function ensureModules({
54
48
  abi: worldAbi,
55
49
  // TODO: replace with batchCall (https://github.com/latticexyz/mud/issues/1645)
56
50
  functionName: "installModule",
57
- args: [moduleAddress, mod.installData],
51
+ args: [mod.address, mod.installData],
58
52
  });
59
53
  } catch (error) {
60
54
  if (error instanceof BaseError && error.message.includes("Module_AlreadyInstalled")) {
@@ -71,9 +65,9 @@ export async function ensureModules({
71
65
  debug(`failed to install module ${mod.name}, retrying in ${delay}ms...`);
72
66
  await wait(delay);
73
67
  },
74
- },
75
- ),
76
- ),
68
+ }
69
+ )
70
+ )
77
71
  )
78
72
  ).filter(isDefined);
79
73
  }
@@ -1,25 +1,20 @@
1
- import { Client, Transport, Chain, Account, Hex, getAddress, Address } from "viem";
2
- import { writeContract, resourceToLabel } from "@latticexyz/common";
3
- import { Library, System, WorldDeploy, worldAbi } from "./common";
1
+ import { Client, Transport, Chain, Account, Hex, getAddress } from "viem";
2
+ import { writeContract } from "@latticexyz/common";
3
+ import { System, WorldDeploy, worldAbi } from "./common";
4
4
  import { debug } from "./debug";
5
+ import { resourceLabel } from "./resourceLabel";
5
6
  import { getSystems } from "./getSystems";
6
7
  import { getResourceAccess } from "./getResourceAccess";
7
- import { wait } from "@latticexyz/common/utils";
8
+ import { uniqueBy, wait } from "@latticexyz/common/utils";
8
9
  import pRetry from "p-retry";
9
10
  import { ensureContractsDeployed } from "./ensureContractsDeployed";
10
11
 
11
- // TODO: move each system registration+access to batch call to be atomic
12
-
13
12
  export async function ensureSystems({
14
13
  client,
15
- deployerAddress,
16
- libraries,
17
14
  worldDeploy,
18
15
  systems,
19
16
  }: {
20
17
  readonly client: Client<Transport, Chain | undefined, Account>;
21
- readonly deployerAddress: Hex;
22
- readonly libraries: readonly Library[];
23
18
  readonly worldDeploy: WorldDeploy;
24
19
  readonly systems: readonly System[];
25
20
  }): Promise<readonly Hex[]> {
@@ -27,112 +22,30 @@ export async function ensureSystems({
27
22
  getSystems({ client, worldDeploy }),
28
23
  getResourceAccess({ client, worldDeploy }),
29
24
  ]);
30
-
31
- // Register or replace systems
32
-
33
- const existingSystems = systems.filter((system) =>
34
- worldSystems.some(
35
- (worldSystem) =>
36
- worldSystem.systemId === system.systemId &&
37
- getAddress(worldSystem.address) === getAddress(system.prepareDeploy(deployerAddress, libraries).address),
38
- ),
39
- );
40
- if (existingSystems.length) {
41
- debug("existing systems", existingSystems.map(resourceToLabel).join(", "));
42
- }
43
- const existingSystemIds = existingSystems.map((system) => system.systemId);
44
-
45
- const missingSystems = systems.filter((system) => !existingSystemIds.includes(system.systemId));
46
- if (!missingSystems.length) return [];
47
-
48
- const systemsToUpgrade = missingSystems.filter((system) =>
49
- worldSystems.some(
50
- (worldSystem) =>
51
- worldSystem.systemId === system.systemId &&
52
- getAddress(worldSystem.address) !== getAddress(system.prepareDeploy(deployerAddress, libraries).address),
53
- ),
54
- );
55
- if (systemsToUpgrade.length) {
56
- debug("upgrading systems", systemsToUpgrade.map(resourceToLabel).join(", "));
57
- }
58
-
59
- const systemsToAdd = missingSystems.filter(
60
- (system) => !worldSystems.some((worldSystem) => worldSystem.systemId === system.systemId),
61
- );
62
- if (systemsToAdd.length) {
63
- debug("registering new systems", systemsToAdd.map(resourceToLabel).join(", "));
64
- }
65
-
66
- await ensureContractsDeployed({
67
- client,
68
- deployerAddress,
69
- contracts: missingSystems.map((system) => ({
70
- bytecode: system.prepareDeploy(deployerAddress, libraries).bytecode,
71
- deployedBytecodeSize: system.deployedBytecodeSize,
72
- label: `${resourceToLabel(system)} system`,
73
- })),
74
- });
75
-
76
- const registerTxs = await Promise.all(
77
- missingSystems.map((system) =>
78
- pRetry(
79
- () =>
80
- writeContract(client, {
81
- chain: client.chain ?? null,
82
- address: worldDeploy.address,
83
- abi: worldAbi,
84
- // TODO: replace with batchCall (https://github.com/latticexyz/mud/issues/1645)
85
- functionName: "registerSystem",
86
- args: [system.systemId, system.prepareDeploy(deployerAddress, libraries).address, system.allowAll],
87
- }),
88
- {
89
- retries: 3,
90
- onFailedAttempt: async (error) => {
91
- const delay = error.attemptNumber * 500;
92
- debug(`failed to register system ${resourceToLabel(system)}, retrying in ${delay}ms...`);
93
- await wait(delay);
94
- },
95
- },
96
- ),
97
- ),
98
- );
99
-
100
- // Adjust system access
101
-
102
25
  const systemIds = systems.map((system) => system.systemId);
103
26
  const currentAccess = worldAccess.filter(({ resourceId }) => systemIds.includes(resourceId));
104
- const desiredAccess = [
105
- ...systems.flatMap((system) =>
106
- system.allowedAddresses.map((address) => ({ resourceId: system.systemId, address })),
107
- ),
108
- ...systems.flatMap((system) =>
109
- system.allowedSystemIds
110
- .map((systemId) => ({
111
- resourceId: system.systemId,
112
- address:
113
- worldSystems.find((s) => s.systemId === systemId)?.address ??
114
- systems.find((s) => s.systemId === systemId)?.prepareDeploy(deployerAddress, libraries).address,
115
- }))
116
- .filter((access): access is typeof access & { address: Address } => access.address != null),
117
- ),
118
- ];
27
+ const desiredAccess = systems.flatMap((system) =>
28
+ system.allowedAddresses.map((address) => ({ resourceId: system.systemId, address }))
29
+ );
119
30
 
120
31
  const accessToAdd = desiredAccess.filter(
121
32
  (access) =>
122
33
  !currentAccess.some(
123
34
  ({ resourceId, address }) =>
124
- resourceId === access.resourceId && getAddress(address) === getAddress(access.address),
125
- ),
35
+ resourceId === access.resourceId && getAddress(address) === getAddress(access.address)
36
+ )
126
37
  );
127
38
 
128
39
  const accessToRemove = currentAccess.filter(
129
40
  (access) =>
130
41
  !desiredAccess.some(
131
42
  ({ resourceId, address }) =>
132
- resourceId === access.resourceId && getAddress(address) === getAddress(access.address),
133
- ),
43
+ resourceId === access.resourceId && getAddress(address) === getAddress(access.address)
44
+ )
134
45
  );
135
46
 
47
+ // TODO: move each system access+registration to batch call to be atomic
48
+
136
49
  if (accessToRemove.length) {
137
50
  debug("revoking", accessToRemove.length, "access grants");
138
51
  }
@@ -140,7 +53,7 @@ export async function ensureSystems({
140
53
  debug("adding", accessToAdd.length, "access grants");
141
54
  }
142
55
 
143
- const accessTxs = await Promise.all([
56
+ const accessTxs = [
144
57
  ...accessToRemove.map((access) =>
145
58
  pRetry(
146
59
  () =>
@@ -158,8 +71,8 @@ export async function ensureSystems({
158
71
  debug(`failed to revoke access, retrying in ${delay}ms...`);
159
72
  await wait(delay);
160
73
  },
161
- },
162
- ),
74
+ }
75
+ )
163
76
  ),
164
77
  ...accessToAdd.map((access) =>
165
78
  pRetry(
@@ -178,10 +91,72 @@ export async function ensureSystems({
178
91
  debug(`failed to grant access, retrying in ${delay}ms...`);
179
92
  await wait(delay);
180
93
  },
181
- },
182
- ),
94
+ }
95
+ )
183
96
  ),
184
- ]);
97
+ ];
98
+
99
+ const existingSystems = systems.filter((system) =>
100
+ worldSystems.some(
101
+ (worldSystem) =>
102
+ worldSystem.systemId === system.systemId && getAddress(worldSystem.address) === getAddress(system.address)
103
+ )
104
+ );
105
+ if (existingSystems.length) {
106
+ debug("existing systems", existingSystems.map(resourceLabel).join(", "));
107
+ }
108
+ const existingSystemIds = existingSystems.map((system) => system.systemId);
109
+
110
+ const missingSystems = systems.filter((system) => !existingSystemIds.includes(system.systemId));
111
+ if (!missingSystems.length) return [];
112
+
113
+ const systemsToUpgrade = missingSystems.filter((system) =>
114
+ worldSystems.some(
115
+ (worldSystem) =>
116
+ worldSystem.systemId === system.systemId && getAddress(worldSystem.address) !== getAddress(system.address)
117
+ )
118
+ );
119
+ if (systemsToUpgrade.length) {
120
+ debug("upgrading systems", systemsToUpgrade.map(resourceLabel).join(", "));
121
+ }
122
+
123
+ const systemsToAdd = missingSystems.filter(
124
+ (system) => !worldSystems.some((worldSystem) => worldSystem.systemId === system.systemId)
125
+ );
126
+ if (systemsToAdd.length) {
127
+ debug("registering new systems", systemsToAdd.map(resourceLabel).join(", "));
128
+ }
129
+
130
+ await ensureContractsDeployed({
131
+ client,
132
+ contracts: uniqueBy(missingSystems, (system) => getAddress(system.address)).map((system) => ({
133
+ bytecode: system.bytecode,
134
+ deployedBytecodeSize: system.deployedBytecodeSize,
135
+ label: `${resourceLabel(system)} system`,
136
+ })),
137
+ });
138
+
139
+ const registerTxs = missingSystems.map((system) =>
140
+ pRetry(
141
+ () =>
142
+ writeContract(client, {
143
+ chain: client.chain ?? null,
144
+ address: worldDeploy.address,
145
+ abi: worldAbi,
146
+ // TODO: replace with batchCall (https://github.com/latticexyz/mud/issues/1645)
147
+ functionName: "registerSystem",
148
+ args: [system.systemId, system.address, system.allowAll],
149
+ }),
150
+ {
151
+ retries: 3,
152
+ onFailedAttempt: async (error) => {
153
+ const delay = error.attemptNumber * 500;
154
+ debug(`failed to register system ${resourceLabel(system)}, retrying in ${delay}ms...`);
155
+ await wait(delay);
156
+ },
157
+ }
158
+ )
159
+ );
185
160
 
186
- return [...registerTxs, ...accessTxs];
161
+ return await Promise.all([...accessTxs, ...registerTxs]);
187
162
  }
@@ -1,9 +1,10 @@
1
1
  import { Client, Transport, Chain, Account, Hex } from "viem";
2
2
  import { Table } from "./configToTables";
3
- import { resourceToLabel, writeContract } from "@latticexyz/common";
3
+ import { writeContract } from "@latticexyz/common";
4
4
  import { WorldDeploy, worldAbi } from "./common";
5
5
  import { valueSchemaToFieldLayoutHex, keySchemaToHex, valueSchemaToHex } from "@latticexyz/protocol-parser";
6
6
  import { debug } from "./debug";
7
+ import { resourceLabel } from "./resourceLabel";
7
8
  import { getTables } from "./getTables";
8
9
  import pRetry from "p-retry";
9
10
  import { wait } from "@latticexyz/common/utils";
@@ -22,12 +23,12 @@ export async function ensureTables({
22
23
 
23
24
  const existingTables = tables.filter((table) => worldTableIds.includes(table.tableId));
24
25
  if (existingTables.length) {
25
- debug("existing tables", existingTables.map(resourceToLabel).join(", "));
26
+ debug("existing tables", existingTables.map(resourceLabel).join(", "));
26
27
  }
27
28
 
28
29
  const missingTables = tables.filter((table) => !worldTableIds.includes(table.tableId));
29
30
  if (missingTables.length) {
30
- debug("registering tables", missingTables.map(resourceToLabel).join(", "));
31
+ debug("registering tables", missingTables.map(resourceLabel).join(", "));
31
32
  return await Promise.all(
32
33
  missingTables.map((table) =>
33
34
  pRetry(
@@ -51,12 +52,12 @@ export async function ensureTables({
51
52
  retries: 3,
52
53
  onFailedAttempt: async (error) => {
53
54
  const delay = error.attemptNumber * 500;
54
- debug(`failed to register table ${resourceToLabel(table)}, retrying in ${delay}ms...`);
55
+ debug(`failed to register table ${resourceLabel(table)}, retrying in ${delay}ms...`);
55
56
  await wait(delay);
56
57
  },
57
- },
58
- ),
59
- ),
58
+ }
59
+ )
60
+ )
60
61
  );
61
62
  }
62
63
 
@@ -1,105 +1,47 @@
1
- import accessManagementSystemBuild from "@latticexyz/world/out/AccessManagementSystem.sol/AccessManagementSystem.json" assert { type: "json" };
2
- import balanceTransferSystemBuild from "@latticexyz/world/out/BalanceTransferSystem.sol/BalanceTransferSystem.json" assert { type: "json" };
3
- import batchCallSystemBuild from "@latticexyz/world/out/BatchCallSystem.sol/BatchCallSystem.json" assert { type: "json" };
4
- import registrationSystemBuild from "@latticexyz/world/out/RegistrationSystem.sol/RegistrationSystem.json" assert { type: "json" };
5
- import initModuleBuild from "@latticexyz/world/out/InitModule.sol/InitModule.json" assert { type: "json" };
6
- import initModuleAbi from "@latticexyz/world/out/InitModule.sol/InitModule.abi.json" assert { type: "json" };
1
+ import coreModuleBuild from "@latticexyz/world/out/CoreModule.sol/CoreModule.json" assert { type: "json" };
7
2
  import worldFactoryBuild from "@latticexyz/world/out/WorldFactory.sol/WorldFactory.json" assert { type: "json" };
8
- import worldFactoryAbi from "@latticexyz/world/out/WorldFactory.sol/WorldFactory.abi.json" assert { type: "json" };
9
- import { Client, Transport, Chain, Account, Hex, getCreate2Address, encodeDeployData, size, Address } from "viem";
3
+ import { Client, Transport, Chain, Account, Hex, parseAbi, getCreate2Address, encodeDeployData, size } from "viem";
4
+ import { deployer } from "./ensureDeployer";
10
5
  import { salt } from "./common";
11
6
  import { ensureContractsDeployed } from "./ensureContractsDeployed";
12
7
  import { Contract } from "./ensureContract";
13
8
 
14
- export async function ensureWorldFactory(
15
- client: Client<Transport, Chain | undefined, Account>,
16
- deployerAddress: Hex,
17
- ): Promise<Address> {
18
- const accessManagementSystemDeployedBytecodeSize = size(accessManagementSystemBuild.deployedBytecode.object as Hex);
19
- const accessManagementSystemBytecode = accessManagementSystemBuild.bytecode.object as Hex;
20
- const accessManagementSystem = getCreate2Address({
21
- from: deployerAddress,
22
- bytecode: accessManagementSystemBytecode,
23
- salt,
24
- });
25
-
26
- const balanceTransferSystemDeployedBytecodeSize = size(balanceTransferSystemBuild.deployedBytecode.object as Hex);
27
- const balanceTransferSystemBytecode = balanceTransferSystemBuild.bytecode.object as Hex;
28
- const balanceTransferSystem = getCreate2Address({
29
- from: deployerAddress,
30
- bytecode: balanceTransferSystemBytecode,
31
- salt,
32
- });
33
-
34
- const batchCallSystemDeployedBytecodeSize = size(batchCallSystemBuild.deployedBytecode.object as Hex);
35
- const batchCallSystemBytecode = batchCallSystemBuild.bytecode.object as Hex;
36
- const batchCallSystem = getCreate2Address({ from: deployerAddress, bytecode: batchCallSystemBytecode, salt });
37
-
38
- const registrationDeployedBytecodeSize = size(registrationSystemBuild.deployedBytecode.object as Hex);
39
- const registrationBytecode = registrationSystemBuild.bytecode.object as Hex;
40
- const registration = getCreate2Address({
41
- from: deployerAddress,
42
- bytecode: registrationBytecode,
43
- salt,
44
- });
45
-
46
- const initModuleDeployedBytecodeSize = size(initModuleBuild.deployedBytecode.object as Hex);
47
- const initModuleBytecode = encodeDeployData({
48
- bytecode: initModuleBuild.bytecode.object as Hex,
49
- abi: initModuleAbi,
50
- args: [accessManagementSystem, balanceTransferSystem, batchCallSystem, registration],
51
- });
52
-
53
- const initModule = getCreate2Address({ from: deployerAddress, bytecode: initModuleBytecode, salt });
54
-
55
- const worldFactoryDeployedBytecodeSize = size(worldFactoryBuild.deployedBytecode.object as Hex);
56
- const worldFactoryBytecode = encodeDeployData({
57
- bytecode: worldFactoryBuild.bytecode.object as Hex,
58
- abi: worldFactoryAbi,
59
- args: [initModule],
60
- });
9
+ export const coreModuleDeployedBytecodeSize = size(coreModuleBuild.deployedBytecode.object as Hex);
10
+ export const coreModuleBytecode = encodeDeployData({
11
+ bytecode: coreModuleBuild.bytecode.object as Hex,
12
+ abi: [],
13
+ });
14
+
15
+ export const coreModule = getCreate2Address({ from: deployer, bytecode: coreModuleBytecode, salt });
16
+
17
+ export const worldFactoryDeployedBytecodeSize = size(worldFactoryBuild.deployedBytecode.object as Hex);
18
+ export const worldFactoryBytecode = encodeDeployData({
19
+ bytecode: worldFactoryBuild.bytecode.object as Hex,
20
+ abi: parseAbi(["constructor(address)"]),
21
+ args: [coreModule],
22
+ });
23
+
24
+ export const worldFactory = getCreate2Address({ from: deployer, bytecode: worldFactoryBytecode, salt });
25
+
26
+ export const worldFactoryContracts: readonly Contract[] = [
27
+ {
28
+ bytecode: coreModuleBytecode,
29
+ deployedBytecodeSize: coreModuleDeployedBytecodeSize,
30
+ label: "core module",
31
+ },
32
+ {
33
+ bytecode: worldFactoryBytecode,
34
+ deployedBytecodeSize: worldFactoryDeployedBytecodeSize,
35
+ label: "world factory",
36
+ },
37
+ ];
61
38
 
62
- const worldFactory = getCreate2Address({ from: deployerAddress, bytecode: worldFactoryBytecode, salt });
63
-
64
- const worldFactoryContracts: readonly Contract[] = [
65
- {
66
- bytecode: accessManagementSystemBytecode,
67
- deployedBytecodeSize: accessManagementSystemDeployedBytecodeSize,
68
- label: "access management system",
69
- },
70
- {
71
- bytecode: balanceTransferSystemBytecode,
72
- deployedBytecodeSize: balanceTransferSystemDeployedBytecodeSize,
73
- label: "balance transfer system",
74
- },
75
- {
76
- bytecode: batchCallSystemBytecode,
77
- deployedBytecodeSize: batchCallSystemDeployedBytecodeSize,
78
- label: "batch call system",
79
- },
80
- {
81
- bytecode: registrationBytecode,
82
- deployedBytecodeSize: registrationDeployedBytecodeSize,
83
- label: "core registration system",
84
- },
85
- {
86
- bytecode: initModuleBytecode,
87
- deployedBytecodeSize: initModuleDeployedBytecodeSize,
88
- label: "core module",
89
- },
90
- {
91
- bytecode: worldFactoryBytecode,
92
- deployedBytecodeSize: worldFactoryDeployedBytecodeSize,
93
- label: "world factory",
94
- },
95
- ];
96
-
97
- // WorldFactory constructor doesn't call InitModule, only sets its address, so we can do these in parallel since the address is deterministic
98
- await ensureContractsDeployed({
39
+ export async function ensureWorldFactory(
40
+ client: Client<Transport, Chain | undefined, Account>
41
+ ): Promise<readonly Hex[]> {
42
+ // WorldFactory constructor doesn't call CoreModule, only sets its address, so we can do these in parallel since the address is deterministic
43
+ return await ensureContractsDeployed({
99
44
  client,
100
- deployerAddress,
101
45
  contracts: worldFactoryContracts,
102
46
  });
103
-
104
- return worldFactory;
105
47
  }
@@ -1,4 +1,4 @@
1
- import { Client, toFunctionSelector, parseAbiItem } from "viem";
1
+ import { Client, getFunctionSelector, parseAbiItem } from "viem";
2
2
  import { WorldDeploy, WorldFunction, worldTables } from "./common";
3
3
  import { debug } from "./debug";
4
4
  import { storeSetRecordEvent } from "@latticexyz/store";
@@ -34,12 +34,12 @@ export async function getFunctions({
34
34
  // TODO: parallelize with a bulk getRecords
35
35
  const functions = await Promise.all(
36
36
  signatures.map(async (signature) => {
37
- const selector = toFunctionSelector(signature);
37
+ const selector = getFunctionSelector(signature);
38
38
  const { systemId, systemFunctionSelector } = await getTableValue({
39
39
  client,
40
40
  worldDeploy,
41
41
  table: worldTables.world_FunctionSelectors,
42
- key: { worldFunctionSelector: selector },
42
+ key: { functionSelector: selector },
43
43
  });
44
44
  const { namespace, name } = hexToResource(systemId);
45
45
  // TODO: find away around undoing contract logic (https://github.com/latticexyz/mud/issues/1708)
@@ -51,7 +51,7 @@ export async function getFunctions({
51
51
  systemFunctionSignature,
52
52
  systemFunctionSelector,
53
53
  };
54
- }),
54
+ })
55
55
  );
56
56
 
57
57
  return functions;
@@ -35,8 +35,8 @@ export async function getResourceAccess({
35
35
  await Promise.all(
36
36
  keys.map(
37
37
  async (key) =>
38
- [key, await getTableValue({ client, worldDeploy, table: worldTables.world_ResourceAccess, key })] as const,
39
- ),
38
+ [key, await getTableValue({ client, worldDeploy, table: worldTables.world_ResourceAccess, key })] as const
39
+ )
40
40
  )
41
41
  )
42
42
  .filter(([, value]) => value.access)
@@ -1,9 +1,10 @@
1
- import { DeployedSystem, WorldDeploy, worldTables } from "./common";
1
+ import { System, WorldDeploy, worldTables } from "./common";
2
2
  import { Client } from "viem";
3
3
  import { getResourceIds } from "./getResourceIds";
4
- import { hexToResource, resourceToLabel } from "@latticexyz/common";
4
+ import { hexToResource } from "@latticexyz/common";
5
5
  import { getTableValue } from "./getTableValue";
6
6
  import { debug } from "./debug";
7
+ import { resourceLabel } from "./resourceLabel";
7
8
  import { getFunctions } from "./getFunctions";
8
9
  import { getResourceAccess } from "./getResourceAccess";
9
10
 
@@ -13,7 +14,7 @@ export async function getSystems({
13
14
  }: {
14
15
  readonly client: Client;
15
16
  readonly worldDeploy: WorldDeploy;
16
- }): Promise<readonly DeployedSystem[]> {
17
+ }): Promise<readonly Omit<System, "abi" | "bytecode" | "deployedBytecodeSize">[]> {
17
18
  const [resourceIds, functions, resourceAccess] = await Promise.all([
18
19
  getResourceIds({ client, worldDeploy }),
19
20
  getFunctions({ client, worldDeploy }),
@@ -21,9 +22,9 @@ export async function getSystems({
21
22
  ]);
22
23
  const systems = resourceIds.map(hexToResource).filter((resource) => resource.type === "system");
23
24
 
24
- debug("looking up systems", systems.map(resourceToLabel).join(", "));
25
+ debug("looking up systems", systems.map(resourceLabel).join(", "));
25
26
  return await Promise.all(
26
- systems.map(async (system): Promise<DeployedSystem> => {
27
+ systems.map(async (system) => {
27
28
  const { system: address, publicAccess } = await getTableValue({
28
29
  client,
29
30
  worldDeploy,
@@ -42,6 +43,6 @@ export async function getSystems({
42
43
  .map(({ address }) => address),
43
44
  functions: systemFunctions,
44
45
  };
45
- }),
46
+ })
46
47
  );
47
48
  }
@@ -45,7 +45,7 @@ export async function getTables({
45
45
  const valueAbiTypes = [...valueSchemaFields.staticFields, ...valueSchemaFields.dynamicFields];
46
46
 
47
47
  const keySchema = Object.fromEntries(
48
- keySchemaFields.staticFields.map((abiType, i) => [keyNames[i], abiType]),
48
+ keySchemaFields.staticFields.map((abiType, i) => [keyNames[i], abiType])
49
49
  ) as KeySchema;
50
50
  const valueSchema = Object.fromEntries(valueAbiTypes.map((abiType, i) => [fieldNames[i], abiType])) as ValueSchema;
51
51
 
@@ -37,7 +37,7 @@ export function logsToWorldDeploy(logs: readonly Log<bigint, number, false>[]):
37
37
  ? { storeVersion: hexToString(trim(log.args.storeVersion, { dir: "right" })) }
38
38
  : null),
39
39
  }),
40
- {},
40
+ {}
41
41
  );
42
42
 
43
43
  if (address == null) throw new Error("could not find world address");