create-mud 2.2.17-d252fd65ce1e5a2085d1a43ba02df7e985d90aa5 → 2.2.17-d5f4e1e44bbc260ff21dacdfab0e0f8389e9f304

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 (48) hide show
  1. package/dist/cli.js +8 -2
  2. package/dist/cli.js.map +1 -1
  3. package/package.json +6 -6
  4. package/templates/react/mprocs.yaml +9 -1
  5. package/templates/react/packages/client/index.html +2 -2
  6. package/templates/react/packages/client/package.json +17 -9
  7. package/templates/react/packages/client/postcss.config.cjs +6 -0
  8. package/templates/react/packages/client/src/App.tsx +41 -100
  9. package/templates/react/packages/client/src/Providers.tsx +35 -0
  10. package/templates/react/packages/client/src/common.ts +26 -0
  11. package/templates/react/packages/client/src/game/GameMap.tsx +102 -0
  12. package/templates/react/packages/client/src/game/useKeyboardMovement.ts +26 -0
  13. package/templates/react/packages/client/src/index.tsx +17 -32
  14. package/templates/react/packages/client/src/mud/Explorer.tsx +32 -0
  15. package/templates/react/packages/client/src/mud/Synced.tsx +14 -0
  16. package/templates/react/packages/client/src/mud/stash.ts +4 -0
  17. package/templates/react/packages/client/src/mud/useSyncStatus.ts +21 -0
  18. package/templates/react/packages/client/src/mud/useWorldContract.ts +44 -0
  19. package/templates/react/packages/client/src/ui/AsyncButton.tsx +41 -0
  20. package/templates/react/packages/client/src/ui/ErrorFallback.tsx +58 -0
  21. package/templates/react/packages/client/src/ui/icons/ArrowDownIcon.tsx +22 -0
  22. package/templates/react/packages/client/src/ui/icons/MUDIcon.tsx +25 -0
  23. package/templates/react/packages/client/src/wagmiConfig.ts +49 -0
  24. package/templates/react/packages/client/tailwind.config.ts +10 -0
  25. package/templates/react/packages/client/tsconfig.json +1 -1
  26. package/templates/react/packages/client/vite.config.ts +2 -7
  27. package/templates/react/packages/contracts/mud.config.ts +13 -8
  28. package/templates/react/packages/contracts/out/IWorld.sol/IWorld.abi.json +2021 -0
  29. package/templates/react/packages/contracts/package.json +1 -0
  30. package/templates/react/packages/contracts/script/PostDeploy.s.sol +1 -9
  31. package/templates/react/packages/contracts/src/MoveSystem.sol +26 -0
  32. package/templates/react/packages/contracts/src/codegen/common.sol +11 -0
  33. package/templates/react/packages/contracts/src/codegen/index.sol +1 -1
  34. package/templates/react/packages/contracts/src/codegen/tables/Position.sol +318 -0
  35. package/templates/react/packages/contracts/src/codegen/world/{ITasksSystem.sol → IMoveSystem.sol} +5 -9
  36. package/templates/react/packages/contracts/src/codegen/world/IWorld.sol +2 -2
  37. package/templates/react/packages/contracts/test/MoveTest.t.sol +27 -0
  38. package/templates/react/packages/contracts/test/WorldTest.t.sol +21 -0
  39. package/templates/react/packages/contracts/worlds.json +1 -1
  40. package/templates/react/packages/client/src/MUDContext.tsx +0 -21
  41. package/templates/react/packages/client/src/mud/createSystemCalls.ts +0 -56
  42. package/templates/react/packages/client/src/mud/getNetworkConfig.ts +0 -76
  43. package/templates/react/packages/client/src/mud/setup.ts +0 -18
  44. package/templates/react/packages/client/src/mud/setupNetwork.ts +0 -101
  45. package/templates/react/packages/client/src/mud/supportedChains.ts +0 -20
  46. package/templates/react/packages/contracts/src/codegen/tables/Tasks.sol +0 -522
  47. package/templates/react/packages/contracts/src/systems/TasksSystem.sol +0 -24
  48. package/templates/react/packages/contracts/test/TasksTest.t.sol +0 -30
@@ -17,6 +17,7 @@
17
17
  },
