create-mud 2.0.0-next.1 → 2.0.0-next.10

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 (92) hide show
  1. package/dist/cli.js +1 -1
  2. package/dist/templates/phaser/.vscode/settings.json +2 -1
  3. package/dist/templates/phaser/packages/art/package.json +0 -1
  4. package/dist/templates/phaser/packages/client/package.json +5 -7
  5. package/dist/templates/phaser/packages/client/src/index.tsx +0 -2
  6. package/dist/templates/phaser/packages/client/src/layers/network/createNetworkLayer.ts +2 -6
  7. package/dist/templates/phaser/packages/client/src/mud/createClientComponents.ts +11 -0
  8. package/dist/templates/phaser/packages/client/src/mud/createSystemCalls.ts +34 -0
  9. package/dist/templates/phaser/packages/client/src/mud/getNetworkConfig.ts +61 -5
  10. package/dist/templates/phaser/packages/client/src/mud/setupNetwork.ts +54 -13
  11. package/dist/templates/phaser/packages/client/src/mud/supportedChains.ts +16 -1
  12. package/dist/templates/phaser/packages/client/src/store.ts +2 -5
  13. package/dist/templates/phaser/packages/client/src/ui/App.tsx +20 -3
  14. package/dist/templates/phaser/packages/client/src/ui/LoadingScreen/LoadingScreen.tsx +2 -1
  15. package/dist/templates/phaser/packages/contracts/.gitignore +0 -2
  16. package/dist/templates/phaser/packages/contracts/foundry.toml +1 -1
  17. package/dist/templates/phaser/packages/contracts/mud.config.ts +1 -1
  18. package/dist/templates/phaser/packages/contracts/package.json +7 -12
  19. package/dist/templates/phaser/packages/contracts/script/PostDeploy.s.sol +1 -1
  20. package/dist/templates/phaser/packages/contracts/src/codegen/{Tables.sol → index.sol} +1 -1
  21. package/dist/templates/phaser/packages/contracts/src/codegen/tables/Counter.sol +202 -50
  22. package/dist/templates/phaser/packages/contracts/src/codegen/world/IIncrementSystem.sol +5 -1
  23. package/dist/templates/phaser/packages/contracts/src/codegen/world/IWorld.sol +6 -4
  24. package/dist/templates/phaser/packages/contracts/src/systems/IncrementSystem.sol +2 -2
  25. package/dist/templates/phaser/packages/contracts/test/CounterTest.t.sol +4 -4
  26. package/dist/templates/phaser/packages/contracts/worlds.json.d.ts +2 -0
  27. package/dist/templates/react/.vscode/settings.json +2 -1
  28. package/dist/templates/react/packages/client/package.json +5 -7
  29. package/dist/templates/react/packages/client/src/index.tsx +18 -3
  30. package/dist/templates/react/packages/client/src/mud/createClientComponents.ts +11 -0
  31. package/dist/templates/react/packages/client/src/mud/createSystemCalls.ts +28 -0
  32. package/dist/templates/react/packages/client/src/mud/getNetworkConfig.ts +62 -5
  33. package/dist/templates/react/packages/client/src/mud/setup.ts +5 -0
  34. package/dist/templates/react/packages/client/src/mud/setupNetwork.ts +56 -13
  35. package/dist/templates/react/packages/client/src/mud/supportedChains.ts +17 -1
  36. package/dist/templates/react/packages/contracts/.gitignore +0 -2
  37. package/dist/templates/react/packages/contracts/foundry.toml +1 -1
  38. package/dist/templates/react/packages/contracts/mud.config.ts +1 -1
  39. package/dist/templates/react/packages/contracts/package.json +7 -12
  40. package/dist/templates/react/packages/contracts/script/PostDeploy.s.sol +1 -1
  41. package/dist/templates/{vanilla/packages/contracts/src/codegen/Tables.sol → react/packages/contracts/src/codegen/index.sol} +1 -1
  42. package/dist/templates/react/packages/contracts/src/codegen/tables/Counter.sol +202 -50
  43. package/dist/templates/react/packages/contracts/src/codegen/world/IIncrementSystem.sol +5 -1
  44. package/dist/templates/react/packages/contracts/src/codegen/world/IWorld.sol +6 -4
  45. package/dist/templates/react/packages/contracts/src/systems/IncrementSystem.sol +2 -2
  46. package/dist/templates/react/packages/contracts/test/CounterTest.t.sol +4 -4
  47. package/dist/templates/react/packages/contracts/worlds.json.d.ts +2 -0
  48. package/dist/templates/threejs/.vscode/settings.json +2 -1
  49. package/dist/templates/threejs/packages/client/package.json +5 -7
  50. package/dist/templates/threejs/packages/client/src/index.tsx +18 -3
  51. package/dist/templates/threejs/packages/client/src/mud/createClientComponents.ts +11 -0
  52. package/dist/templates/threejs/packages/client/src/mud/createSystemCalls.ts +26 -0
  53. package/dist/templates/threejs/packages/client/src/mud/getNetworkConfig.ts +65 -5
  54. package/dist/templates/threejs/packages/client/src/mud/setup.ts +3 -0
  55. package/dist/templates/threejs/packages/client/src/mud/setupNetwork.ts +54 -13
  56. package/dist/templates/threejs/packages/client/src/mud/supportedChains.ts +15 -1
  57. package/dist/templates/threejs/packages/contracts/.gitignore +0 -2
  58. package/dist/templates/threejs/packages/contracts/foundry.toml +1 -1
  59. package/dist/templates/threejs/packages/contracts/mud.config.ts +1 -1
  60. package/dist/templates/threejs/packages/contracts/package.json +7 -13
  61. package/dist/templates/threejs/packages/contracts/src/codegen/{Tables.sol → index.sol} +1 -1
  62. package/dist/templates/threejs/packages/contracts/src/codegen/tables/Position.sol +356 -96
  63. package/dist/templates/threejs/packages/contracts/src/codegen/world/IMoveSystem.sol +5 -1
  64. package/dist/templates/threejs/packages/contracts/src/codegen/world/IWorld.sol +6 -4
  65. package/dist/templates/threejs/packages/contracts/src/systems/MoveSystem.sol +2 -2
  66. package/dist/templates/threejs/packages/contracts/worlds.json.d.ts +2 -0
  67. package/dist/templates/vanilla/.vscode/settings.json +2 -1
  68. package/dist/templates/vanilla/packages/client/package.json +3 -5
  69. package/dist/templates/vanilla/packages/client/src/index.ts +17 -2
  70. package/dist/templates/vanilla/packages/client/src/mud/createClientComponents.ts +11 -0
  71. package/dist/templates/vanilla/packages/client/src/mud/createSystemCalls.ts +29 -0
  72. package/dist/templates/vanilla/packages/client/src/mud/getNetworkConfig.ts +63 -5
  73. package/dist/templates/vanilla/packages/client/src/mud/setup.ts +5 -0
  74. package/dist/templates/vanilla/packages/client/src/mud/setupNetwork.ts +56 -13
  75. package/dist/templates/vanilla/packages/client/src/mud/supportedChains.ts +16 -1
  76. package/dist/templates/vanilla/packages/contracts/.gitignore +0 -2
  77. package/dist/templates/vanilla/packages/contracts/foundry.toml +1 -1
  78. package/dist/templates/vanilla/packages/contracts/mud.config.ts +1 -1
  79. package/dist/templates/vanilla/packages/contracts/package.json +7 -12
  80. package/dist/templates/vanilla/packages/contracts/script/PostDeploy.s.sol +1 -1
  81. package/dist/templates/{react/packages/contracts/src/codegen/Tables.sol → vanilla/packages/contracts/src/codegen/index.sol} +1 -1
  82. package/dist/templates/vanilla/packages/contracts/src/codegen/tables/Counter.sol +202 -50
  83. package/dist/templates/vanilla/packages/contracts/src/codegen/world/IIncrementSystem.sol +5 -1
  84. package/dist/templates/vanilla/packages/contracts/src/codegen/world/IWorld.sol +6 -4
  85. package/dist/templates/vanilla/packages/contracts/src/systems/IncrementSystem.sol +2 -2
  86. package/dist/templates/vanilla/packages/contracts/test/CounterTest.t.sol +4 -4
  87. package/dist/templates/vanilla/packages/contracts/worlds.json.d.ts +2 -0
  88. package/package.json +2 -1
  89. package/dist/templates/phaser/packages/client/src/mud/contractComponents.ts +0 -27
  90. package/dist/templates/react/packages/client/src/mud/contractComponents.ts +0 -27
  91. package/dist/templates/threejs/packages/client/src/mud/contractComponents.ts +0 -29
  92. package/dist/templates/vanilla/packages/client/src/mud/contractComponents.ts +0 -27
