create-mud 2.2.17-d252fd65ce1e5a2085d1a43ba02df7e985d90aa5 → 2.2.17-d5210ce502a781b858a575a715d97dfd3a91c29d
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 +8 -2
- package/dist/cli.js.map +1 -1
- package/package.json +6 -6
- package/templates/phaser/.gitignore_ +7 -0
- package/templates/phaser/packages/art/.gitignore_ +0 -0
- package/templates/phaser/packages/client/.gitignore_ +3 -0
- package/templates/phaser/packages/contracts/.gitignore_ +9 -0
- package/templates/phaser/packages/contracts/worlds.json +2 -2
- package/templates/react/.gitignore_ +16 -0
- package/templates/react/mprocs.yaml +9 -1
- package/templates/react/packages/client/.gitignore_ +1 -0
- package/templates/react/packages/client/index.html +2 -2
- package/templates/react/packages/client/package.json +17 -9
- package/templates/react/packages/client/postcss.config.cjs +6 -0
- package/templates/react/packages/client/src/App.tsx +41 -100
- package/templates/react/packages/client/src/Providers.tsx +35 -0
- package/templates/react/packages/client/src/common.ts +26 -0
- package/templates/react/packages/client/src/game/GameMap.tsx +102 -0
- package/templates/react/packages/client/src/game/useKeyboardMovement.ts +26 -0
- package/templates/react/packages/client/src/index.tsx +17 -32
- package/templates/react/packages/client/src/mud/Explorer.tsx +32 -0
- package/templates/react/packages/client/src/mud/Synced.tsx +14 -0
- package/templates/react/packages/client/src/mud/stash.ts +4 -0
- package/templates/react/packages/client/src/mud/useSyncStatus.ts +21 -0
- package/templates/react/packages/client/src/mud/useWorldContract.ts +44 -0
- package/templates/react/packages/client/src/ui/AsyncButton.tsx +41 -0
- package/templates/react/packages/client/src/ui/ErrorFallback.tsx +58 -0
- package/templates/react/packages/client/src/ui/icons/ArrowDownIcon.tsx +22 -0
- package/templates/react/packages/client/src/ui/icons/MUDIcon.tsx +25 -0
- package/templates/react/packages/client/src/wagmiConfig.ts +49 -0
- package/templates/react/packages/client/tailwind.config.ts +10 -0
- package/templates/react/packages/client/tsconfig.json +1 -1
- package/templates/react/packages/client/vite.config.ts +2 -7
- package/templates/react/packages/contracts/.env +1 -1
- package/templates/react/packages/contracts/.gitignore_ +13 -0
- package/templates/react/packages/contracts/mud.config.ts +6 -8
- package/templates/react/packages/contracts/out/IWorld.sol/IWorld.abi.json +2021 -0
- package/templates/react/packages/contracts/package.json +1 -0
- package/templates/react/packages/contracts/script/PostDeploy.s.sol +1 -9
- package/templates/react/packages/contracts/src/MoveSystem.sol +26 -0
- package/templates/react/packages/contracts/src/codegen/common.sol +11 -0
- package/templates/react/packages/contracts/src/codegen/index.sol +1 -1
- package/templates/react/packages/contracts/src/codegen/tables/Position.sol +318 -0
- package/templates/{react-ecs/packages/contracts/src/codegen/world/IIncrementSystem.sol → react/packages/contracts/src/codegen/world/IMoveSystem.sol} +5 -3
- package/templates/react/packages/contracts/src/codegen/world/IWorld.sol +2 -2
- package/templates/react/packages/contracts/test/MoveTest.t.sol +25 -0
- package/templates/react/packages/contracts/test/WorldTest.t.sol +16 -0
- package/templates/react/packages/contracts/worlds.json +2 -2
- package/templates/react-ecs/.gitignore_ +16 -0
- package/templates/react-ecs/mprocs.yaml +9 -1
- package/templates/react-ecs/package.json +1 -2
- package/templates/react-ecs/packages/client/.gitignore_ +1 -0
- package/templates/react-ecs/packages/client/index.html +2 -2
- package/templates/react-ecs/packages/client/package.json +16 -9
- package/templates/react-ecs/packages/client/postcss.config.cjs +6 -0
- package/templates/react-ecs/packages/client/src/App.tsx +66 -21
- package/templates/react-ecs/packages/client/src/Providers.tsx +29 -0
- package/templates/react-ecs/packages/client/src/common.ts +27 -0
- package/templates/react-ecs/packages/client/src/game/GameMap.tsx +112 -0
- package/templates/react-ecs/packages/client/src/game/useKeyboardMovement.ts +26 -0
- package/templates/react-ecs/packages/client/src/index.tsx +17 -32
- package/templates/react-ecs/packages/client/src/mud/Explorer.tsx +32 -0
- package/templates/react-ecs/packages/client/src/mud/Synced.tsx +14 -0
- package/templates/react-ecs/packages/client/src/mud/recs.ts +6 -0
- package/templates/react-ecs/packages/client/src/mud/useSyncStatus.ts +17 -0
- package/templates/react-ecs/packages/client/src/mud/useWorldContract.ts +44 -0
- package/templates/react-ecs/packages/client/src/ui/AsyncButton.tsx +41 -0
- package/templates/react-ecs/packages/client/src/ui/ErrorFallback.tsx +58 -0
- package/templates/react-ecs/packages/client/src/ui/icons/ArrowDownIcon.tsx +22 -0
- package/templates/react-ecs/packages/client/src/ui/icons/MUDIcon.tsx +25 -0
- package/templates/react-ecs/packages/client/src/wagmiConfig.ts +49 -0
- package/templates/react-ecs/packages/client/tailwind.config.ts +10 -0
- package/templates/react-ecs/packages/client/tsconfig.json +1 -1
- package/templates/react-ecs/packages/client/vite.config.ts +2 -7
- package/templates/react-ecs/packages/contracts/.env +1 -1
- package/templates/react-ecs/packages/contracts/.gitignore_ +13 -0
- package/templates/react-ecs/packages/contracts/mud.config.ts +11 -6
- package/templates/react-ecs/packages/contracts/out/IWorld.sol/IWorld.abi.json +2039 -0
- package/templates/react-ecs/packages/contracts/package.json +1 -0
- package/templates/react-ecs/packages/contracts/script/PostDeploy.s.sol +1 -5
- package/templates/react-ecs/packages/contracts/src/Entity.sol +20 -0
- package/templates/react-ecs/packages/contracts/src/MoveSystem.sol +30 -0
- package/templates/react-ecs/packages/contracts/src/SpawnSystem.sol +18 -0
- package/templates/react-ecs/packages/contracts/src/codegen/common.sol +11 -0
- package/templates/react-ecs/packages/contracts/src/codegen/index.sol +3 -1
- package/templates/react-ecs/packages/contracts/src/codegen/tables/{Counter.sol → EntityCount.sol} +35 -35
- package/templates/react-ecs/packages/contracts/src/codegen/tables/Owner.sol +202 -0
- package/templates/react-ecs/packages/contracts/src/codegen/tables/Position.sol +321 -0
- package/templates/{react/packages/contracts/src/codegen/world/ITasksSystem.sol → react-ecs/packages/contracts/src/codegen/world/IMoveSystem.sol} +6 -9
- package/templates/react-ecs/packages/contracts/src/codegen/world/ISpawnSystem.sol +15 -0
- package/templates/react-ecs/packages/contracts/src/codegen/world/IWorld.sol +3 -2
- package/templates/react-ecs/packages/contracts/src/createEntity.sol +11 -0
- package/templates/react-ecs/packages/contracts/test/MoveTest.t.sol +39 -0
- package/templates/react-ecs/packages/contracts/test/WorldTest.t.sol +16 -0
- package/templates/react-ecs/packages/contracts/worlds.json +2 -2
- package/templates/threejs/.gitignore_ +7 -0
- package/templates/threejs/packages/client/.gitignore_ +3 -0
- package/templates/threejs/packages/contracts/.gitignore_ +9 -0
- package/templates/threejs/packages/contracts/worlds.json +2 -2
- package/templates/vanilla/.gitignore_ +7 -0
- package/templates/vanilla/packages/client/.gitignore_ +3 -0
- package/templates/vanilla/packages/contracts/.gitignore_ +9 -0
- package/templates/vanilla/packages/contracts/worlds.json +2 -2
- package/templates/react/packages/client/src/MUDContext.tsx +0 -21
- package/templates/react/packages/client/src/mud/createSystemCalls.ts +0 -56
- package/templates/react/packages/client/src/mud/getNetworkConfig.ts +0 -76
- package/templates/react/packages/client/src/mud/setup.ts +0 -18
- package/templates/react/packages/client/src/mud/setupNetwork.ts +0 -101
- package/templates/react/packages/client/src/mud/supportedChains.ts +0 -20
- package/templates/react/packages/contracts/src/codegen/tables/Tasks.sol +0 -522
- package/templates/react/packages/contracts/src/systems/TasksSystem.sol +0 -24
- package/templates/react/packages/contracts/test/TasksTest.t.sol +0 -30
- package/templates/react-ecs/packages/client/src/MUDContext.tsx +0 -21
- package/templates/react-ecs/packages/client/src/mud/createClientComponents.ts +0 -21
- package/templates/react-ecs/packages/client/src/mud/createSystemCalls.ts +0 -51
- package/templates/react-ecs/packages/client/src/mud/getNetworkConfig.ts +0 -77
- package/templates/react-ecs/packages/client/src/mud/setup.ts +0 -21
- package/templates/react-ecs/packages/client/src/mud/setupNetwork.ts +0 -106
- package/templates/react-ecs/packages/client/src/mud/supportedChains.ts +0 -20
- package/templates/react-ecs/packages/client/src/mud/world.ts +0 -3
- package/templates/react-ecs/packages/contracts/src/systems/IncrementSystem.sol +0 -14
- package/templates/react-ecs/packages/contracts/test/CounterTest.t.sol +0 -31
|
@@ -1,30 +0,0 @@
|
|
|
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
|
-
|
|
7
|
-
import { IWorld } from "../src/codegen/world/IWorld.sol";
|
|
8
|
-
import { Tasks, TasksData } from "../src/codegen/index.sol";
|
|
9
|
-
|
|
10
|
-
contract TasksTest is MudTest {
|
|
11
|
-
function testWorldExists() public {
|
|
12
|
-
uint256 codeSize;
|
|
13
|
-
address addr = worldAddress;
|
|
14
|
-
assembly {
|
|
15
|
-
codeSize := extcodesize(addr)
|
|
16
|
-
}
|
|
17
|
-
assertTrue(codeSize > 0);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function testTasks() public {
|
|
21
|
-
// Expect task to exist that we created during PostDeploy script
|
|
22
|
-
TasksData memory task = Tasks.get("1");
|
|
23
|
-
assertEq(task.description, "Walk the dog");
|
|
24
|
-
assertEq(task.completedAt, 0);
|
|
25
|
-
|
|
26
|
-
// Expect the task to be completed after calling completeTask from our TasksSystem
|
|
27
|
-
IWorld(worldAddress).app__completeTask("1");
|
|
28
|
-
assertEq(Tasks.getCompletedAt("1"), block.timestamp);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
@@ -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,21 +0,0 @@
|
|
|
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
|
-
|
|
12
|
-
import { SetupNetworkResult } from "./setupNetwork";
|
|
13
|
-
|
|
14
|
-
export type ClientComponents = ReturnType<typeof createClientComponents>;
|
|
15
|
-
|
|
16
|
-
export function createClientComponents({ components }: SetupNetworkResult) {
|
|
17
|
-
return {
|
|
18
|
-
...components,
|
|
19
|
-
// add your client components or overrides here
|
|
20
|
-
};
|
|
21
|
-
}
|
|
@@ -1,51 +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 { getComponentValue } from "@latticexyz/recs";
|
|
7
|
-
import { ClientComponents } from "./createClientComponents";
|
|
8
|
-
import { SetupNetworkResult } from "./setupNetwork";
|
|
9
|
-
import { singletonEntity } from "@latticexyz/store-sync/recs";
|
|
10
|
-
|
|
11
|
-
export type SystemCalls = ReturnType<typeof createSystemCalls>;
|
|
12
|
-
|
|
13
|
-
export function createSystemCalls(
|
|
14
|
-
/*
|
|
15
|
-
* The parameter list informs TypeScript that:
|
|
16
|
-
*
|
|
17
|
-
* - The first parameter is expected to be a
|
|
18
|
-
* SetupNetworkResult, as defined in setupNetwork.ts
|
|
19
|
-
*
|
|
20
|
-
* Out of this parameter, we only care about two fields:
|
|
21
|
-
* - worldContract (which comes from getContract, see
|
|
22
|
-
* https://github.com/latticexyz/mud/blob/main/templates/react/packages/client/src/mud/setupNetwork.ts#L63-L69).
|
|
23
|
-
*
|
|
24
|
-
* - waitForTransaction (which comes from syncToRecs, see
|
|
25
|
-
* https://github.com/latticexyz/mud/blob/main/templates/react/packages/client/src/mud/setupNetwork.ts#L77-L83).
|
|
26
|
-
*
|
|
27
|
-
* - From the second parameter, which is a ClientComponent,
|
|
28
|
-
* we only care about Counter. This parameter comes to use
|
|
29
|
-
* through createClientComponents.ts, but it originates in
|
|
30
|
-
* syncToRecs
|
|
31
|
-
* (https://github.com/latticexyz/mud/blob/main/templates/react/packages/client/src/mud/setupNetwork.ts#L77-L83).
|
|
32
|
-
*/
|
|
33
|
-
{ worldContract, waitForTransaction }: SetupNetworkResult,
|
|
34
|
-
{ Counter }: ClientComponents,
|
|
35
|
-
) {
|
|
36
|
-
const increment = async () => {
|
|
37
|
-
/*
|
|
38
|
-
* Because IncrementSystem
|
|
39
|
-
* (https://mud.dev/templates/typescript/contracts#incrementsystemsol)
|
|
40
|
-
* is in the root namespace, `.increment` can be called directly
|
|
41
|
-
* on the World contract.
|
|
42
|
-
*/
|
|
43
|
-
const tx = await worldContract.write.app__increment();
|
|
44
|
-
await waitForTransaction(tx);
|
|
45
|
-
return getComponentValue(Counter, singletonEntity);
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
return {
|
|
49
|
-
increment,
|
|
50
|
-
};
|
|
51
|
-
}
|
|
@@ -1,77 +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
|
-
* By default, there are only two chains here:
|
|
23
|
-
*/
|
|
24
|
-
import { supportedChains } from "./supportedChains";
|
|
25
|
-
|
|
26
|
-
export async function getNetworkConfig() {
|
|
27
|
-
const params = new URLSearchParams(window.location.search);
|
|
28
|
-
|
|
29
|
-
/*
|
|
30
|
-
* The chain ID is the first item available from this list:
|
|
31
|
-
* 1. chainId query parameter
|
|
32
|
-
* 2. chainid query parameter
|
|
33
|
-
* 3. The VITE_CHAIN_ID environment variable set when the
|
|
34
|
-
* vite dev server was started or client was built
|
|
35
|
-
* 4. The default, 31337 (anvil)
|
|
36
|
-
*/
|
|
37
|
-
const chainId = Number(params.get("chainId") || params.get("chainid") || import.meta.env.VITE_CHAIN_ID || 31337);
|
|
38
|
-
|
|
39
|
-
/*
|
|
40
|
-
* Find the chain (unless it isn't in the list of supported chains).
|
|
41
|
-
*/
|
|
42
|
-
const chainIndex = supportedChains.findIndex((c) => c.id === chainId);
|
|
43
|
-
const chain = supportedChains[chainIndex];
|
|
44
|
-
if (!chain) {
|
|
45
|
-
throw new Error(`Chain ${chainId} not found`);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/*
|
|
49
|
-
* Get the address of the World. If you want to use a
|
|
50
|
-
* different address than the one in worlds.json,
|
|
51
|
-
* provide it as worldAddress in the query string.
|
|
52
|
-
*/
|
|
53
|
-
const world = worlds[chain.id.toString()];
|
|
54
|
-
const worldAddress = params.get("worldAddress") || world?.address;
|
|
55
|
-
if (!worldAddress) {
|
|
56
|
-
throw new Error(`No world address found for chain ${chainId}. Did you run \`mud deploy\`?`);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/*
|
|
60
|
-
* MUD clients use events to synchronize the database, meaning
|
|
61
|
-
* they need to look as far back as when the World was started.
|
|
62
|
-
* The block number for the World start can be specified either
|
|
63
|
-
* on the URL (as initialBlockNumber) or in the worlds.json
|
|
64
|
-
* file. If neither has it, it starts at the first block, zero.
|
|
65
|
-
*/
|
|
66
|
-
const initialBlockNumber = params.has("initialBlockNumber")
|
|
67
|
-
? Number(params.get("initialBlockNumber"))
|
|
68
|
-
: world?.blockNumber ?? 0n;
|
|
69
|
-
|
|
70
|
-
return {
|
|
71
|
-
privateKey: getBurnerPrivateKey(),
|
|
72
|
-
chainId,
|
|
73
|
-
chain,
|
|
74
|
-
worldAddress,
|
|
75
|
-
initialBlockNumber,
|
|
76
|
-
};
|
|
77
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* This file sets up all the definitions required for a MUD client.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { createClientComponents } from "./createClientComponents";
|
|
6
|
-
import { createSystemCalls } from "./createSystemCalls";
|
|
7
|
-
import { setupNetwork } from "./setupNetwork";
|
|
8
|
-
|
|
9
|
-
export type SetupResult = Awaited<ReturnType<typeof setup>>;
|
|
10
|
-
|
|
11
|
-
export async function setup() {
|
|
12
|
-
const network = await setupNetwork();
|
|
13
|
-
const components = createClientComponents(network);
|
|
14
|
-
const systemCalls = createSystemCalls(network, components);
|
|
15
|
-
|
|
16
|
-
return {
|
|
17
|
-
network,
|
|
18
|
-
components,
|
|
19
|
-
systemCalls,
|
|
20
|
-
};
|
|
21
|
-
}
|
|
@@ -1,106 +0,0 @@
|
|
|
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
|
-
*/
|
|
6
|
-
import {
|
|
7
|
-
createPublicClient,
|
|
8
|
-
fallback,
|
|
9
|
-
webSocket,
|
|
10
|
-
http,
|
|
11
|
-
createWalletClient,
|
|
12
|
-
Hex,
|
|
13
|
-
ClientConfig,
|
|
14
|
-
getContract,
|
|
15
|
-
} from "viem";
|
|
16
|
-
import { encodeEntity, syncToRecs } from "@latticexyz/store-sync/recs";
|
|
17
|
-
|
|
18
|
-
import { getNetworkConfig } from "./getNetworkConfig";
|
|
19
|
-
import { world } from "./world";
|
|
20
|
-
import IWorldAbi from "contracts/out/IWorld.sol/IWorld.abi.json";
|
|
21
|
-
import { createBurnerAccount, transportObserver, ContractWrite } from "@latticexyz/common";
|
|
22
|
-
import { transactionQueue, writeObserver } from "@latticexyz/common/actions";
|
|
23
|
-
|
|
24
|
-
import { Subject, share } from "rxjs";
|
|
25
|
-
|
|
26
|
-
/*
|
|
27
|
-
* Import our MUD config, which includes strong types for
|
|
28
|
-
* our tables and other config options. We use this to generate
|
|
29
|
-
* things like RECS components and get back strong types for them.
|
|
30
|
-
*
|
|
31
|
-
* See https://mud.dev/templates/typescript/contracts#mudconfigts
|
|
32
|
-
* for the source of this information.
|
|
33
|
-
*/
|
|
34
|
-
import mudConfig from "contracts/mud.config";
|
|
35
|
-
|
|
36
|
-
export type SetupNetworkResult = Awaited<ReturnType<typeof setupNetwork>>;
|
|
37
|
-
|
|
38
|
-
export async function setupNetwork() {
|
|
39
|
-
const networkConfig = await getNetworkConfig();
|
|
40
|
-
|
|
41
|
-
/*
|
|
42
|
-
* Create a viem public (read only) client
|
|
43
|
-
* (https://viem.sh/docs/clients/public.html)
|
|
44
|
-
*/
|
|
45
|
-
const clientOptions = {
|
|
46
|
-
chain: networkConfig.chain,
|
|
47
|
-
transport: transportObserver(fallback([webSocket(), http()])),
|
|
48
|
-
pollingInterval: 1000,
|
|
49
|
-
} as const satisfies ClientConfig;
|
|
50
|
-
|
|
51
|
-
const publicClient = createPublicClient(clientOptions);
|
|
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
|
-
|
|
59
|
-
/*
|
|
60
|
-
* Create a temporary wallet and a viem client for it
|
|
61
|
-
* (see https://viem.sh/docs/clients/wallet.html).
|
|
62
|
-
*/
|
|
63
|
-
const burnerAccount = createBurnerAccount(networkConfig.privateKey as Hex);
|
|
64
|
-
const burnerWalletClient = createWalletClient({
|
|
65
|
-
...clientOptions,
|
|
66
|
-
account: burnerAccount,
|
|
67
|
-
})
|
|
68
|
-
.extend(transactionQueue())
|
|
69
|
-
.extend(writeObserver({ onWrite: (write) => write$.next(write) }));
|
|
70
|
-
|
|
71
|
-
/*
|
|
72
|
-
* Create an object for communicating with the deployed World.
|
|
73
|
-
*/
|
|
74
|
-
const worldContract = getContract({
|
|
75
|
-
address: networkConfig.worldAddress as Hex,
|
|
76
|
-
abi: IWorldAbi,
|
|
77
|
-
client: { public: publicClient, wallet: burnerWalletClient },
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
/*
|
|
81
|
-
* Sync on-chain state into RECS and keeps our client in sync.
|
|
82
|
-
* Uses the MUD indexer if available, otherwise falls back
|
|
83
|
-
* to the viem publicClient to make RPC calls to fetch MUD
|
|
84
|
-
* events from the chain.
|
|
85
|
-
*/
|
|
86
|
-
const { components, latestBlock$, storedBlockLogs$, waitForTransaction } = await syncToRecs({
|
|
87
|
-
world,
|
|
88
|
-
config: mudConfig,
|
|
89
|
-
address: networkConfig.worldAddress as Hex,
|
|
90
|
-
publicClient,
|
|
91
|
-
startBlock: BigInt(networkConfig.initialBlockNumber),
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
return {
|
|
95
|
-
world,
|
|
96
|
-
components,
|
|
97
|
-
playerEntity: encodeEntity({ address: "address" }, { address: burnerWalletClient.account.address }),
|
|
98
|
-
publicClient,
|
|
99
|
-
walletClient: burnerWalletClient,
|
|
100
|
-
latestBlock$,
|
|
101
|
-
storedBlockLogs$,
|
|
102
|
-
waitForTransaction,
|
|
103
|
-
worldContract,
|
|
104
|
-
write$: write$.asObservable().pipe(share()),
|
|
105
|
-
};
|
|
106
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
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
|
-
* - Redstone, our production blockchain (https://redstone.xyz/)
|
|
10
|
-
* - Garnet, our test blockchain (https://garnetchain.com/))
|
|
11
|
-
*
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
import { MUDChain, mudFoundry, redstone, garnet } from "@latticexyz/common/chains";
|
|
15
|
-
|
|
16
|
-
/*
|
|
17
|
-
* See https://mud.dev/guides/hello-world/add-chain-client
|
|
18
|
-
* for instructions on how to add networks.
|
|
19
|
-
*/
|
|
20
|
-
export const supportedChains: MUDChain[] = [mudFoundry, redstone, garnet];
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: MIT
|
|
2
|
-
pragma solidity >=0.8.24;
|
|
3
|
-
|
|
4
|
-
import { System } from "@latticexyz/world/src/System.sol";
|
|
5
|
-
import { Counter } from "../codegen/index.sol";
|
|
6
|
-
|
|
7
|
-
contract IncrementSystem is System {
|
|
8
|
-
function increment() public returns (uint32) {
|
|
9
|
-
uint32 counter = Counter.get();
|
|
10
|
-
uint32 newValue = counter + 1;
|
|
11
|
-
Counter.set(newValue);
|
|
12
|
-
return newValue;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
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 { Counter } from "../src/codegen/index.sol";
|
|
10
|
-
|
|
11
|
-
contract CounterTest is MudTest {
|
|
12
|
-
function testWorldExists() public {
|
|
13
|
-
uint256 codeSize;
|
|
14
|
-
address addr = worldAddress;
|
|
15
|
-
assembly {
|
|
16
|
-
codeSize := extcodesize(addr)
|
|
17
|
-
}
|
|
18
|
-
assertTrue(codeSize > 0);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function testCounter() public {
|
|
22
|
-
// Expect the counter to be 1 because it was incremented in the PostDeploy script.
|
|
23
|
-
uint32 counter = Counter.get();
|
|
24
|
-
assertEq(counter, 1);
|
|
25
|
-
|
|
26
|
-
// Expect the counter to be 2 after calling increment.
|
|
27
|
-
IWorld(worldAddress).app__increment();
|
|
28
|
-
counter = Counter.get();
|
|
29
|
-
assertEq(counter, 2);
|
|
30
|
-
}
|
|
31
|
-
}
|