-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): deploy custom world (#3131)
- Loading branch information
Showing
42 changed files
with
1,047 additions
and
76 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,24 @@ | ||
--- | ||
"@latticexyz/cli": patch | ||
"@latticexyz/world": patch | ||
--- | ||
|
||
MUD config now supports a `deploy.customWorld` option that, when used with the CLI, will deploy the specified custom World implementation. | ||
Custom implementations must still follow [the World protocol](https://github.com/latticexyz/mud/tree/main/packages/world/ts/protocol-snapshots). | ||
|
||
If you want to extend the world with new functions or override existing registered functions, we recommend using [root systems](https://mud.dev/world/systems#root-systems). | ||
However, there are rare cases where this may not be enough to modify the native/internal World behavior. | ||
Note that deploying a custom World opts out of the world factory, deterministic world deploys, and upgradeable implementation proxy. | ||
|
||
```ts | ||
import { defineWorld } from "@latticexyz/world"; | ||
|
||
export default defineWorld({ | ||
customWorld: { | ||
// path to custom world source from project root | ||
sourcePath: "src/CustomWorld.sol", | ||
// custom world contract name | ||
name: "CustomWorld", | ||
}, | ||
}); | ||
``` |
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
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,12 @@ | ||
out/ | ||
cache/ | ||
node_modules/ | ||
bindings/ | ||
artifacts/ | ||
broadcast/ | ||
|
||
pnpm-lock.yaml | ||
|
||
# Ignore MUD deploy artifacts | ||
deploys/**/*.json | ||
worlds.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,8 @@ | ||
{ | ||
"plugins": ["prettier-plugin-solidity"], | ||
"printWidth": 120, | ||
"semi": true, | ||
"tabWidth": 2, | ||
"useTabs": false, | ||
"bracketSpacing": true | ||
} |
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,12 @@ | ||
{ | ||
"extends": ["solhint:recommended", "mud"], | ||
"plugins": ["mud"], | ||
"rules": { | ||
"compiler-version": ["error", ">=0.8.0"], | ||
"avoid-low-level-calls": "off", | ||
"no-inline-assembly": "off", | ||
"func-visibility": ["warn", { "ignoreConstructors": true }], | ||
"no-empty-blocks": "off", | ||
"no-complex-fallback": "off" | ||
} | ||
} |
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,29 @@ | ||
[profile.default] | ||
solc = "0.8.24" | ||
ffi = false | ||
fuzz_runs = 256 | ||
optimizer = true | ||
optimizer_runs = 3000 | ||
verbosity = 2 | ||
src = "src" | ||
test = "test" | ||
out = "out" | ||
allow_paths = [ | ||
# pnpm symlinks to the project root's node_modules | ||
"../../node_modules", | ||
# template uses linked mud packages from within the mud monorepo | ||
"../../../../packages", | ||
# projects created from this template and using linked mud packages | ||
"../../../mud/packages", | ||
] | ||
extra_output_files = [ | ||
"abi", | ||
"evm.bytecode" | ||
] | ||
fs_permissions = [{ access = "read", path = "./"}] | ||
|
||
[profile.garnet] | ||
eth_rpc_url = "https://rpc.garnetchain.com" | ||
|
||
[profile.redstone] | ||
eth_rpc_url = "https://rpc.redstonechain.com" |
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,22 @@ | ||
import { defineWorld } from "@latticexyz/world"; | ||
|
||
export default defineWorld({ | ||
namespace: "app", | ||
tables: { | ||
Tasks: { | ||
schema: { | ||
id: "bytes32", | ||
createdAt: "uint256", | ||
completedAt: "uint256", | ||
description: "string", | ||
}, | ||
key: ["id"], | ||
}, | ||
}, | ||
deploy: { | ||
customWorld: { | ||
sourcePath: "src/CustomWorld.sol", | ||
name: "CustomWorld", | ||
}, | ||
}, | ||
}); |
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,35 @@ | ||
{ | ||
"name": "mud-example-custom-world", | ||
"version": "0.0.0", | ||
"private": true, | ||
"license": "MIT", | ||
"scripts": { | ||
"build": "mud build", | ||
"clean": "forge clean && shx rm -rf src/**/codegen", | ||
"deploy:garnet": "mud deploy --profile=garnet", | ||
"deploy:local": "mud deploy", | ||
"deploy:redstone": "mud deploy --profile=redstone", | ||
"dev": "mud dev-contracts", | ||
"lint": "pnpm run prettier && pnpm run solhint", | ||
"prettier": "prettier --write 'src/**/*.sol'", | ||
"solhint": "solhint --config ./.solhint.json 'src/**/*.sol' --fix", | ||
"test": "tsc --noEmit && mud test" | ||
}, | ||
"dependencies": { | ||
"@latticexyz/schema-type": "link:../../packages/schema-type", | ||
"@latticexyz/store": "link:../../packages/store", | ||
"@latticexyz/world": "link:../../packages/world" | ||
}, | ||
"devDependencies": { | ||
"@latticexyz/cli": "link:../../packages/cli", | ||
"@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", | ||
"shx": "^0.3.4", | ||
"solhint": "^3.3.7", | ||
"solhint-config-mud": "link:../../packages/solhint-config-mud", | ||
"solhint-plugin-mud": "link:../../packages/solhint-plugin-mud" | ||
} | ||
} |
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 @@ | ||
# this file forces pnpm to treat this separately from the monorepo root workspace |
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 @@ | ||
ds-test/=node_modules/ds-test/src/ | ||
forge-std/=node_modules/forge-std/src/ | ||
@latticexyz/=node_modules/@latticexyz/ |
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,33 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity >=0.8.24; | ||
|
||
import { Script } from "forge-std/Script.sol"; | ||
import { console } from "forge-std/console.sol"; | ||
import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; | ||
|
||
import { IWorld } from "../src/codegen/world/IWorld.sol"; | ||
import { Tasks, TasksData } from "../src/codegen/index.sol"; | ||
|
||
contract PostDeploy is Script { | ||
function run(address worldAddress) external { | ||
// Specify a store so that you can use tables directly in PostDeploy | ||
StoreSwitch.setStoreAddress(worldAddress); | ||
|
||
// Load the private key from the `PRIVATE_KEY` environment variable (in .env) | ||
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY"); | ||
|
||
// Start broadcasting transactions from the deployer account | ||
vm.startBroadcast(deployerPrivateKey); | ||
|
||
// We can set table records directly | ||
Tasks.set("1", TasksData({ description: "Walk the dog", createdAt: block.timestamp, completedAt: 0 })); | ||
|
||
// Or we can call our own systems | ||
IWorld(worldAddress).app__addTask("Take out the trash"); | ||
|
||
bytes32 key = IWorld(worldAddress).app__addTask("Do the dishes"); | ||
IWorld(worldAddress).app__completeTask(key); | ||
|
||
vm.stopBroadcast(); | ||
} | ||
} |
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 { World } from "@latticexyz/world/src/World.sol"; | ||
|
||
contract CustomWorld is World { | ||
function helloWorld() public pure returns (string memory) { | ||
return "Hello world!"; | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.