18
18
  "dependencies": {
19
19
  "@latticexyz/cli": "{{mud-version}}",
20
+ "@latticexyz/entrykit": "{{mud-version}}",
20
21
  "@latticexyz/schema-type": "{{mud-version}}",
21
22
  "@latticexyz/store": "{{mud-version}}",
22
23
  "@latticexyz/world": "{{mud-version}}",
@@ -6,7 +6,6 @@ import { console } from "forge-std/console.sol";
6
6
  import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol";
7
7
 
8
8
  import { IWorld } from "../src/codegen/world/IWorld.sol";
9
- import { Tasks, TasksData } from "../src/codegen/index.sol";
10
9
 
11
10
  contract PostDeploy is Script {
12
11
  function run(address worldAddress) external {
@@ -19,14 +18,7 @@ contract PostDeploy is Script {
19
18
  // Start broadcasting transactions from the deployer account
20
19
  vm.startBroadcast(deployerPrivateKey);
21
20
 
22
- // We can set table records directly
23
- Tasks.set("1", TasksData({ description: "Walk the dog", createdAt: block.timestamp, completedAt: 0 }));
24
-
25
- // Or we can call our own systems
26
- IWorld(worldAddress).app__addTask("Take out the trash");
27
-
28
- bytes32 key = IWorld(worldAddress).app__addTask("Do the dishes");
29
- IWorld(worldAddress).app__completeTask(key);
21
+ // TODO
30
22
 
31
23
  vm.stopBroadcast();
32
24
  }
@@ -0,0 +1,26 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity >=0.8.24;
3
+
4
+ import { System } from "@latticexyz/world/src/System.sol";
5
+
6
+ import { Direction } from "./codegen/common.sol";
7
+ import { Position, PositionData } from "./codegen/tables/Position.sol";
8
+
9
+ contract MoveSystem is System {
10
+ function move(Direction direction) public {
11
+ address player = _msgSender();
12
+ PositionData memory position = Position.get(player);
13
+
14
+ if (direction == Direction.North) {
15
+ position.y += 1;
16
+ } else if (direction == Direction.East) {
17
+ position.x += 1;
18
+ } else if (direction == Direction.South) {
19
+ position.y -= 1;
20
+ } else if (direction == Direction.West) {
21
+ position.x -= 1;
22
+ }
23
+
24
+ Position.set(player, position);
25
+ }
26
+ }
@@ -0,0 +1,11 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity >=0.8.24;
3
+
4
+ /* Autogenerated file. Do not edit manually. */
5
+
6
+ enum Direction {
7
+ North,
8
+ East,
9
+ South,
10
+ West
11
+ }
@@ -3,4 +3,4 @@ pragma solidity >=0.8.24;
3
3
 
4
4
  /* Autogenerated file. Do not edit manually. */
5
5
 
6
- import { Tasks, TasksData } from "./tables/Tasks.sol";
6
+ import { Position, PositionData } from "./tables/Position.sol";
@@ -0,0 +1,318 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity >=0.8.24;
3
+
4
+ /* Autogenerated file. Do not edit manually. */
5
+
6
+ // Import store internals
7
+ import { IStore } from "@latticexyz/store/src/IStore.sol";
8
+ import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol";
9
+ import { StoreCore } from "@latticexyz/store/src/StoreCore.sol";
10
+ import { Bytes } from "@latticexyz/store/src/Bytes.sol";
11
+ import { Memory } from "@latticexyz/store/src/Memory.sol";
12
+ import { SliceLib } from "@latticexyz/store/src/Slice.sol";
13
+ import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol";
14
+ import { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol";
15
+ import { Schema } from "@latticexyz/store/src/Schema.sol";
16
+ import { EncodedLengths, EncodedLengthsLib } from "@latticexyz/store/src/EncodedLengths.sol";
17
+ import { ResourceId } from "@latticexyz/store/src/ResourceId.sol";
18
+
19
+ struct PositionData {
20
+ int32 x;
21
+ int32 y;
22
+ }
23
+
24
+ library Position {
25
+ // Hex below is the result of `WorldResourceIdLib.encode({ namespace: "app", name: "Position", typeId: RESOURCE_TABLE });`
26
+ ResourceId constant _tableId = ResourceId.wrap(0x74626170700000000000000000000000506f736974696f6e0000000000000000);
27
+
28
+ FieldLayout constant _fieldLayout =
29
+ FieldLayout.wrap(0x0008020004040000000000000000000000000000000000000000000000000000);
30
+
31
+ // Hex-encoded key schema of (address)
32
+ Schema constant _keySchema = Schema.wrap(0x0014010061000000000000000000000000000000000000000000000000000000);
33
+ // Hex-encoded value schema of (int32, int32)
34
+ Schema constant _valueSchema = Schema.wrap(0x0008020023230000000000000000000000000000000000000000000000000000);
35
+
36
+ /**
37
+ * @notice Get the table's key field names.
38
+ * @return keyNames An array of strings with the names of key fields.
39
+ */
40
+ function getKeyNames() internal pure returns (string[] memory keyNames) {
41
+ keyNames = new string[](1);
42
+ keyNames[0] = "player";
43
+ }
44
+
45
+ /**
46
+ * @notice Get the table's value field names.
47
+ * @return fieldNames An array of strings with the names of value fields.
48
+ */
49
+ function getFieldNames() internal pure returns (string[] memory fieldNames) {
50
+ fieldNames = new string[](2);
51
+ fieldNames[0] = "x";
52
+ fieldNames[1] = "y";
53
+ }
54
+
55
+ /**
56
+ * @notice Register the table with its config.
57
+ */
58
+ function register() internal {
59
+ StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames());
60
+ }
61
+
62
+ /**
63
+ * @notice Register the table with its config.
64
+ */
65
+ function _register() internal {
66
+ StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames());
67
+ }
68
+
69
+ /**
70
+ * @notice Get x.
71
+ */
72
+ function getX(address player) internal view returns (int32 x) {
73
+ bytes32[] memory _keyTuple = new bytes32[](1);
74
+ _keyTuple[0] = bytes32(uint256(uint160(player)));
75
+
76
+ bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout);
77
+ return (int32(uint32(bytes4(_blob))));
78
+ }
79
+
80
+ /**
81
+ * @notice Get x.
82
+ */
83
+ function _getX(address player) internal view returns (int32 x) {
84
+ bytes32[] memory _keyTuple = new bytes32[](1);
85
+ _keyTuple[0] = bytes32(uint256(uint160(player)));
86
+
87
+ bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 0, _fieldLayout);
88
+ return (int32(uint32(bytes4(_blob))));
89
+ }
90
+
91
+ /**
92
+ * @notice Set x.
93
+ */
94
+ function setX(address player, int32 x) internal {
95
+ bytes32[] memory _keyTuple = new bytes32[](1);
96
+ _keyTuple[0] = bytes32(uint256(uint160(player)));
97
+
98
+ StoreSwitch.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((x)), _fieldLayout);
99
+ }
100
+
101
+ /**
102
+ * @notice Set x.
103
+ */
104
+ function _setX(address player, int32 x) internal {
105
+ bytes32[] memory _keyTuple = new bytes32[](1);
106
+ _keyTuple[0] = bytes32(uint256(uint160(player)));
107
+
108
+ StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((x)), _fieldLayout);
109
+ }
110
+
111
+ /**
112
+ * @notice Get y.
113
+ */
114
+ function getY(address player) internal view returns (int32 y) {
115
+ bytes32[] memory _keyTuple = new bytes32[](1);
116
+ _keyTuple[0] = bytes32(uint256(uint160(player)));
117
+
118
+ bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 1, _fieldLayout);
119
+ return (int32(uint32(bytes4(_blob))));
120
+ }
121
+
122
+ /**
123
+ * @notice Get y.
124
+ */
125
+ function _getY(address player) internal view returns (int32 y) {
126
+ bytes32[] memory _keyTuple = new bytes32[](1);
127
+ _keyTuple[0] = bytes32(uint256(uint160(player)));
128
+
129
+ bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 1, _fieldLayout);
130
+ return (int32(uint32(bytes4(_blob))));
131
+ }
132
+
133
+ /**
134
+ * @notice Set y.
135
+ */
136
+ function setY(address player, int32 y) internal {
137
+ bytes32[] memory _keyTuple = new bytes32[](1);
138
+ _keyTuple[0] = bytes32(uint256(uint160(player)));
139
+
140
+ StoreSwitch.setStaticField(_tableId, _keyTuple, 1, abi.encodePacked((y)), _fieldLayout);
141
+ }
142
+
143
+ /**
144
+ * @notice Set y.
145
+ */
146
+ function _setY(address player, int32 y) internal {
147
+ bytes32[] memory _keyTuple = new bytes32[](1);
148
+ _keyTuple[0] = bytes32(uint256(uint160(player)));
149
+
150
+ StoreCore.setStaticField(_tableId, _keyTuple, 1, abi.encodePacked((y)), _fieldLayout);
151
+ }
152
+
153
+ /**
154
+ * @notice Get the full data.
155
+ */
156
+ function get(address player) internal view returns (PositionData memory _table) {
157
+ bytes32[] memory _keyTuple = new bytes32[](1);
158
+ _keyTuple[0] = bytes32(uint256(uint160(player)));
159
+
160
+ (bytes memory _staticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = StoreSwitch.getRecord(
161
+ _tableId,
162
+ _keyTuple,
163
+ _fieldLayout
164
+ );
165
+ return decode(_staticData, _encodedLengths, _dynamicData);
166
+ }
167
+
168
+ /**
169
+ * @notice Get the full data.
170
+ */
171
+ function _get(address player) internal view returns (PositionData memory _table) {
172
+ bytes32[] memory _keyTuple = new bytes32[](1);
173
+ _keyTuple[0] = bytes32(uint256(uint160(player)));
174
+
175
+ (bytes memory _staticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = StoreCore.getRecord(
176
+ _tableId,
177
+ _keyTuple,
178
+ _fieldLayout
179
+ );
180
+ return decode(_staticData, _encodedLengths, _dynamicData);
181
+ }
182
+
183
+ /**
184
+ * @notice Set the full data using individual values.
185
+ */
186
+ function set(address player, int32 x, int32 y) internal {
187
+ bytes memory _staticData = encodeStatic(x, y);
188
+
189
+ EncodedLengths _encodedLengths;
190
+ bytes memory _dynamicData;
191
+
192
+ bytes32[] memory _keyTuple = new bytes32[](1);
193
+ _keyTuple[0] = bytes32(uint256(uint160(player)));
194
+
195
+ StoreSwitch.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData);
196
+ }
197
+
198
+ /**
199
+ * @notice Set the full data using individual values.
200
+ */
201
+ function _set(address player, int32 x, int32 y) internal {
202
+ bytes memory _staticData = encodeStatic(x, y);
203
+
204
+ EncodedLengths _encodedLengths;
205
+ bytes memory _dynamicData;
206
+
207
+ bytes32[] memory _keyTuple = new bytes32[](1);
208
+ _keyTuple[0] = bytes32(uint256(uint160(player)));
209
+
210
+ StoreCore.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout);
211
+ }
212
+
213
+ /**
214
+ * @notice Set the full data using the data struct.
215
+ */
216
+ function set(address player, PositionData memory _table) internal {
217
+ bytes memory _staticData = encodeStatic(_table.x, _table.y);
218
+
219
+ EncodedLengths _encodedLengths;
220
+ bytes memory _dynamicData;
221
+
222
+ bytes32[] memory _keyTuple = new bytes32[](1);
223
+ _keyTuple[0] = bytes32(uint256(uint160(player)));
224
+
225
+ StoreSwitch.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData);
226
+ }
227
+
228
+ /**
229
+ * @notice Set the full data using the data struct.
230
+ */
231
+ function _set(address player, PositionData memory _table) internal {
232
+ bytes memory _staticData = encodeStatic(_table.x, _table.y);
233
+
234
+ EncodedLengths _encodedLengths;
235
+ bytes memory _dynamicData;
236
+
237
+ bytes32[] memory _keyTuple = new bytes32[](1);
238
+ _keyTuple[0] = bytes32(uint256(uint160(player)));
239
+
240
+ StoreCore.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout);
241
+ }
242
+
243
+ /**
244
+ * @notice Decode the tightly packed blob of static data using this table's field layout.
245
+ */
246
+ function decodeStatic(bytes memory _blob) internal pure returns (int32 x, int32 y) {
247
+ x = (int32(uint32(Bytes.getBytes4(_blob, 0))));
248
+
249
+ y = (int32(uint32(Bytes.getBytes4(_blob, 4))));
250
+ }
251
+
252
+ /**
253
+ * @notice Decode the tightly packed blobs using this table's field layout.
254
+ * @param _staticData Tightly packed static fields.
255
+ *
256
+ *
257
+ */
258
+ function decode(
259
+ bytes memory _staticData,
260
+ EncodedLengths,
261
+ bytes memory
262
+ ) internal pure returns (PositionData memory _table) {
263
+ (_table.x, _table.y) = decodeStatic(_staticData);
264
+ }
265
+
266
+ /**
267
+ * @notice Delete all data for given keys.
268
+ */
269
+ function deleteRecord(address player) internal {
270
+ bytes32[] memory _keyTuple = new bytes32[](1);
271
+ _keyTuple[0] = bytes32(uint256(uint160(player)));
272
+
273
+ StoreSwitch.deleteRecord(_tableId, _keyTuple);
274
+ }
275
+
276
+ /**
277
+ * @notice Delete all data for given keys.
278
+ */
279
+ function _deleteRecord(address player) internal {
280
+ bytes32[] memory _keyTuple = new bytes32[](1);
281
+ _keyTuple[0] = bytes32(uint256(uint160(player)));
282
+
283
+ StoreCore.deleteRecord(_tableId, _keyTuple, _fieldLayout);
284
+ }
285
+
286
+ /**
287
+ * @notice Tightly pack static (fixed length) data using this table's schema.
288
+ * @return The static data, encoded into a sequence of bytes.
289
+ */
290
+ function encodeStatic(int32 x, int32 y) internal pure returns (bytes memory) {
291
+ return abi.encodePacked(x, y);
292
+ }
293
+
294
+ /**
295
+ * @notice Encode all of a record's fields.
296
+ * @return The static (fixed length) data, encoded into a sequence of bytes.
297
+ * @return The lengths of the dynamic fields (packed into a single bytes32 value).
298
+ * @return The dynamic (variable length) data, encoded into a sequence of bytes.
299
+ */
300
+ function encode(int32 x, int32 y) internal pure returns (bytes memory, EncodedLengths, bytes memory) {
301
+ bytes memory _staticData = encodeStatic(x, y);
302
+
303
+ EncodedLengths _encodedLengths;
304
+ bytes memory _dynamicData;
305
+
306
+ return (_staticData, _encodedLengths, _dynamicData);
307
+ }
308
+
309
+ /**
310
+ * @notice Encode keys as a bytes32 array using this table's field layout.
311
+ */
312
+ function encodeKeyTuple(address player) internal pure returns (bytes32[] memory) {
313
+ bytes32[] memory _keyTuple = new bytes32[](1);
314
+ _keyTuple[0] = bytes32(uint256(uint160(player)));
315
+
316
+ return _keyTuple;
317
+ }
318
+ }
@@ -3,17 +3,13 @@ pragma solidity >=0.8.24;
3
3
 