package/dist/cli.js CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- "use strict";var t=require("create-create-app"),a=require("path");var e={name:"create-mud",version:"2.0.0-next.1",description:"Create a new MUD project",license:"MIT",author:"Lattice <mud@lattice.xyz>",bin:"dist/cli.js",files:["dist"],scripts:{build:"pnpm run build:js","build:js":"tsup && ./scripts/copy-templates.sh",clean:"pnpm run clean:js","clean:js":"rimraf dist",dev:"tsup --watch",prepublishOnly:"npm run clean && npm run build",test:"pnpm run test:vanilla && pnpm run test:react && pnpm run test:phaser && pnpm run test:threejs","test:phaser":"dist/cli.js test-project --template phaser && rimraf test-project","test:react":"dist/cli.js test-project --template react && rimraf test-project","test:threejs":"dist/cli.js test-project --template threejs && rimraf test-project","test:vanilla":"dist/cli.js test-project --template vanilla && rimraf test-project"},dependencies:{"create-create-app":"git+https://github.com/holic/create-create-app#74376c59b48a04aabbe94d9cacfe9cb1cecccd63"},devDependencies:{"@types/node":"^18.15.11",tsup:"^6.7.0"},publishConfig:{access:"public",registry:"https://registry.npmjs.org"},gitHead:"914a1e0ae4a573d685841ca2ea921435057deb8f"};var i=(0,a.resolve)(__dirname,"..","dist","templates");(0,t.create)("create-mud",{templateRoot:i,defaultTemplate:"vanilla",defaultPackageManager:"pnpm",promptForDescription:!1,promptForAuthor:!1,promptForEmail:!1,promptForLicense:!1,promptForTemplate:!0,caveat:({answers:r,packageManager:s})=>`Done! Play in the MUD with \`cd ${r.name}\` and \`${s} run dev\``,extra:{"mud-version":{type:"input",describe:"The version of MUD packages to use, defaults to latest",default:e.version}}});
2
+ "use strict";var t=require("create-create-app"),s=require("path");var e={name:"create-mud",version:"2.0.0-next.10",description:"Create a new MUD project",license:"MIT",author:"Lattice <mud@lattice.xyz>",bin:"dist/cli.js",files:["dist"],scripts:{build:"pnpm run build:js","build:js":"tsup && ./scripts/copy-templates.sh",clean:"pnpm run clean:js","clean:js":"rimraf dist",dev:"tsup --watch",prepublishOnly:"npm run clean && npm run build",test:"pnpm run test:vanilla && pnpm run test:react && pnpm run test:phaser && pnpm run test:threejs","test:ci":"pnpm run test","test:phaser":"dist/cli.js test-project --template phaser && rimraf test-project","test:react":"dist/cli.js test-project --template react && rimraf test-project","test:threejs":"dist/cli.js test-project --template threejs && rimraf test-project","test:vanilla":"dist/cli.js test-project --template vanilla && rimraf test-project"},dependencies:{"create-create-app":"git+https://github.com/holic/create-create-app#74376c59b48a04aabbe94d9cacfe9cb1cecccd63"},devDependencies:{"@types/node":"^18.15.11",tsup:"^6.7.0"},publishConfig:{access:"public",registry:"https://registry.npmjs.org"},gitHead:"914a1e0ae4a573d685841ca2ea921435057deb8f"};var i=(0,s.resolve)(__dirname,"..","dist","templates");(0,t.create)("create-mud",{templateRoot:i,defaultTemplate:"vanilla",defaultPackageManager:"pnpm",promptForDescription:!1,promptForAuthor:!1,promptForEmail:!1,promptForLicense:!1,promptForTemplate:!0,caveat:({answers:r,packageManager:a})=>`Done! Play in the MUD with \`cd ${r.name}\` and \`${a} run dev\``,extra:{"mud-version":{type:"input",describe:"The version of MUD packages to use, defaults to latest",default:e.version}}});
@@ -1,3 +1,4 @@
1
1
  {
2
- "solidity.monoRepoSupport": true
2
+ "solidity.monoRepoSupport": true,
3
+ "solidity.compileUsingRemoteVersion": "v0.8.21+commit.d9974bed"
3
4
  }
