-
Notifications
You must be signed in to change notification settings - Fork 203
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
43 changed files
with
1,864 additions
and
2,813 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"root": true, | ||
"parser": "@typescript-eslint/parser", | ||
"plugins": ["@typescript-eslint"], | ||
"extends": [ | ||
"eslint:recommended", | ||
"plugin:@typescript-eslint/eslint-recommended", | ||
"plugin:@typescript-eslint/recommended" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Minimal MUD example project with multiple clients | ||
|
||
This example project demonstrates how to use the MUD framework to create a simple on-chain application. It includes several client types that you can pick from to run the app or get inspiration from, all using the same underlying smart contracts. | ||
|
||
## Getting started | ||
|
||
1. Since this project uses local MUD dependencies, you need to prepare them first by running this command in the MUD root directory: `pnpm install && pnpm build` | ||
2. To start the development environment of this project, run `pnpm dev` in the project root. This will start a local chain, deploy the contracts in `packages/contracts`, and start a development server for the client. By default the react client (`packages/client-react`) will be used. To use the vanilla client instead, run `pnpm dev:client-vanilla`. | ||
3. Open [localhost:3000](http://localhost:3000) in your browser. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
procs: | ||
client: | ||
cwd: packages/client | ||
shell: pnpm run dev | ||
contracts: | ||
cwd: packages/contracts | ||
shell: pnpm mud dev-contracts --rpc http://127.0.0.1:8545 | ||
anvil: | ||
cwd: packages/contracts | ||
shell: anvil --base-fee 0 --block-time 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"name": "mud-example-minimal", | ||
"private": true, | ||
"scripts": { | ||
"build": "pnpm recursive run build", | ||
"clean": "pnpm recursive run clean", | ||
"dev": "mprocs 'pnpm run dev:contracts' 'pnpm run dev:client-react'", | ||
"dev-with-phaser": "mprocs 'pnpm run dev:contracts' 'pnpm run dev:client-phaser'", | ||
"dev-with-vanilla": "mprocs 'pnpm run dev:contracts' 'pnpm run dev:client-vanilla'", | ||
"dev:client-phaser": "pnpm --filter 'client-phaser' run dev", | ||
"dev:client-react": "pnpm --filter 'client-react' run dev", | ||
"dev:client-vanilla": "pnpm --filter 'client-vanilla' run dev", | ||
"dev:contracts": "pnpm --filter 'contracts' run dev", | ||
"test": "pnpm recursive run test" | ||
}, | ||
"devDependencies": { | ||
"@latticexyz/cli": "link:../../packages/cli", | ||
"@typescript-eslint/eslint-plugin": "7.1.1", | ||
"@typescript-eslint/parser": "7.1.1", | ||
"eslint": "8.57.0", | ||
"mprocs": "^0.6.4", | ||
"typescript": "5.4.2" | ||
}, | ||
"engines": { | ||
"node": "^18", | ||
"pnpm": "^8 || ^9" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"plugins": ["prettier-plugin-solidity"], | ||
"printWidth": 120, | ||
"semi": true, | ||
"tabWidth": 2, | ||
"useTabs": false, | ||
"bracketSpacing": true | ||
} |
3 changes: 2 additions & 1 deletion
3
test/mock-multiple-namespaces/.solhint.json → ...mespaces/packages/contracts/.solhint.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
examples/multiple-namespaces/packages/contracts/mud.config.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { defineWorld } from "@latticexyz/world"; | ||
|
||
export default defineWorld({ | ||
namespace: "game", | ||
tables: { | ||
Health: { | ||
schema: { | ||
player: "address", | ||
value: "uint256", | ||
}, | ||
key: ["player"], | ||
}, | ||
}, | ||
}); |
37 changes: 37 additions & 0 deletions
37
examples/multiple-namespaces/packages/contracts/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{ | ||
"name": "contracts", | ||
"version": "0.0.0", | ||
"private": true, | ||
"license": "MIT", | ||
"scripts": { | ||
"build": "mud build", | ||
"clean": "forge clean && rimraf src/codegen", | ||
"deploy:local": "mud deploy", | ||
"dev": "mud dev-contracts", | ||
"faucet": "DEBUG=mud:faucet faucet-server", | ||
"lint": "pnpm run prettier && pnpm run solhint", | ||
"prettier": "prettier --write 'src/**/*.sol'", | ||
"solhint": "solhint --config ./.solhint.json 'src/**/*.sol' --fix", | ||
"test": "mud test" | ||
}, | ||
"devDependencies": { | ||
"@latticexyz/cli": "link:../../../../packages/cli", | ||
"@latticexyz/faucet": "link:../../../../packages/faucet", | ||
"@latticexyz/schema-type": "link:../../../../packages/schema-type", | ||
"@latticexyz/store": "link:../../../../packages/store", | ||
"@latticexyz/world": "link:../../../../packages/world", | ||
"@latticexyz/world-modules": "link:../../../../packages/world-modules", | ||
"@solidstate/contracts": "^0.0.52", | ||
"@types/node": "^18.15.11", | ||
"ds-test": "https://github.com/dapphub/ds-test.git#e282159d5170298eb2455a6c05280ab5a73a4ef0", | ||
"forge-std": "https://github.com/foundry-rs/forge-std.git#74cfb77e308dd188d2f58864aaf44963ae6b88b1", | ||
"prettier": "3.2.5", | ||
"prettier-plugin-solidity": "1.3.1", | ||
"rimraf": "^3.0.2", | ||
"solhint": "^3.4.1", | ||
"solhint-config-mud": "file:../../../../packages/solhint-config-mud", | ||
"solhint-plugin-mud": "file:../../../../packages/solhint-plugin-mud", | ||
"ts-node": "^10.9.1", | ||
"typescript": "5.4.2" | ||
} | ||
} |
File renamed without changes.
8 changes: 2 additions & 6 deletions
8
...ultiple-namespaces/src/codegen/common.sol → .../packages/contracts/src/codegen/index.sol
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
50 changes: 25 additions & 25 deletions
50
...spaces/src/codegen/game/tables/Health.sol → ...s/contracts/src/codegen/tables/Health.sol
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
6 changes: 3 additions & 3 deletions
6
...espaces/src/codegen/world/IMoveSystem.sol → ...ntracts/src/codegen/world/IHealSystem.sol
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
4 changes: 2 additions & 2 deletions
4
...e-namespaces/src/codegen/world/IWorld.sol → ...es/contracts/src/codegen/world/IWorld.sol
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
6 changes: 6 additions & 0 deletions
6
examples/multiple-namespaces/packages/contracts/src/interfaces/IChatNamespacedSystem.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity >=0.8.24; | ||
|
||
interface IChatNamespacedSystem { | ||
function namespace__sendMessage(string memory message) external; | ||
} |
10 changes: 10 additions & 0 deletions
10
examples/multiple-namespaces/packages/contracts/src/systems/HealSystem.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity >=0.8.24; | ||
import { System } from "@latticexyz/world/src/System.sol"; | ||
import { Health } from "../codegen/tables/Health.sol"; | ||
|
||
contract HealSystem is System { | ||
function heal(address player) public { | ||
Health.set(player, Health.get(player) + 1); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
examples/multiple-namespaces/packages/contracts/test/HealthTest.t.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity >=0.8.24; | ||
|
||
import "forge-std/Test.sol"; | ||
import { MudTest } from "@latticexyz/world/test/MudTest.t.sol"; | ||
|
||
import { IWorld } from "../src/codegen/world/IWorld.sol"; | ||
import { Health } from "../src/codegen/index.sol"; | ||
|
||
contract HealthTest is MudTest { | ||
function testHealth(address player) public { | ||
// Expect health to be 0 initially. | ||
uint256 health = Health.get(player); | ||
assertEq(health, 0); | ||
|
||
// Expect the counter to be 1 after healing. | ||
IWorld(worldAddress).game__heal(player); | ||
health = Health.get(player); | ||
assertEq(health, 1); | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
examples/multiple-namespaces/packages/contracts/tsconfig.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": "../../../../tsconfig.json" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"4242": { | ||
"address": "0xb51cE08442de2aB60f327566db833eed15B47b60", | ||
"blockNumber": 21817970 | ||
}, | ||
"31337": { | ||
"address": "0x6e9474e9c83676b9a71133ff96db43e7aa0a4342" | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
examples/multiple-namespaces/packages/contracts/worlds.json.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
declare const worlds: Partial<Record<string, { address: `0x${string}`; blockNumber?: number }>>; | ||
export default worlds; |
Oops, something went wrong.