4
4
  /* Autogenerated file. Do not edit manually. */
5
5
 
6
+ import { Direction } from "../common.sol";
7
+
6
8
  /**
7
- * @title ITasksSystem
9
+ * @title IMoveSystem
8
10
  * @author MUD (https://mud.dev) by Lattice (https://lattice.xyz)
9
11
  * @dev This interface is automatically generated from the corresponding system contract. Do not edit manually.
10
12
  */
11
- interface ITasksSystem {
12
- function app__addTask(string memory description) external returns (bytes32 id);
13
-
14
- function app__completeTask(bytes32 id) external;
15
-
16
- function app__resetTask(bytes32 id) external;
17
-
18
- function app__deleteTask(bytes32 id) external;
13
+ interface IMoveSystem {
14
+ function app__move(Direction direction) external;
19
15
  }
@@ -4,7 +4,7 @@ pragma solidity >=0.8.24;
4
4
  /* Autogenerated file. Do not edit manually. */
5
5
 
6
6
  import { IBaseWorld } from "@latticexyz/world/src/codegen/interfaces/IBaseWorld.sol";
7
- import { ITasksSystem } from "./ITasksSystem.sol";
7
+ import { IMoveSystem } from "./IMoveSystem.sol";
8
8
 
9
9
  /**
10
10
  * @title IWorld
@@ -13,4 +13,4 @@ import { ITasksSystem } from "./ITasksSystem.sol";
13
13
  * that are dynamically registered in the World during deployment.
14
14
  * @dev This is an autogenerated file; do not edit manually.
15
15
  */
16
- interface IWorld is IBaseWorld, ITasksSystem {}
16
+ interface IWorld is IBaseWorld, IMoveSystem {}
@@ -0,0 +1,27 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity >=0.8.24;
3
+
4
+ import "forge-std/Test.sol";
5
+ import { MudTest } from "@latticexyz/world/test/MudTest.t.sol";
6
+ import { getKeysWithValue } from "@latticexyz/world-modules/src/modules/keyswithvalue/getKeysWithValue.sol";
7
+
8
+ import { IWorld } from "../src/codegen/world/IWorld.sol";
9
+ import { Position, PositionData } from "../src/codegen/tables/Position.sol";
10
+ import { Direction } from "../src/codegen/common.sol";
11
+
12
+ contract MoveTest is MudTest {
13
+ function testMove() public {
14
+ address alice = vm.addr(uint256(keccak256("alice")));
15
+ vm.startPrank(alice);
16
+
17
+ PositionData memory position = Position.get(alice);
18
+ assertEq(position.x, 0);
19
+ assertEq(position.y, 0);
20
+
21
+ IWorld(worldAddress).app__move(Direction.North);
22
+ position = Position.get(alice);
23
+
24
+ assertEq(position.x, 0);
25
+ assertEq(position.y, 1);
26
+ }
27
+ }
@@ -0,0 +1,21 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity >=0.8.24;
3
+
4
+ import "forge-std/Test.sol";
5
+ import { MudTest } from "@latticexyz/world/test/MudTest.t.sol";
6
+ import { getKeysWithValue } from "@latticexyz/world-modules/src/modules/keyswithvalue/getKeysWithValue.sol";
7
+
8
+ import { IWorld } from "../src/codegen/world/IWorld.sol";
9
+ import { Position, PositionData } from "../src/codegen/tables/Position.sol";
10
+ import { Direction } from "../src/codegen/common.sol";
11
+
12
+ contract WorldTest is MudTest {
13
+ function testWorldDeployed() public {
14
+ uint256 codeSize;
15
+ address addr = worldAddress;
16
+ assembly {
17
+ codeSize := extcodesize(addr)
18
+ }
19
+ assertTrue(codeSize > 0);
20
+ }
21
+ }
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "31337": {
3
- "address": "0x8d8b6b8414e1e3dcfd4168561b9be6bd3bf6ec4b"
3
+ "address": "0xfdf868ea710ffd8cd33b829c5aff79edd15ecd5f"
4
4
  }
5
5
  }