@@ -15,7 +15,6 @@
15
15
  "@types/glob": "^7.2.0",
16
16
  "@types/node": "^18.0.3",
17
17
  "ejs": "^3.1.8",
18
- "ethers": "^5.7.0",
19
18
  "free-tex-packer-cli": "^0.3.0",
20
19
  "free-tex-packer-core": "^0.3.4",
21
20
  "glob": "^8.0.3",
@@ -11,33 +11,31 @@
11
11
  "test": "tsc --noEmit"
12
12
  },
13
13
  "dependencies": {
14
- "@ethersproject/providers": "^5.7.2",
15
14
  "@latticexyz/common": "{{mud-version}}",
16
15
  "@latticexyz/dev-tools": "{{mud-version}}",
17
- "@latticexyz/network": "{{mud-version}}",
18
16
  "@latticexyz/phaserx": "{{mud-version}}",
19
17
  "@latticexyz/react": "{{mud-version}}",
20
18
  "@latticexyz/recs": "{{mud-version}}",
21
19
  "@latticexyz/schema-type": "{{mud-version}}",
22
- "@latticexyz/std-client": "{{mud-version}}",
20
+ "@latticexyz/services": "{{mud-version}}",
23
21
  "@latticexyz/store-sync": "{{mud-version}}",
24
22
  "@latticexyz/utils": "{{mud-version}}",
25
23
  "@latticexyz/world": "{{mud-version}}",
26
24
  "contracts": "workspace:*",
27
- "ethers": "^5.7.2",
28
25
  "lodash": "^4.17.21",
29
26
  "react": "^18.2.0",
30
27
  "react-dom": "^18.2.0",
28
+ "rxjs": "7.5.5",
31
29
  "simplex-noise": "^4.0.1",
32
30
  "styled-components": "^5.3.10",
33
31
  "use-resize-observer": "^9.1.0",
34
- "viem": "1.3.1",
32
+ "viem": "1.6.0",
35
33
  "zustand": "^4.3.8"
36
34
  },
