create-mud 2.0.0-transaction-context-324984c5 → 2.0.0
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.
- package/dist/cli.js +1 -1
- package/dist/templates/phaser/.vscode/extensions.json +1 -1
- package/dist/templates/phaser/.vscode/settings.json +3 -1
- package/dist/templates/phaser/package.json +4 -5
- package/dist/templates/phaser/packages/art/package.json +1 -1
- package/dist/templates/phaser/packages/client/package.json +2 -2
- package/dist/templates/phaser/packages/client/src/mud/createSystemCalls.ts +1 -1
- package/dist/templates/phaser/packages/client/src/mud/setupNetwork.ts +23 -12
- package/dist/templates/phaser/packages/client/src/ui/App.tsx +1 -1
- package/dist/templates/phaser/packages/client/src/ui/hooks/usePhaserLayer.tsx +2 -2
- package/dist/templates/phaser/packages/contracts/mud.config.ts +6 -4
- package/dist/templates/phaser/packages/contracts/package.json +2 -2
- package/dist/templates/phaser/packages/contracts/src/codegen/index.sol +1 -1
- package/dist/templates/phaser/packages/contracts/src/codegen/tables/Counter.sol +15 -44
- package/dist/templates/phaser/packages/contracts/src/codegen/world/IIncrementSystem.sol +1 -0
- package/dist/templates/phaser/packages/contracts/src/codegen/world/IWorld.sol +2 -3
- package/dist/templates/phaser/packages/contracts/test/CounterTest.t.sol +1 -1
- package/dist/templates/react/.vscode/extensions.json +1 -1
- package/dist/templates/react/.vscode/settings.json +3 -1
- package/dist/templates/react/package.json +4 -5
- package/dist/templates/react/packages/client/package.json +1 -1
- package/dist/templates/react/packages/client/src/App.tsx +2 -2
- package/dist/templates/react/packages/client/src/index.tsx +1 -1
- package/dist/templates/react/packages/client/src/mud/createSystemCalls.ts +6 -6
- package/dist/templates/react/packages/client/src/mud/setupNetwork.ts +23 -12
- package/dist/templates/react/packages/contracts/mud.config.ts +5 -3
- package/dist/templates/react/packages/contracts/package.json +2 -2
- package/dist/templates/react/packages/contracts/src/codegen/index.sol +1 -1
- package/dist/templates/react/packages/contracts/src/codegen/tables/Tasks.sol +90 -122
- package/dist/templates/react/packages/contracts/src/codegen/world/ITasksSystem.sol +5 -4
- package/dist/templates/react/packages/contracts/src/codegen/world/IWorld.sol +2 -3
- package/dist/templates/react/packages/contracts/src/systems/TasksSystem.sol +9 -9
- package/dist/templates/react-ecs/.vscode/extensions.json +1 -1
- package/dist/templates/react-ecs/.vscode/settings.json +3 -1
- package/dist/templates/react-ecs/package.json +4 -5
- package/dist/templates/react-ecs/packages/client/package.json +1 -1
- package/dist/templates/react-ecs/packages/client/src/index.tsx +1 -1
- package/dist/templates/react-ecs/packages/client/src/mud/createSystemCalls.ts +1 -1
- package/dist/templates/react-ecs/packages/client/src/mud/setupNetwork.ts +23 -12
- package/dist/templates/react-ecs/packages/contracts/mud.config.ts +6 -4
- package/dist/templates/react-ecs/packages/contracts/package.json +2 -2
- package/dist/templates/react-ecs/packages/contracts/src/codegen/index.sol +1 -1
- package/dist/templates/react-ecs/packages/contracts/src/codegen/tables/Counter.sol +15 -44
- package/dist/templates/react-ecs/packages/contracts/src/codegen/world/IIncrementSystem.sol +1 -0
- package/dist/templates/react-ecs/packages/contracts/src/codegen/world/IWorld.sol +2 -3
- package/dist/templates/react-ecs/packages/contracts/test/CounterTest.t.sol +1 -1
- package/dist/templates/threejs/.vscode/extensions.json +1 -1
- package/dist/templates/threejs/.vscode/settings.json +3 -1
- package/dist/templates/threejs/package.json +4 -5
- package/dist/templates/threejs/packages/client/package.json +1 -1
- package/dist/templates/threejs/packages/client/src/index.tsx +1 -1
- package/dist/templates/threejs/packages/client/src/mud/createSystemCalls.ts +1 -1
- package/dist/templates/threejs/packages/client/src/mud/setupNetwork.ts +23 -12
- package/dist/templates/threejs/packages/contracts/mud.config.ts +5 -3
- package/dist/templates/threejs/packages/contracts/package.json +2 -2
- package/dist/templates/threejs/packages/contracts/src/codegen/index.sol +1 -1
- package/dist/templates/threejs/packages/contracts/src/codegen/tables/Position.sol +68 -100
- package/dist/templates/threejs/packages/contracts/src/codegen/world/IMoveSystem.sol +1 -0
- package/dist/templates/threejs/packages/contracts/src/codegen/world/IWorld.sol +2 -3
- package/dist/templates/vanilla/.vscode/extensions.json +1 -1
- package/dist/templates/vanilla/.vscode/settings.json +3 -1
- package/dist/templates/vanilla/package.json +4 -5
- package/dist/templates/vanilla/packages/client/package.json +1 -1
- package/dist/templates/vanilla/packages/client/src/mud/createSystemCalls.ts +1 -1
- package/dist/templates/vanilla/packages/client/src/mud/setupNetwork.ts +23 -12
- package/dist/templates/vanilla/packages/contracts/mud.config.ts +6 -4
- package/dist/templates/vanilla/packages/contracts/package.json +2 -2
- package/dist/templates/vanilla/packages/contracts/src/codegen/index.sol +1 -1
- package/dist/templates/vanilla/packages/contracts/src/codegen/tables/Counter.sol +15 -44
- package/dist/templates/vanilla/packages/contracts/src/codegen/world/IIncrementSystem.sol +1 -0
- package/dist/templates/vanilla/packages/contracts/src/codegen/world/IWorld.sol +2 -3
- package/dist/templates/vanilla/packages/contracts/test/CounterTest.t.sol +1 -1
- package/package.json +1 -2
package/dist/cli.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
"use strict";var t=require("create-create-app"),s=require("path");var e={name:"create-mud",version:"2.0.0
|
|
2
|
+
"use strict";var t=require("create-create-app"),s=require("path");var e={name:"create-mud",version:"2.0.0",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:react-ecs && 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:react-ecs":"dist/cli.js test-project --template react-ecs && 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"}};var c=(0,s.resolve)(__dirname,"..","dist","templates");(0,t.create)("create-mud",{templateRoot:c,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}}});
|
|
@@ -14,13 +14,12 @@
|
|
|
14
14
|
"devDependencies": {
|
|
15
15
|
"@latticexyz/cli": "{{mud-version}}",
|
|
16
16
|
"@types/debug": "4.1.7",
|
|
17
|
-
"@
|
|
18
|
-
"@typescript-eslint/
|
|
19
|
-
"
|
|
20
|
-
"eslint": "8.29.0",
|
|
17
|
+
"@typescript-eslint/eslint-plugin": "7.1.1",
|
|
18
|
+
"@typescript-eslint/parser": "7.1.1",
|
|
19
|
+
"eslint": "8.57.0",
|
|
21
20
|
"mprocs": "^0.6.4",
|
|
22
21
|
"rimraf": "^3.0.2",
|
|
23
|
-
"typescript": "5.
|
|
22
|
+
"typescript": "5.4.2"
|
|
24
23
|
},
|
|
25
24
|
"engines": {
|
|
26
25
|
"node": "18.x",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"@latticexyz/common": "{{mud-version}}",
|
|
15
15
|
"@latticexyz/dev-tools": "{{mud-version}}",
|
|
16
|
-
"@latticexyz/phaserx": "
|
|
16
|
+
"@latticexyz/phaserx": "2.0.0-next.17",
|
|
17
17
|
"@latticexyz/react": "{{mud-version}}",
|
|
18
18
|
"@latticexyz/recs": "{{mud-version}}",
|
|
19
19
|
"@latticexyz/schema-type": "{{mud-version}}",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"simplex-noise": "^4.0.1",
|
|
30
30
|
"styled-components": "^5.3.10",
|
|
31
31
|
"use-resize-observer": "^9.1.0",
|
|
32
|
-
"viem": "
|
|
32
|
+
"viem": "2.7.12",
|
|
33
33
|
"zustand": "^4.3.8"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
@@ -37,7 +37,7 @@ export function createSystemCalls(
|
|
|
37
37
|
* (https://github.com/latticexyz/mud/blob/main/templates/phaser/packages/client/src/mud/setupNetwork.ts#L75-L81).
|
|
38
38
|
*/
|
|
39
39
|
{ worldContract, waitForTransaction }: SetupNetworkResult,
|
|
40
|
-
{ Counter }: ClientComponents
|
|
40
|
+
{ Counter }: ClientComponents,
|
|
41
41
|
) {
|
|
42
42
|
const increment = async () => {
|
|
43
43
|
/*
|
|
@@ -3,13 +3,24 @@
|
|
|
3
3
|
* (https://viem.sh/docs/getting-started.html).
|
|
4
4
|
* This line imports the functions we need from it.
|
|
5
5
|
*/
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
createPublicClient,
|
|
8
|
+
fallback,
|
|
9
|
+
webSocket,
|
|
10
|
+
http,
|
|
11
|
+
createWalletClient,
|
|
12
|
+
Hex,
|
|
13
|
+
parseEther,
|
|
14
|
+
ClientConfig,
|
|
15
|
+
getContract,
|
|
16
|
+
} from "viem";
|
|
7
17
|
import { createFaucetService } from "@latticexyz/services/faucet";
|
|
8
18
|
import { encodeEntity, syncToRecs } from "@latticexyz/store-sync/recs";
|
|
9
19
|
import { getNetworkConfig } from "./getNetworkConfig";
|
|
10
20
|
import { world } from "./world";
|
|
11
21
|
import IWorldAbi from "contracts/out/IWorld.sol/IWorld.abi.json";
|
|
12
|
-
import { createBurnerAccount,
|
|
22
|
+
import { createBurnerAccount, transportObserver, ContractWrite } from "@latticexyz/common";
|
|
23
|
+
import { transactionQueue, writeObserver } from "@latticexyz/common/actions";
|
|
13
24
|
import { Subject, share } from "rxjs";
|
|
14
25
|
|
|
15
26
|
/*
|
|
@@ -39,6 +50,12 @@ export async function setupNetwork() {
|
|
|
39
50
|
|
|
40
51
|
const publicClient = createPublicClient(clientOptions);
|
|
41
52
|
|
|
53
|
+
/*
|
|
54
|
+
* Create an observable for contract writes that we can
|
|
55
|
+
* pass into MUD dev tools for transaction observability.
|
|
56
|
+
*/
|
|
57
|
+
const write$ = new Subject<ContractWrite>();
|
|
58
|
+
|
|
42
59
|
/*
|
|
43
60
|
* Create a temporary wallet and a viem client for it
|
|
44
61
|
* (see https://viem.sh/docs/clients/wallet.html).
|
|
@@ -47,13 +64,9 @@ export async function setupNetwork() {
|
|
|
47
64
|
const burnerWalletClient = createWalletClient({
|
|
48
65
|
...clientOptions,
|
|
49
66
|
account: burnerAccount,
|
|
50
|
-
})
|
|
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>();
|
|
67
|
+
})
|
|
68
|
+
.extend(transactionQueue())
|
|
69
|
+
.extend(writeObserver({ onWrite: (write) => write$.next(write) }));
|
|
57
70
|
|
|
58
71
|
/*
|
|
59
72
|
* Create an object for communicating with the deployed World.
|
|
@@ -61,9 +74,7 @@ export async function setupNetwork() {
|
|
|
61
74
|
const worldContract = getContract({
|
|
62
75
|
address: networkConfig.worldAddress as Hex,
|
|
63
76
|
abi: IWorldAbi,
|
|
64
|
-
publicClient,
|
|
65
|
-
walletClient: burnerWalletClient,
|
|
66
|
-
onWrite: (write) => write$.next(write),
|
|
77
|
+
client: { public: publicClient, wallet: burnerWalletClient },
|
|
67
78
|
});
|
|
68
79
|
|
|
69
80
|
/*
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
2
2
|
import useResizeObserver, { ResizeHandler } from "use-resize-observer";
|
|
3
3
|
import { throttle } from "lodash";
|
|
4
4
|
import { createPhaserLayer } from "../../layers/phaser/createPhaserLayer";
|
|
@@ -80,7 +80,7 @@ export const usePhaserLayer = ({ networkLayer }: Props) => {
|
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
82
|
},
|
|
83
|
-
[container]
|
|
83
|
+
[container],
|
|
84
84
|
);
|
|
85
85
|
|
|
86
86
|
return useMemo(() => ({ ref, phaserLayer }), [ref, phaserLayer]);
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { defineWorld } from "@latticexyz/world";
|
|
2
2
|
|
|
3
|
-
export default
|
|
3
|
+
export default defineWorld({
|
|
4
4
|
tables: {
|
|
5
5
|
Counter: {
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
schema: {
|
|
7
|
+
value: "uint32",
|
|
8
|
+
},
|
|
9
|
+
key: [],
|
|
8
10
|
},
|
|
9
11
|
},
|
|
10
12
|
});
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"@types/node": "^18.15.11",
|
|
26
26
|
"ds-test": "https://github.com/dapphub/ds-test.git#e282159d5170298eb2455a6c05280ab5a73a4ef0",
|
|
27
27
|
"forge-std": "https://github.com/foundry-rs/forge-std.git#74cfb77e308dd188d2f58864aaf44963ae6b88b1",
|
|
28
|
-
"prettier": "
|
|
29
|
-
"prettier-plugin-solidity": "1.1
|
|
28
|
+
"prettier": "3.2.5",
|
|
29
|
+
"prettier-plugin-solidity": "1.3.1",
|
|
30
30
|
"solhint": "^3.3.7",
|
|
31
31
|
"solhint-config-mud": "{{mud-version}}",
|
|
32
32
|
"solhint-plugin-mud": "{{mud-version}}"
|
|
@@ -3,9 +3,6 @@ pragma solidity >=0.8.24;
|
|
|
3
3
|
|
|
4
4
|
/* Autogenerated file. Do not edit manually. */
|
|
5
5
|
|
|
6
|
-
// Import schema type
|
|
7
|
-
import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol";
|
|
8
|
-
|
|
9
6
|
// Import store internals
|
|
10
7
|
import { IStore } from "@latticexyz/store/src/IStore.sol";
|
|
11
8
|
import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol";
|
|
@@ -14,48 +11,22 @@ import { Bytes } from "@latticexyz/store/src/Bytes.sol";
|
|
|
14
11
|
import { Memory } from "@latticexyz/store/src/Memory.sol";
|
|
15
12
|
import { SliceLib } from "@latticexyz/store/src/Slice.sol";
|
|
16
13
|
import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol";
|
|
17
|
-
import { FieldLayout
|
|
18
|
-
import { Schema
|
|
19
|
-
import {
|
|
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";
|
|
20
17
|
import { ResourceId } from "@latticexyz/store/src/ResourceId.sol";
|
|
21
18
|
|
|
22
|
-
// Hex below is the result of `WorldResourceIdLib.encode({ namespace: "", name: "Counter", typeId: RESOURCE_TABLE });`
|
|
23
|
-
ResourceId constant _tableId = ResourceId.wrap(0x74620000000000000000000000000000436f756e746572000000000000000000);
|
|
24
|
-
ResourceId constant CounterTableId = _tableId;
|
|
25
|
-
|
|
26
|
-
FieldLayout constant _fieldLayout = FieldLayout.wrap(
|
|
27
|
-
0x0004010004000000000000000000000000000000000000000000000000000000
|
|
28
|
-
);
|
|
29
|
-
|
|
30
19
|
library Counter {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
* @return _fieldLayout The field layout for the table.
|
|
34
|
-
*/
|
|
35
|
-
function getFieldLayout() internal pure returns (FieldLayout) {
|
|
36
|
-
return _fieldLayout;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* @notice Get the table's key schema.
|
|
41
|
-
* @return _keySchema The key schema for the table.
|
|
42
|
-
*/
|
|
43
|
-
function getKeySchema() internal pure returns (Schema) {
|
|
44
|
-
SchemaType[] memory _keySchema = new SchemaType[](0);
|
|
20
|
+
// Hex below is the result of `WorldResourceIdLib.encode({ namespace: "", name: "Counter", typeId: RESOURCE_TABLE });`
|
|
21
|
+
ResourceId constant _tableId = ResourceId.wrap(0x74620000000000000000000000000000436f756e746572000000000000000000);
|
|
45
22
|
|
|
46
|
-
|
|
47
|
-
|
|
23
|
+
FieldLayout constant _fieldLayout =
|
|
24
|
+
FieldLayout.wrap(0x0004010004000000000000000000000000000000000000000000000000000000);
|
|
48
25
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
function getValueSchema() internal pure returns (Schema) {
|
|
54
|
-
SchemaType[] memory _valueSchema = new SchemaType[](1);
|
|
55
|
-
_valueSchema[0] = SchemaType.UINT32;
|
|
56
|
-
|
|
57
|
-
return SchemaLib.encode(_valueSchema);
|
|
58
|
-
}
|
|
26
|
+
// Hex-encoded key schema of ()
|
|
27
|
+
Schema constant _keySchema = Schema.wrap(0x0000000000000000000000000000000000000000000000000000000000000000);
|
|
28
|
+
// Hex-encoded value schema of (uint32)
|
|
29
|
+
Schema constant _valueSchema = Schema.wrap(0x0004010003000000000000000000000000000000000000000000000000000000);
|
|
59
30
|
|
|
60
31
|
/**
|
|
61
32
|
* @notice Get the table's key field names.
|
|
@@ -78,14 +49,14 @@ library Counter {
|
|
|
78
49
|
* @notice Register the table with its config.
|
|
79
50
|
*/
|
|
80
51
|
function register() internal {
|
|
81
|
-
StoreSwitch.registerTable(_tableId, _fieldLayout,
|
|
52
|
+
StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames());
|
|
82
53
|
}
|
|
83
54
|
|
|
84
55
|
/**
|
|
85
56
|
* @notice Register the table with its config.
|
|
86
57
|
*/
|
|
87
58
|
function _register() internal {
|
|
88
|
-
StoreCore.registerTable(_tableId, _fieldLayout,
|
|
59
|
+
StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames());
|
|
89
60
|
}
|
|
90
61
|
|
|
91
62
|
/**
|
|
@@ -196,10 +167,10 @@ library Counter {
|
|
|
196
167
|
* @return The lengths of the dynamic fields (packed into a single bytes32 value).
|
|
197
168
|
* @return The dynamic (variable length) data, encoded into a sequence of bytes.
|
|
198
169
|
*/
|
|
199
|
-
function encode(uint32 value) internal pure returns (bytes memory,
|
|
170
|
+
function encode(uint32 value) internal pure returns (bytes memory, EncodedLengths, bytes memory) {
|
|
200
171
|
bytes memory _staticData = encodeStatic(value);
|
|
201
172
|
|
|
202
|
-
|
|
173
|
+
EncodedLengths _encodedLengths;
|
|
203
174
|
bytes memory _dynamicData;
|
|
204
175
|
|
|
205
176
|
return (_staticData, _encodedLengths, _dynamicData);
|
|
@@ -5,6 +5,7 @@ pragma solidity >=0.8.24;
|
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* @title IIncrementSystem
|
|
8
|
+
* @author MUD (https://mud.dev) by Lattice (https://lattice.xyz)
|
|
8
9
|
* @dev This interface is automatically generated from the corresponding system contract. Do not edit manually.
|
|
9
10
|
*/
|
|
10
11
|
interface IIncrementSystem {
|
|
@@ -9,10 +9,9 @@ import { IIncrementSystem } from "./IIncrementSystem.sol";
|
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* @title IWorld
|
|
12
|
+
* @author MUD (https://mud.dev) by Lattice (https://lattice.xyz)
|
|
12
13
|
* @notice This interface integrates all systems and associated function selectors
|
|
13
14
|
* that are dynamically registered in the World during deployment.
|
|
14
15
|
* @dev This is an autogenerated file; do not edit manually.
|
|
15
16
|
*/
|
|
16
|
-
interface IWorld is IBaseWorld, IIncrementSystem {
|
|
17
|
-
|
|
18
|
-
}
|
|
17
|
+
interface IWorld is IBaseWorld, IIncrementSystem {}
|
|
@@ -6,7 +6,7 @@ import { MudTest } from "@latticexyz/world/test/MudTest.t.sol";
|
|
|
6
6
|
import { getKeysWithValue } from "@latticexyz/world-modules/src/modules/keyswithvalue/getKeysWithValue.sol";
|
|
7
7
|
|
|
8
8
|
import { IWorld } from "../src/codegen/world/IWorld.sol";
|
|
9
|
-
import { Counter
|
|
9
|
+
import { Counter } from "../src/codegen/index.sol";
|
|
10
10
|
|
|
11
11
|
contract CounterTest is MudTest {
|
|
12
12
|
function testWorldExists() public {
|
|
@@ -14,13 +14,12 @@
|
|
|
14
14
|
"devDependencies": {
|
|
15
15
|
"@latticexyz/cli": "{{mud-version}}",
|
|
16
16
|
"@types/debug": "4.1.7",
|
|
17
|
-
"@
|
|
18
|
-
"@typescript-eslint/
|
|
19
|
-
"
|
|
20
|
-
"eslint": "8.29.0",
|
|
17
|
+
"@typescript-eslint/eslint-plugin": "7.1.1",
|
|
18
|
+
"@typescript-eslint/parser": "7.1.1",
|
|
19
|
+
"eslint": "8.57.0",
|
|
21
20
|
"mprocs": "^0.6.4",
|
|
22
21
|
"rimraf": "^3.0.2",
|
|
23
|
-
"typescript": "5.
|
|
22
|
+
"typescript": "5.4.2"
|
|
24
23
|
},
|
|
25
24
|
"engines": {
|
|
26
25
|
"node": "18.x",
|
|
@@ -31,7 +31,7 @@ export const App = () => {
|
|
|
31
31
|
|
|
32
32
|
checkbox.disabled = true;
|
|
33
33
|
try {
|
|
34
|
-
await toggleTask(task.key.
|
|
34
|
+
await toggleTask(task.key.id);
|
|
35
35
|
} finally {
|
|
36
36
|
checkbox.disabled = false;
|
|
37
37
|
}
|
|
@@ -51,7 +51,7 @@ export const App = () => {
|
|
|
51
51
|
const button = event.currentTarget;
|
|
52
52
|
button.disabled = true;
|
|
53
53
|
try {
|
|
54
|
-
await deleteTask(task.key.
|
|
54
|
+
await deleteTask(task.key.id);
|
|
55
55
|
} finally {
|
|
56
56
|
button.disabled = false;
|
|
57
57
|
}
|
|
@@ -28,21 +28,21 @@ export function createSystemCalls(
|
|
|
28
28
|
* syncToRecs
|
|
29
29
|
* (https://github.com/latticexyz/mud/blob/main/templates/react/packages/client/src/mud/setupNetwork.ts#L77-L83).
|
|
30
30
|
*/
|
|
31
|
-
{ tables, useStore, worldContract, waitForTransaction }: SetupNetworkResult
|
|
31
|
+
{ tables, useStore, worldContract, waitForTransaction }: SetupNetworkResult,
|
|
32
32
|
) {
|
|
33
33
|
const addTask = async (label: string) => {
|
|
34
34
|
const tx = await worldContract.write.addTask([label]);
|
|
35
35
|
await waitForTransaction(tx);
|
|
36
36
|
};
|
|
37
37
|
|
|
38
|
-
const toggleTask = async (
|
|
39
|
-
const isComplete = (useStore.getState().getValue(tables.Tasks, {
|
|
40
|
-
const tx = isComplete ? await worldContract.write.resetTask([
|
|
38
|
+
const toggleTask = async (id: Hex) => {
|
|
39
|
+
const isComplete = (useStore.getState().getValue(tables.Tasks, { id })?.completedAt ?? 0n) > 0n;
|
|
40
|
+
const tx = isComplete ? await worldContract.write.resetTask([id]) : await worldContract.write.completeTask([id]);
|
|
41
41
|
await waitForTransaction(tx);
|
|
42
42
|
};
|
|
43
43
|
|
|
44
|
-
const deleteTask = async (
|
|
45
|
-
const tx = await worldContract.write.deleteTask([
|
|
44
|
+
const deleteTask = async (id: Hex) => {
|
|
45
|
+
const tx = await worldContract.write.deleteTask([id]);
|
|
46
46
|
await waitForTransaction(tx);
|
|
47
47
|
};
|
|
48
48
|
|
|
@@ -3,12 +3,23 @@
|
|
|
3
3
|
* (https://viem.sh/docs/getting-started.html).
|
|
4
4
|
* This line imports the functions we need from it.
|
|
5
5
|
*/
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
createPublicClient,
|
|
8
|
+
fallback,
|
|
9
|
+
webSocket,
|
|
10
|
+
http,
|
|
11
|
+
createWalletClient,
|
|
12
|
+
Hex,
|
|
13
|
+
parseEther,
|
|
14
|
+
ClientConfig,
|
|
15
|
+
getContract,
|
|
16
|
+
} from "viem";
|
|
7
17
|
import { createFaucetService } from "@latticexyz/services/faucet";
|
|
8
18
|
import { syncToZustand } from "@latticexyz/store-sync/zustand";
|
|
9
19
|
import { getNetworkConfig } from "./getNetworkConfig";
|
|
10
20
|
import IWorldAbi from "contracts/out/IWorld.sol/IWorld.abi.json";
|
|
11
|
-
import { createBurnerAccount,
|
|
21
|
+
import { createBurnerAccount, transportObserver, ContractWrite } from "@latticexyz/common";
|
|
22
|
+
import { transactionQueue, writeObserver } from "@latticexyz/common/actions";
|
|
12
23
|
import { Subject, share } from "rxjs";
|
|
13
24
|
|
|
14
25
|
/*
|
|
@@ -38,6 +49,12 @@ export async function setupNetwork() {
|
|
|
38
49
|
|
|
39
50
|
const publicClient = createPublicClient(clientOptions);
|
|
40
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
|
+
|
|
41
58
|
/*
|
|
42
59
|
* Create a temporary wallet and a viem client for it
|
|
43
60
|
* (see https://viem.sh/docs/clients/wallet.html).
|
|
@@ -46,13 +63,9 @@ export async function setupNetwork() {
|
|
|
46
63
|
const burnerWalletClient = createWalletClient({
|
|
47
64
|
...clientOptions,
|
|
48
65
|
account: burnerAccount,
|
|
49
|
-
})
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
* Create an observable for contract writes that we can
|
|
53
|
-
* pass into MUD dev tools for transaction observability.
|
|
54
|
-
*/
|
|
55
|
-
const write$ = new Subject<ContractWrite>();
|
|
66
|
+
})
|
|
67
|
+
.extend(transactionQueue())
|
|
68
|
+
.extend(writeObserver({ onWrite: (write) => write$.next(write) }));
|
|
56
69
|
|
|
57
70
|
/*
|
|
58
71
|
* Create an object for communicating with the deployed World.
|
|
@@ -60,9 +73,7 @@ export async function setupNetwork() {
|
|
|
60
73
|
const worldContract = getContract({
|
|
61
74
|
address: networkConfig.worldAddress as Hex,
|
|
62
75
|
abi: IWorldAbi,
|
|
63
|
-
publicClient,
|
|
64
|
-
walletClient: burnerWalletClient,
|
|
65
|
-
onWrite: (write) => write$.next(write),
|
|
76
|
+
client: { public: publicClient, wallet: burnerWalletClient },
|
|
66
77
|
});
|
|
67
78
|
|
|
68
79
|
/*
|
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { defineWorld } from "@latticexyz/world";
|
|
2
2
|
|
|
3
|
-
export default
|
|
3
|
+
export default defineWorld({
|
|
4
4
|
tables: {
|
|
5
5
|
Tasks: {
|
|
6
|
-
|
|
6
|
+
schema: {
|
|
7
|
+
id: "bytes32",
|
|
7
8
|
createdAt: "uint256",
|
|
8
9
|
completedAt: "uint256",
|
|
9
10
|
description: "string",
|
|
10
11
|
},
|
|
12
|
+
key: ["id"],
|
|
11
13
|
},
|
|
12
14
|
},
|
|
13
15
|
});
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"@types/node": "^18.15.11",
|
|
26
26
|
"ds-test": "https://github.com/dapphub/ds-test.git#e282159d5170298eb2455a6c05280ab5a73a4ef0",
|
|
27
27
|
"forge-std": "https://github.com/foundry-rs/forge-std.git#74cfb77e308dd188d2f58864aaf44963ae6b88b1",
|
|
28
|
-
"prettier": "
|
|
29
|
-
"prettier-plugin-solidity": "1.1
|
|
28
|
+
"prettier": "3.2.5",
|
|
29
|
+
"prettier-plugin-solidity": "1.3.1",
|
|
30
30
|
"solhint": "^3.3.7",
|
|
31
31
|
"solhint-config-mud": "{{mud-version}}",
|
|
32
32
|
"solhint-plugin-mud": "{{mud-version}}"
|