@@ -1,21 +0,0 @@
1
- import { createContext, ReactNode, useContext } from "react";
2
- import { SetupResult } from "./mud/setup";
3
-
4
- const MUDContext = createContext<SetupResult | null>(null);
5
-
6
- type Props = {
7
- children: ReactNode;
8
- value: SetupResult;
9
- };
10
-
11
- export const MUDProvider = ({ children, value }: Props) => {
12
- const currentValue = useContext(MUDContext);
13
- if (currentValue) throw new Error("MUDProvider can only be used once");
14
- return <MUDContext.Provider value={value}>{children}</MUDContext.Provider>;
15
- };
16
-
17
- export const useMUD = () => {
18
- const value = useContext(MUDContext);
19
- if (!value) throw new Error("Must be used within a MUDProvider");
20
- return value;
21
- };
@@ -1,56 +0,0 @@
1
- /*
2
- * Create the system calls that the client can use to ask
3
- * for changes in the World state (using the System contracts).
4
- */
5
-
6
- import { Hex } from "viem";
7
- import { SetupNetworkResult } from "./setupNetwork";
8
-
9
- export type SystemCalls = ReturnType<typeof createSystemCalls>;
10
-
11
- export function createSystemCalls(
12
- /*
13
- * The parameter list informs TypeScript that:
14
- *
15
- * - The first parameter is expected to be a
16
- * SetupNetworkResult, as defined in setupNetwork.ts
17
- *
18
- * Out of this parameter, we only care about two fields:
19
- * - worldContract (which comes from getContract, see
20
- * https://github.com/latticexyz/mud/blob/main/templates/react/packages/client/src/mud/setupNetwork.ts#L63-L69).
21
- *
22
- * - waitForTransaction (which comes from syncToRecs, see
23
- * https://github.com/latticexyz/mud/blob/main/templates/react/packages/client/src/mud/setupNetwork.ts#L77-L83).
24
- *
25
- * - From the second parameter, which is a ClientComponent,
26
- * we only care about Counter. This parameter comes to use
27
- * through createClientComponents.ts, but it originates in
28
- * syncToRecs
29
- * (https://github.com/latticexyz/mud/blob/main/templates/react/packages/client/src/mud/setupNetwork.ts#L77-L83).
30
- */
31
- { tables, useStore, worldContract, waitForTransaction }: SetupNetworkResult,
32
- ) {
33
- const addTask = async (label: string) => {
34
- const tx = await worldContract.write.app__addTask([label]);
35
- await waitForTransaction(tx);
36
- };
37
-
38
- const toggleTask = async (id: Hex) => {
39
- const isComplete = (useStore.getState().getValue(tables.Tasks, { id })?.completedAt ?? 0n) > 0n;
40
- const tx = isComplete
41
- ? await worldContract.write.app__resetTask([id])
42
- : await worldContract.write.app__completeTask([id]);
43
- await waitForTransaction(tx);
44
- };
45
-
46
- const deleteTask = async (id: Hex) => {
47
- const tx = await worldContract.write.app__deleteTask([id]);
48
- await waitForTransaction(tx);
49
- };
50
-
51
- return {
52
- addTask,
53
- toggleTask,
54
- deleteTask,
55
- };
56
- }
@@ -1,76 +0,0 @@
1
- /*
2
- * Network specific configuration for the client.
3
- * By default connect to the anvil test network.
4
- *
5
- */
6
-
7
- /*
8
- * By default the template just creates a temporary wallet
9
- * (called a burner wallet).
10
- */
11
- import { getBurnerPrivateKey } from "@latticexyz/common";
12
-
13
- /*
14
- * Import the addresses of the World, possibly on multiple chains,
15
- * from packages/contracts/worlds.json. When the contracts package
16
- * deploys a new `World`, it updates this file.
17
- */
18
- import worlds from "contracts/worlds.json";
19
-
20
- /*
21
- * The supported chains.
22
- */
23
- import { supportedChains } from "./supportedChains";
24
-
25
- export async function getNetworkConfig() {
26
- const params = new URLSearchParams(window.location.search);
27
-
28
- /*
29
- * The chain ID is the first item available from this list:
30
- * 1. chainId query parameter
31
- * 2. chainid query parameter
32
- * 3. The VITE_CHAIN_ID environment variable set when the
33
- * vite dev server was started or client was built
34
- * 4. The default, 31337 (anvil)
35
- */
36
- const chainId = Number(params.get("chainId") || params.get("chainid") || import.meta.env.VITE_CHAIN_ID || 31337);
37
-
38
- /*
39
- * Find the chain (unless it isn't in the list of supported chains).
40
- */
41
- const chainIndex = supportedChains.findIndex((c) => c.id === chainId);
42
- const chain = supportedChains[chainIndex];
43
- if (!chain) {
44
- throw new Error(`Chain ${chainId} not found`);
45
- }
46
-
47
- /*
48
- * Get the address of the World. If you want to use a
49
- * different address than the one in worlds.json,
50
- * provide it as worldAddress in the query string.
51
- */
52
- const world = worlds[chain.id.toString()];
53
- const worldAddress = params.get("worldAddress") || world?.address;
54
- if (!worldAddress) {
55
- throw new Error(`No world address found for chain ${chainId}. Did you run \`mud deploy\`?`);
56
- }
57
-
58
- /*
59
- * MUD clients use events to synchronize the database, meaning
60
- * they need to look as far back as when the World was started.
61
- * The block number for the World start can be specified either
62
- * on the URL (as initialBlockNumber) or in the worlds.json
63
- * file. If neither has it, it starts at the first block, zero.
64
- */
65
- const initialBlockNumber = params.has("initialBlockNumber")
66
- ? Number(params.get("initialBlockNumber"))
67
- : world?.blockNumber ?? 0n;
68
-
69
- return {
70
- privateKey: getBurnerPrivateKey(),
71
- chainId,
72
- chain,
73
- worldAddress,
74
- initialBlockNumber,
75
- };
76
- }
@@ -1,18 +0,0 @@
1
- /*
2
- * This file sets up all the definitions required for a MUD client.
3
- */
4
-
5
- import { createSystemCalls } from "./createSystemCalls";
6
- import { setupNetwork } from "./setupNetwork";
7
-
8
- export type SetupResult = Awaited<ReturnType<typeof setup>>;
9
-
10
- export async function setup() {
11
- const network = await setupNetwork();
12
- const systemCalls = createSystemCalls(network);
13
-
14
- return {
15
- network,
16
- systemCalls,
17
- };
18
- }