37
35
  "devDependencies": {
38
36
  "@types/lodash": "^4.14.194",
39
- "@types/react": "^18.2.6",
40
- "@types/react-dom": "^18.2.4",
37
+ "@types/react": "18.2.22",
38
+ "@types/react-dom": "18.2.7",
41
39
  "@types/styled-components": "^5.1.26",
42
40
  "@vitejs/plugin-react": "^3.1.0",
43
41
  "eslint-plugin-react": "7.31.11",
@@ -1,11 +1,9 @@
1
1
  import React from "react";
2
2
  import ReactDOM from "react-dom/client";
3
3
  import { App } from "./ui/App";
4
- import { mount as mountDevTools } from "@latticexyz/dev-tools";
5
4
 
6
5
  const rootElement = document.getElementById("react-root");
7
6
  if (!rootElement) throw new Error("React root not found");
8
7
  const root = ReactDOM.createRoot(rootElement);
9
8
 
10
9
  root.render(<App />);
11
- mountDevTools();
@@ -4,16 +4,12 @@ import { setup } from "../../mud/setup";
4
4
  export type NetworkLayer = Awaited<ReturnType<typeof createNetworkLayer>>;
5
5
 
6
6
  export const createNetworkLayer = async () => {
7
- const { components, systemCalls } = await setup();
8
-
9
- // Give components a Human-readable ID
10
- Object.entries(components).forEach(([name, component]) => {
11
- component.id = name;
12
- });
7
+ const { components, systemCalls, network } = await setup();
13
8
 
14
9
  return {
15
10
  world,
16
11
  systemCalls,
17
12
  components,
13
+ network,
18
14
  };
19
15
  };
@@ -1,3 +1,14 @@
1
+ /*
2
+ * Creates components for use by the client.
3
+ *
4
+ * By default it returns the components from setupNetwork.ts, those which are
5
+ * automatically inferred from the mud.config.ts table definitions.
6
+ *
7
+ * However, you can add or override components here as needed. This
8
+ * lets you add user defined components, which may or may not have
9
+ * an onchain component.
10
+ */
11
+
1
12
  import { SetupNetworkResult } from "./setupNetwork";
2
13
 
3
14
  export type ClientComponents = ReturnType<typeof createClientComponents>;
@@ -1,3 +1,14 @@
1
+ /*
2
+ * Creates components for use by the client.
3
+ *
4
+ * By default it returns the components from setupNetwork.ts, those which are
5
+ * automatically inferred from the mud.config.ts table definitions.
6
+ *
7
+ * However, you can add or override components here as needed. This
8
+ * lets you add user defined components, which may or may not have
9
+ * an onchain component.
10
+ */
11
+
1
12
  import { getComponentValue } from "@latticexyz/recs";
2
13
  import { ClientComponents } from "./createClientComponents";
3
14
  import { SetupNetworkResult } from "./setupNetwork";
@@ -6,10 +17,33 @@ import { singletonEntity } from "@latticexyz/store-sync/recs";
6
17
  export type SystemCalls = ReturnType<typeof createSystemCalls>;
7
18
 
8
19
  export function createSystemCalls(
20
+ /*
21
+ * The parameter list informs TypeScript that:
22
+ *
23
+ * - The first parameter is expected to be a
24
+ * SetupNetworkResult, as defined in setupNetwork.ts
25
+ *
26
+ * - Out of this parameter, we only care about two fields:
27
+ * - worldContract (which comes from createContract, see
28
+ * https://github.com/latticexyz/mud/blob/26dabb34321eedff7a43f3fcb46da4f3f5ba3708/templates/phaser/packages/client/src/mud/setupNetwork.ts#L31).
29
+ * - waitForTransaction (which comes from syncToRecs, see
30
+ * https://github.com/latticexyz/mud/blob/26dabb34321eedff7a43f3fcb46da4f3f5ba3708/templates/phaser/packages/client/src/mud/setupNetwork.ts#L39).
31
+ *
32
+ * - From the second parameter, which is a ClientComponent,
33
+ * we only care about Counter. This parameter comes to use
34
+ * through createClientComponents.ts, but it originates in
35
+ * syncToRecs (https://github.com/latticexyz/mud/blob/26dabb34321eedff7a43f3fcb46da4f3f5ba3708/templates/phaser/packages/client/src/mud/setupNetwork.ts#L39).
36
+ */
9
37
  { worldContract, waitForTransaction }: SetupNetworkResult,
10
38
  { Counter }: ClientComponents
11
39
  ) {
12
40
  const increment = async () => {
41
+ /*
42
+ * Because IncrementSystem
43
+ * (https://mud.dev/tutorials/walkthrough/minimal-onchain#incrementsystemsol)
44
+ * is in the root namespace, `.increment` can be called directly
45
+ * on the World contract.
46
+ */
13
47
  const tx = await worldContract.write.increment();
14
48
  await waitForTransaction(tx);
15
49
  return getComponentValue(Counter, singletonEntity);
@@ -1,30 +1,86 @@
1
- import { getBurnerWallet } from "@latticexyz/std-client";
2
- import worldsJson from "contracts/worlds.json";
3
- import { supportedChains } from "./supportedChains";
1
+ /*
2
+ * Network specific configuration for the client.
3
+ * By default connect to the anvil test network.
4
+ */
5
+
6
+ /*
7
+ * By default the template just creates a temporary wallet
8
+ * (called a burner wallet) and uses a faucet (on our test net)
9
+ * to get ETH for it.
10
+ *
11
+ * See https://mud.dev/tutorials/minimal/deploy#wallet-managed-address
12
+ * for how to use the user's own address instead.
13
+ */
14
+ import { getBurnerPrivateKey } from "@latticexyz/common";
15
+
16
+ /*
17
+ * Import the addresses of the World, possibly on multiple chains,
18
+ * from packages/contracts/worlds.json. When the contracts package
19
+ * deploys a new `World`, it updates this file.
20
+ */
21
+ import worlds from "contracts/worlds.json";
4
22
 
5
- const worlds = worldsJson as Partial<Record<string, { address: string; blockNumber?: number }>>;
23
+ /*
24
+ * The supported chains.
25
+ * By default, there are only two chains here:
26
+ *
27
+ * - mudFoundry, the chain running on anvil that pnpm dev
28
+ * starts by default. It is similar to the viem anvil chain
29
+ * (see https://viem.sh/docs/clients/test.html), but with the
30
+ * basefee set to zero to avoid transaction fees.
31
+ * - latticeTestnet, our public test network.
32
+ *
33
+ * See https://mud.dev/tutorials/minimal/deploy#run-the-user-interface
34
+ * for instructions on how to add networks.
35
+ */
36
+ import { supportedChains } from "./supportedChains";
6
37
 
7
38
  export async function getNetworkConfig() {
8
39
  const params = new URLSearchParams(window.location.search);
40
+
41
+ /*
42
+ * The chain ID is the first item available from this list:
43
+ * 1. chainId query parameter
44
+ * 2. chainid query parameter
45
+ * 3. The VITE_CHAIN_ID environment variable set when the
46
+ * vite dev server was started or client was built
47
+ * 4. The default, 31337 (anvil)
48
+ */
9
49
  const chainId = Number(params.get("chainId") || params.get("chainid") || import.meta.env.VITE_CHAIN_ID || 31337);
50
+
51
+ /*
52
+ * Find the chain (unless it isn't in the list of supported chains).
53
+ */
10
54
  const chainIndex = supportedChains.findIndex((c) => c.id === chainId);
11
55
  const chain = supportedChains[chainIndex];
12
56
  if (!chain) {
13
57
  throw new Error(`Chain ${chainId} not found`);
14
58
  }
15
59
 
60
+ /*
61
+ * Get the address of the World. If you want to use a
62
+ * different address than the one in worlds.json,
63
+ * provide it as worldAddress in the query string.
64
+ */
16
65
  const world = worlds[chain.id.toString()];
17
66
  const worldAddress = params.get("worldAddress") || world?.address;
18
67
  if (!worldAddress) {
19
68
  throw new Error(`No world address found for chain ${chainId}. Did you run \`mud deploy\`?`);
20
69
  }
21
70
 
71
+ /*
72
+ * MUD clients use events to synchronize the database, meaning
73
+ * they need to look as far back as when the World was started.
74
+ * The block number for the World start can be specified either
75
+ * on the URL (as initialBlockNumber) or in the worlds.json
76
+ * file. If neither has it, it starts at the first block, zero.
77
+ */
22
78
  const initialBlockNumber = params.has("initialBlockNumber")
23
79
  ? Number(params.get("initialBlockNumber"))
24
80
  : world?.blockNumber ?? 0n;
25
81
 
26
82
  return {
27
- privateKey: getBurnerWallet().value,
83
+ privateKey: getBurnerPrivateKey(),
28
84
  chainId,
29
85
  chain,
30
86
  faucetServiceUrl: params.get("faucet") ?? chain.faucetUrl,
@@ -1,19 +1,36 @@
1
+ /*
2
+ * The MUD client code is built on top of viem
3
+ * (https://viem.sh/docs/getting-started.html).
4
+ * This line imports the functions we need from it.
5
+ */
1
6
  import { createPublicClient, fallback, webSocket, http, createWalletClient, Hex, parseEther, ClientConfig } from "viem";
2
- import { createFaucetService } from "@latticexyz/network";
7
+ import { createFaucetService } from "@latticexyz/services/faucet";
3
8
  import { encodeEntity, syncToRecs } from "@latticexyz/store-sync/recs";
4
9
  import { getNetworkConfig } from "./getNetworkConfig";
5
- import { defineContractComponents } from "./contractComponents";
6
10
  import { world } from "./world";
7
- import { IWorld__factory } from "contracts/types/ethers-contracts/factories/IWorld__factory";
8
- import storeConfig from "contracts/mud.config";
9
- import { createBurnerAccount, createContract, transportObserver } from "@latticexyz/common";
11
+ import IWorldAbi from "contracts/out/IWorld.sol/IWorld.abi.json";
12
+ import { createBurnerAccount, createContract, transportObserver, ContractWrite } from "@latticexyz/common";
13
+ import { Subject, share } from "rxjs";
14
+
15
+ /*
16
+ * Import our MUD config, which includes strong types for
17
+ * our tables and other config options. We use this to generate
18
+ * things like RECS components and get back strong types for them.
19
+ *
20
+ * See https://mud.dev/tutorials/walkthrough/minimal-onchain#mudconfigts
21
+ * for the source of this information.
22
+ */
23
+ import mudConfig from "contracts/mud.config";
10
24
 
11
25
  export type SetupNetworkResult = Awaited<ReturnType<typeof setupNetwork>>;
12
26
 
13
27
  export async function setupNetwork() {
14
- const contractComponents = defineContractComponents(world);
15
28
  const networkConfig = await getNetworkConfig();
16
29
 
30
+ /*
31
+ * Create a viem public (read only) client
32
+ * (https://viem.sh/docs/clients/public.html)
33
+ */
17
34
  const clientOptions = {
18
35
  chain: networkConfig.chain,
19
36
  transport: transportObserver(fallback([webSocket(), http()])),
@@ -22,29 +39,52 @@ export async function setupNetwork() {
22
39
 
23
40
  const publicClient = createPublicClient(clientOptions);
24
41
 
42
+ /*
43
+ * Create a temporary wallet and a viem client for it
44
+ * (see https://viem.sh/docs/clients/wallet.html).
45
+ */
25
46
  const burnerAccount = createBurnerAccount(networkConfig.privateKey as Hex);
26
47
  const burnerWalletClient = createWalletClient({
27
48
  ...clientOptions,
28
49
  account: burnerAccount,
29
50
  });
30
51
 
52
+ /*
53
+ * Create an observable for contract writes that we can
54
+ * pass into MUD dev tools for transaction observability.
55
+ */
56
+ const write$ = new Subject<ContractWrite>();
57
+
58
+ /*
59
+ * Create an object for communicating with the deployed World.
60
+ */
31
61
  const worldContract = createContract({
32
62
  address: networkConfig.worldAddress as Hex,
33
- abi: IWorld__factory.abi,
63
+ abi: IWorldAbi,
34
64
  publicClient,
35
65
  walletClient: burnerWalletClient,
66
+ onWrite: (write) => write$.next(write),
36
67
  });
37
68
 
38
- const { components, latestBlock$, blockStorageOperations$, waitForTransaction } = await syncToRecs({
69
+ /*
70
+ * Sync on-chain state into RECS and keeps our client in sync.
71
+ * Uses the MUD indexer if available, otherwise falls back
72
+ * to the viem publicClient to make RPC calls to fetch MUD
73
+ * events from the chain.
74
+ */
75
+ const { components, latestBlock$, storedBlockLogs$, waitForTransaction } = await syncToRecs({
39
76
  world,
40
- config: storeConfig,
77
+ config: mudConfig,
41
78
  address: networkConfig.worldAddress as Hex,
42
79
  publicClient,
43
- components: contractComponents,
44
80
  startBlock: BigInt(networkConfig.initialBlockNumber),
45
81
  });
46
82
 
47
- // Request drip from faucet
83
+ /*
84
+ * If there is a faucet, request (test) ETH if you have
85
+ * less than 1 ETH. Repeat every 20 seconds to ensure you don't
86
+ * run out.
87
+ */
48
88
  if (networkConfig.faucetServiceUrl) {
49
89
  const address = burnerAccount.address;
50
90
  console.info("[Dev Faucet]: Player address -> ", address);
@@ -74,9 +114,10 @@ export async function setupNetwork() {
74
114
  playerEntity: encodeEntity({ address: "address" }, { address: burnerWalletClient.account.address }),
75
115
  publicClient,
76
116
  walletClient: burnerWalletClient,
77
- worldContract,
78
117
  latestBlock$,
79
- blockStorageOperations$,
118
+ storedBlockLogs$,
80
119
  waitForTransaction,
120
+ worldContract,
121
+ write$: write$.asObservable().pipe(share()),
81
122
  };
82
123
  }
@@ -1,4 +1,19 @@
1
+ /*
2
+ * The supported chains.
3
+ * By default, there are only two chains here:
4
+ *
5
+ * - mudFoundry, the chain running on anvil that pnpm dev
6
+ * starts by default. It is similar to the viem anvil chain
7
+ * (see https://viem.sh/docs/clients/test.html), but with the
8
+ * basefee set to zero to avoid transaction fees.
9
+ * - latticeTestnet, our public test network.
10
+ *
11
+ */
12
+
1
13
  import { MUDChain, latticeTestnet, mudFoundry } from "@latticexyz/common/chains";
2
14
 
3
- // If you are deploying to chains other than anvil or Lattice testnet, add them here
15
+ /*
16
+ * See https://mud.dev/tutorials/minimal/deploy#run-the-user-interface
17
+ * for instructions on how to add networks.
18
+ */
4
19
  export const supportedChains: MUDChain[] = [mudFoundry, latticeTestnet];
@@ -1,5 +1,4 @@
1
- import { createStore } from "zustand/vanilla";
2
- import createReactStore from "zustand";
1
+ import { create } from "zustand";
3
2
  import { NetworkLayer } from "./layers/network/createNetworkLayer";
4
3
  import { PhaserLayer } from "./layers/phaser/createPhaserLayer";
5
4
 
@@ -15,14 +14,12 @@ export type UIStore = {
15
14
  devMode: boolean;
16
15
  };
17
16
 
18
- export const store = createStore<Store>(() => ({
17
+ export const useStore = create<Store>(() => ({
19
18
  networkLayer: null,
20
19
  phaserLayer: null,
21
20
  devMode: false,
22
21
  }));
23
22
 
24
- export const useStore = createReactStore(store);
25
-
26
23
  export const useMUD = () => {
27
24
  const { networkLayer, phaserLayer, devMode } = useStore();
28
25
 
@@ -3,20 +3,37 @@ import { useNetworkLayer } from "./hooks/useNetworkLayer";
3
3
  import { useStore } from "../store";
4
4
  import { PhaserLayer } from "./PhaserLayer";
5
5
  import { UIRoot } from "./UIRoot";
6
+ import mudConfig from "contracts/mud.config";
6
7
 
7
8
  export const App = () => {
8
9
  const networkLayer = useNetworkLayer();
9
10
 
10
11
  useEffect(() => {
11
- if (networkLayer) {
12
- useStore.setState({ networkLayer });
12
+ if (!networkLayer) return;
13
+
14
+ useStore.setState({ networkLayer });
15
+
16
+ // https://vitejs.dev/guide/env-and-mode.html
17
+ if (import.meta.env.DEV) {
18
+ import("@latticexyz/dev-tools").then(({ mount: mountDevTools }) =>
19
+ mountDevTools({
20
+ config: mudConfig,
21
+ publicClient: networkLayer.network.publicClient,
22
+ walletClient: networkLayer.network.walletClient,
23
+ latestBlock$: networkLayer.network.latestBlock$,
24
+ storedBlockLogs$: networkLayer.network.storedBlockLogs$,
25
+ worldAddress: networkLayer.network.worldContract.address,
26
+ worldAbi: networkLayer.network.worldContract.abi,
27
+ write$: networkLayer.network.write$,
28
+ recsWorld: networkLayer.world,
29
+ })
30
+ );
13
31
  }
14
32
  }, [networkLayer]);
15
33
 
16
34
  return (
17
35
  <div>
18
36
  <PhaserLayer networkLayer={networkLayer} />
19
-
20
37
  <UIRoot />
21
38
  </div>
22
39
  );
@@ -4,7 +4,8 @@ import { LoadingBar } from "./LoadingBar";
4
4
  import { BootScreen } from "./BootScreen";
5
5
  import { useComponentValue } from "@latticexyz/react";
6
6
  import { useMUD } from "../../store";
7
- import { SyncStep, singletonEntity } from "@latticexyz/store-sync/recs";
7
+ import { singletonEntity } from "@latticexyz/store-sync/recs";
8
+ import { SyncStep } from "@latticexyz/store-sync";
8
9
 
9
10
  export const LoadingScreen = () => {
10
11
  const {
@@ -3,8 +3,6 @@ cache/
3
3
  node_modules/
4
4
  bindings/
5
5
  artifacts/
6
- abi/
7
- types/
8
6
  broadcast/
9
7
 
10
8
  # Ignore MUD deploy artifacts
@@ -1,5 +1,5 @@
1
1
  [profile.default]
2
- solc_version = "0.8.13"
2
+ solc = "0.8.21"
3
3
  ffi = false
4
4
  fuzz_runs = 256
5
5
  optimizer = true
@@ -4,7 +4,7 @@ export default mudConfig({
4
4
  tables: {
5
5
  Counter: {
6
6
  keySchema: {},
7
- schema: "uint32",
7
+ valueSchema: "uint32",
8
8
  },
9
9
  },
10
10
  });
@@ -4,30 +4,26 @@
4
4
  "private": true,
5
5
  "license": "MIT",
6
6
  "scripts": {
7
- "build": "pnpm run build:mud && pnpm run build:abi && pnpm run build:typechain",
8
- "build:abi": "forge clean && forge build",
9
- "build:mud": "mud tablegen && mud worldgen && mud tsgen --configPath mud.config.ts --out ../client/src/mud",
10
- "build:typechain": "rimraf types && typechain --target=ethers-v5 out/IWorld.sol/IWorld.json",
7
+ "build": "pnpm run build:mud && pnpm run build:abi && pnpm run build:abi-ts",
8
+ "build:abi": "forge clean && forge build --skip test script",
9
+ "build:abi-ts": "mud abi-ts && prettier --write '**/*.abi.json.d.ts'",
10
+ "build:mud": "rimraf src/codegen && mud tablegen && mud worldgen",
11
11
  "deploy:local": "pnpm run build && mud deploy",
12
12
  "deploy:testnet": "pnpm run build && mud deploy --profile=lattice-testnet",
13
- "dev": "pnpm mud dev-contracts --tsgenOutput ../client/src/mud",
13
+ "dev": "pnpm mud dev-contracts",
14
14
  "lint": "pnpm run prettier && pnpm run solhint",
15
15
  "prettier": "prettier --write 'src/**/*.sol'",
16
16
  "solhint": "solhint --config ./.solhint.json 'src/**/*.sol' --fix",
17
17
  "test": "tsc --noEmit && mud test"
18
18
  },
19
19
  "dependencies": {
20
- "@ethersproject/abi": "^5.7.0",
21
- "@ethersproject/bytes": "^5.7.0",
22
- "@ethersproject/providers": "^5.7.2",
23
20
  "@latticexyz/cli": "{{mud-version}}",
24
21
  "@latticexyz/schema-type": "{{mud-version}}",
25
22
  "@latticexyz/store": "{{mud-version}}",
26
23
  "@latticexyz/world": "{{mud-version}}",
27
- "ethers": "^5.7.2"
24
+ "@latticexyz/world-modules": "{{mud-version}}"
28
25
  },
29
26
  "devDependencies": {
30
- "@typechain/ethers-v5": "^10.2.0",
31
27
  "@types/node": "^18.15.11",
32
28
  "ds-test": "https://github.com/dapphub/ds-test.git#e282159d5170298eb2455a6c05280ab5a73a4ef0",
33
29
  "forge-std": "https://github.com/foundry-rs/forge-std.git#74cfb77e308dd188d2f58864aaf44963ae6b88b1",
@@ -35,7 +31,6 @@
35
31
  "prettier-plugin-solidity": "^1.0.0-beta.19",
36
32
  "solhint": "^3.3.7",
37
33
  "solhint-config-mud": "{{mud-version}}",
38
- "solhint-plugin-mud": "{{mud-version}}",
39
- "typechain": "^8.1.1"
34
+ "solhint-plugin-mud": "{{mud-version}}"
40
35
  }
41
36
  }
@@ -1,5 +1,5 @@
1
1
  // SPDX-License-Identifier: MIT
2
- pragma solidity >=0.8.0;
2
+ pragma solidity >=0.8.21;
3
3
 
4
4
  import { Script } from "forge-std/Script.sol";
5
5
  import { console } from "forge-std/console.sol";
@@ -1,5 +1,5 @@
1
1
  // SPDX-License-Identifier: MIT
2
- pragma solidity >=0.8.0;
2
+ pragma solidity >=0.8.21;
3
3
 
4
4
  /* Autogenerated file. Do not edit manually. */
5
5