create-mud 2.0.0-alpha.1.82 → 2.0.0-alpha.1.83
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/{minimal/packages/client → react}/.eslintrc +1 -3
- package/dist/templates/react/package.json +9 -2
- package/dist/templates/react/packages/client/.env +1 -0
- package/dist/templates/react/packages/client/.eslintrc +2 -12
- package/dist/templates/react/packages/client/package.json +12 -17
- package/dist/templates/react/packages/client/src/App.tsx +15 -13
- package/dist/templates/react/packages/client/src/MUDContext.tsx +20 -0
- package/dist/templates/react/packages/client/src/index.tsx +12 -31
- package/dist/templates/react/packages/client/src/mud/clientComponents.ts +1 -0
- package/dist/templates/react/packages/client/src/mud/contractComponents.ts +24 -0
- package/dist/templates/react/packages/client/src/mud/getNetworkConfig.ts +55 -0
- package/dist/templates/react/packages/client/src/mud/setup.ts +92 -0
- package/dist/templates/react/packages/client/src/mud/supportedChains/latticeTestnet.ts +22 -0
- package/dist/templates/react/packages/client/src/mud/supportedChains/types.ts +3 -0
- package/dist/templates/react/packages/client/src/mud/world.ts +3 -0
- package/dist/templates/react/packages/client/tsconfig.json +0 -3
- package/dist/templates/react/packages/client/vite.config.ts +3 -0
- package/dist/templates/react/packages/contracts/.env +8 -0
- package/dist/templates/react/packages/contracts/.gitignore +5 -2
- package/dist/templates/react/packages/contracts/deploys/31337/latest.json +4 -0
- package/dist/templates/react/packages/contracts/deploys/4242/latest.json +4 -0
- package/dist/templates/react/packages/contracts/foundry.toml +9 -1
- package/dist/templates/react/packages/contracts/mud.config.ts +10 -0
- package/dist/templates/react/packages/contracts/package.json +21 -18
- package/dist/templates/react/packages/contracts/remappings.txt +3 -9
- package/dist/templates/react/packages/contracts/script/PostDeploy.s.sol +24 -0
- package/dist/templates/react/packages/contracts/src/codegen/Tables.sol +6 -0
- package/dist/templates/react/packages/contracts/src/codegen/tables/Counter.sol +120 -0
- package/dist/templates/react/packages/contracts/src/codegen/world/IIncrementSystem.sol +8 -0
- package/dist/templates/react/packages/contracts/src/codegen/world/IWorld.sol +16 -0
- package/dist/templates/react/packages/contracts/src/systems/IncrementSystem.sol +7 -15
- package/dist/templates/react/packages/contracts/test/CounterTest.t.sol +38 -0
- package/dist/templates/react/packages/contracts/tsconfig.json +9 -8
- package/dist/templates/vanilla/.eslintrc +10 -0
- package/dist/templates/vanilla/package.json +25 -0
- package/dist/templates/vanilla/packages/client/.env +1 -0
- package/dist/templates/vanilla/packages/client/package.json +30 -0
- package/dist/templates/vanilla/packages/client/src/index.ts +22 -0
- package/dist/templates/vanilla/packages/client/src/mud/clientComponents.ts +1 -0
- package/dist/templates/vanilla/packages/client/src/mud/contractComponents.ts +24 -0
- package/dist/templates/vanilla/packages/client/src/mud/getNetworkConfig.ts +55 -0
- package/dist/templates/vanilla/packages/client/src/mud/setup.ts +92 -0
- package/dist/templates/vanilla/packages/client/src/mud/supportedChains/latticeTestnet.ts +22 -0
- package/dist/templates/vanilla/packages/client/src/mud/supportedChains/types.ts +3 -0
- package/dist/templates/vanilla/packages/client/src/mud/world.ts +3 -0
- package/dist/templates/{minimal → vanilla}/packages/client/tsconfig.json +2 -4
- package/dist/templates/{minimal → vanilla}/packages/client/vite.config.ts +3 -0
- package/dist/templates/vanilla/packages/contracts/.env +8 -0
- package/dist/templates/vanilla/packages/contracts/.gitignore +13 -0
- package/dist/templates/vanilla/packages/contracts/deploys/31337/latest.json +4 -0
- package/dist/templates/vanilla/packages/contracts/deploys/4242/latest.json +4 -0
- package/dist/templates/{minimal → vanilla}/packages/contracts/foundry.toml +9 -1
- package/dist/templates/vanilla/packages/contracts/mud.config.ts +10 -0
- package/dist/templates/vanilla/packages/contracts/package.json +43 -0
- package/dist/templates/vanilla/packages/contracts/remappings.txt +3 -0
- package/dist/templates/vanilla/packages/contracts/script/PostDeploy.s.sol +24 -0
- package/dist/templates/vanilla/packages/contracts/src/codegen/Tables.sol +6 -0
- package/dist/templates/vanilla/packages/contracts/src/codegen/tables/Counter.sol +120 -0
- package/dist/templates/vanilla/packages/contracts/src/codegen/world/IIncrementSystem.sol +8 -0
- package/dist/templates/vanilla/packages/contracts/src/codegen/world/IWorld.sol +16 -0
- package/dist/templates/vanilla/packages/contracts/src/systems/IncrementSystem.sol +14 -0
- package/dist/templates/vanilla/packages/contracts/test/CounterTest.t.sol +38 -0
- package/dist/templates/vanilla/packages/contracts/tsconfig.json +13 -0
- package/package.json +5 -5
- package/dist/templates/minimal/package.json +0 -18
- package/dist/templates/minimal/packages/client/package.json +0 -37
- package/dist/templates/minimal/packages/client/src/config.ts +0 -22
- package/dist/templates/minimal/packages/client/src/index.ts +0 -37
- package/dist/templates/minimal/packages/contracts/.gitignore +0 -10
- package/dist/templates/minimal/packages/contracts/chainSpec.json +0 -5
- package/dist/templates/minimal/packages/contracts/deploy.json +0 -4
- package/dist/templates/minimal/packages/contracts/exports.sh +0 -22
- package/dist/templates/minimal/packages/contracts/package.json +0 -40
- package/dist/templates/minimal/packages/contracts/remappings.txt +0 -9
- package/dist/templates/minimal/packages/contracts/src/components/CounterComponent.sol +0 -9
- package/dist/templates/minimal/packages/contracts/src/libraries/LibMath.sol +0 -10
- package/dist/templates/minimal/packages/contracts/src/systems/IncrementSystem.sol +0 -22
- package/dist/templates/minimal/packages/contracts/src/systems/README.md +0 -7
- package/dist/templates/minimal/packages/contracts/src/test/Deploy.sol +0 -19
- package/dist/templates/minimal/packages/contracts/src/test/Deploy.t.sol +0 -14
- package/dist/templates/minimal/packages/contracts/src/test/LibDeploy.sol +0 -22
- package/dist/templates/minimal/packages/contracts/tsconfig.json +0 -12
- package/dist/templates/react/packages/client/src/config.ts +0 -22
- package/dist/templates/react/packages/contracts/chainSpec.json +0 -5
- package/dist/templates/react/packages/contracts/deploy.json +0 -4
- package/dist/templates/react/packages/contracts/exports.sh +0 -22
- package/dist/templates/react/packages/contracts/src/components/CounterComponent.sol +0 -9
- package/dist/templates/react/packages/contracts/src/libraries/LibMath.sol +0 -10
- package/dist/templates/react/packages/contracts/src/systems/README.md +0 -7
- package/dist/templates/react/packages/contracts/src/test/Deploy.sol +0 -19
- package/dist/templates/react/packages/contracts/src/test/Deploy.t.sol +0 -14
- package/dist/templates/react/packages/contracts/src/test/LibDeploy.sol +0 -22
- /package/dist/templates/{minimal → vanilla}/.gitignore +0 -0
- /package/dist/templates/{minimal → vanilla}/.vscode/extensions.json +0 -0
- /package/dist/templates/{minimal → vanilla}/.vscode/settings.json +0 -0
- /package/dist/templates/{minimal → vanilla}/packages/client/.gitignore +0 -0
- /package/dist/templates/{minimal → vanilla}/packages/client/index.html +0 -0
- /package/dist/templates/{minimal → vanilla}/packages/contracts/.prettierrc +0 -0
- /package/dist/templates/{minimal → vanilla}/packages/contracts/.solhint.json +0 -0
- /package/dist/templates/{minimal → vanilla}/pnpm-workspace.yaml +0 -0
package/dist/cli.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
"use strict";var t=require("create-create-app"),a=require("path");var e={name:"create-mud",version:"2.0.0-alpha.1.
|
|
2
|
+
"use strict";var t=require("create-create-app"),a=require("path");var e={name:"create-mud",version:"2.0.0-alpha.1.83+6c110dc8",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","test:react":"dist/cli.js test-project --template react && 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",typescript:"^4.9.5"},publishConfig:{access:"public",registry:"https://registry.npmjs.org"},gitHead:"6c110dc8b1f55142b1ce5dae144ce10e25eb5308"};var c=(0,a.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:s})=>`Done! Play in the MUD with \`cd ${r.name}\` and \`${s} run dev\``,extra:{"mud-version":{type:"input",describe:"The version of MUD packages to use, defaults to latest",default:e.version}}});
|
|
@@ -6,10 +6,17 @@
|
|
|
6
6
|
"dev": "run-pty % pnpm dev:node % pnpm dev:client % pnpm dev:contracts",
|
|
7
7
|
"dev:client": "pnpm --filter 'client' run dev",
|
|
8
8
|
"dev:contracts": "pnpm --filter 'contracts' dev",
|
|
9
|
-
"dev:node": "pnpm --filter 'contracts' devnode"
|
|
9
|
+
"dev:node": "pnpm --filter 'contracts' devnode",
|
|
10
|
+
"initialize": "pnpm recursive run initialize",
|
|
11
|
+
"test": "pnpm recursive run test"
|
|
10
12
|
},
|
|
11
13
|
"devDependencies": {
|
|
12
|
-
"
|
|
14
|
+
"@typescript-eslint/eslint-plugin": "5.46.1",
|
|
15
|
+
"@typescript-eslint/parser": "5.46.1",
|
|
16
|
+
"eslint": "8.29.0",
|
|
17
|
+
"rimraf": "^3.0.2",
|
|
18
|
+
"run-pty": "^4.0.3",
|
|
19
|
+
"typescript": "^4.9.5"
|
|
13
20
|
},
|
|
14
21
|
"engines": {
|
|
15
22
|
"node": "18.x",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
VITE_CHAIN_ID=31337
|
|
@@ -1,16 +1,6 @@
|
|
|
1
1
|
{
|
|
2
|
-
"
|
|
3
|
-
|
|
4
|
-
},
|
|
5
|
-
"parser": "@typescript-eslint/parser",
|
|
6
|
-
"plugins": ["@typescript-eslint", "react", "react-hooks"],
|
|
7
|
-
"extends": [
|
|
8
|
-
"eslint:recommended",
|
|
9
|
-
"plugin:@typescript-eslint/eslint-recommended",
|
|
10
|
-
"plugin:@typescript-eslint/recommended",
|
|
11
|
-
"plugin:react/recommended",
|
|
12
|
-
"plugin:react-hooks/recommended"
|
|
13
|
-
],
|
|
2
|
+
"extends": ["../../.eslintrc", "plugin:react/recommended", "plugin:react-hooks/recommended"],
|
|
3
|
+
"plugins": ["react", "react-hooks"],
|
|
14
4
|
"rules": {
|
|
15
5
|
"react/react-in-jsx-scope": "off"
|
|
16
6
|
}
|
|
@@ -7,37 +7,32 @@
|
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "vite build",
|
|
9
9
|
"dev": "vite",
|
|
10
|
-
"
|
|
10
|
+
"initialize": "pnpm build",
|
|
11
|
+
"preview": "vite preview",
|
|
12
|
+
"test": "tsc --noEmit"
|
|
11
13
|
},
|
|
12
14
|
"dependencies": {
|
|
13
|
-
"@
|
|
15
|
+
"@ethersproject/providers": "^5.7.2",
|
|
16
|
+
"@latticexyz/dev-tools": "{{mud-version}}",
|
|
14
17
|
"@latticexyz/network": "{{mud-version}}",
|
|
15
18
|
"@latticexyz/react": "{{mud-version}}",
|
|
16
19
|
"@latticexyz/recs": "{{mud-version}}",
|
|
17
|
-
"@latticexyz/
|
|
20
|
+
"@latticexyz/schema-type": "{{mud-version}}",
|
|
18
21
|
"@latticexyz/std-client": "{{mud-version}}",
|
|
19
22
|
"@latticexyz/utils": "{{mud-version}}",
|
|
20
|
-
"
|
|
23
|
+
"@latticexyz/world": "{{mud-version}}",
|
|
24
|
+
"@wagmi/chains": "^0.2.22",
|
|
21
25
|
"contracts": "workspace:*",
|
|
22
26
|
"ethers": "^5.7.2",
|
|
23
|
-
"mobx": "^6.7.0",
|
|
24
|
-
"nice-grpc": "^2.0.1",
|
|
25
|
-
"nice-grpc-web": "^2.0.1",
|
|
26
|
-
"proxy-deep": "^3.1.1",
|
|
27
27
|
"react": "^18.2.0",
|
|
28
|
-
"react-dom": "^18.2.0"
|
|
29
|
-
"threads": "^1.7.0"
|
|
28
|
+
"react-dom": "^18.2.0"
|
|
30
29
|
},
|
|
31
30
|
"devDependencies": {
|
|
32
|
-
"@types/react": "^18.
|
|
33
|
-
"@types/react-dom": "^18.
|
|
34
|
-
"@
|
|
35
|
-
"@typescript-eslint/parser": "5.46.1",
|
|
36
|
-
"@vitejs/plugin-react": "^3.0.0",
|
|
37
|
-
"eslint": "8.29.0",
|
|
31
|
+
"@types/react": "^18.0.11",
|
|
32
|
+
"@types/react-dom": "^18.0.11",
|
|
33
|
+
"@vitejs/plugin-react": "^3.1.0",
|
|
38
34
|
"eslint-plugin-react": "7.31.11",
|
|
39
35
|
"eslint-plugin-react-hooks": "4.6.0",
|
|
40
|
-
"typescript": "^4.9.5",
|
|
41
36
|
"vite": "^4.2.1"
|
|
42
37
|
}
|
|
43
38
|
}
|
|
@@ -1,17 +1,15 @@
|
|
|
1
|
-
import { SingletonID, TxQueue } from "@latticexyz/network";
|
|
2
|
-
import { World } from "@latticexyz/recs";
|
|
3
|
-
import { SystemTypes } from "contracts/types/SystemTypes";
|
|
4
1
|
import { useComponentValue } from "@latticexyz/react";
|
|
5
|
-
import {
|
|
2
|
+
import { useMUD } from "./MUDContext";
|
|
6
3
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
4
|
+
export const App = () => {
|
|
5
|
+
const {
|
|
6
|
+
components: { Counter },
|
|
7
|
+
singletonEntity,
|
|
8
|
+
worldSend,
|
|
9
|
+
} = useMUD();
|
|
10
|
+
|
|
11
|
+
const counter = useComponentValue(Counter, singletonEntity);
|
|
12
12
|
|
|
13
|
-
export const App = ({ systems, components }: Props) => {
|
|
14
|
-
const counter = useComponentValue(components.Counter, singletonIndex);
|
|
15
13
|
return (
|
|
16
14
|
<>
|
|
17
15
|
<div>
|
|
@@ -19,9 +17,13 @@ export const App = ({ systems, components }: Props) => {
|
|
|
19
17
|
</div>
|
|
20
18
|
<button
|
|
21
19
|
type="button"
|
|
22
|
-
onClick={(event) => {
|
|
20
|
+
onClick={async (event) => {
|
|
23
21
|
event.preventDefault();
|
|
24
|
-
|
|
22
|
+
|
|
23
|
+
const tx = await worldSend("increment", []);
|
|
24
|
+
|
|
25
|
+
console.log("increment tx", tx);
|
|
26
|
+
console.log("increment result", await tx.wait());
|
|
25
27
|
}}
|
|
26
28
|
>
|
|
27
29
|
Increment
|
|
@@ -0,0 +1,20 @@
|
|
|
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 = SetupResult & {
|
|
7
|
+
children: ReactNode;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export const MUDProvider = ({ children, ...value }: Props) => {
|
|
11
|
+
const currentValue = useContext(MUDContext);
|
|
12
|
+
if (currentValue) throw new Error("MUDProvider can only be used once");
|
|
13
|
+
return <MUDContext.Provider value={value}>{children}</MUDContext.Provider>;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const useMUD = () => {
|
|
17
|
+
const value = useContext(MUDContext);
|
|
18
|
+
if (!value) throw new Error("Must be used within a MUDProvider");
|
|
19
|
+
return value;
|
|
20
|
+
};
|
|
@@ -1,38 +1,19 @@
|
|
|
1
1
|
import ReactDOM from "react-dom/client";
|
|
2
|
-
import {
|
|
3
|
-
import { createWorld } from "@latticexyz/recs";
|
|
4
|
-
import { SystemTypes } from "contracts/types/SystemTypes";
|
|
5
|
-
import { SystemAbis } from "contracts/types/SystemAbis.mjs";
|
|
6
|
-
import { defineNumberComponent } from "@latticexyz/std-client";
|
|
7
|
-
import { config } from "./config";
|
|
2
|
+
import { mount as mountDevTools } from "@latticexyz/dev-tools";
|
|
8
3
|
import { App } from "./App";
|
|
9
|
-
import {
|
|
4
|
+
import { setup } from "./mud/setup";
|
|
5
|
+
import { MUDProvider } from "./MUDContext";
|
|
10
6
|
|
|
11
7
|
const rootElement = document.getElementById("react-root");
|
|
12
8
|
if (!rootElement) throw new Error("React root not found");
|
|
13
9
|
const root = ReactDOM.createRoot(rootElement);
|
|
14
10
|
|
|
15
|
-
//
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
metadata: {
|
|
25
|
-
contractId: "component.Counter",
|
|
26
|
-
},
|
|
27
|
-
}),
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
// This is where the magic happens
|
|
31
|
-
setupMUDNetwork<typeof components, SystemTypes>(config, world, components, SystemAbis).then(
|
|
32
|
-
({ startSync, systems }) => {
|
|
33
|
-
// After setting up the network, we can tell MUD to start the synchronization process.
|
|
34
|
-
startSync();
|
|
35
|
-
|
|
36
|
-
root.render(<App world={world} systems={systems} components={components} />);
|
|
37
|
-
}
|
|
38
|
-
);
|
|
11
|
+
// TODO: figure out if we actually want this to be async or if we should render something else in the meantime
|
|
12
|
+
setup().then((result) => {
|
|
13
|
+
root.render(
|
|
14
|
+
<MUDProvider {...result}>
|
|
15
|
+
<App />
|
|
16
|
+
</MUDProvider>
|
|
17
|
+
);
|
|
18
|
+
mountDevTools();
|
|
19
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const clientComponents = {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/* Autogenerated file. Do not edit manually. */
|
|
2
|
+
|
|
3
|
+
import { TableId } from "@latticexyz/utils";
|
|
4
|
+
import { defineComponent, Type as RecsType, World } from "@latticexyz/recs";
|
|
5
|
+
|
|
6
|
+
export function defineContractComponents(world: World) {
|
|
7
|
+
return {
|
|
8
|
+
Counter: (() => {
|
|
9
|
+
const tableId = new TableId("", "Counter");
|
|
10
|
+
return defineComponent(
|
|
11
|
+
world,
|
|
12
|
+
{
|
|
13
|
+
value: RecsType.Number,
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
metadata: {
|
|
17
|
+
contractId: tableId.toHexString(),
|
|
18
|
+
tableId: tableId.toString(),
|
|
19
|
+
},
|
|
20
|
+
}
|
|
21
|
+
);
|
|
22
|
+
})(),
|
|
23
|
+
};
|
|
24
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { SetupContractConfig, getBurnerWallet } from "@latticexyz/std-client";
|
|
2
|
+
import { foundry } from "@wagmi/chains";
|
|
3
|
+
import latticeTestnet from "./supportedChains/latticeTestnet";
|
|
4
|
+
import latestLatticeTestnetDeploy from "contracts/deploys/4242/latest.json";
|
|
5
|
+
import latestLocalhostDeploy from "contracts/deploys/31337/latest.json";
|
|
6
|
+
import { MudChain } from "./supportedChains/types";
|
|
7
|
+
|
|
8
|
+
type NetworkConfig = SetupContractConfig & {
|
|
9
|
+
privateKey: string;
|
|
10
|
+
faucetServiceUrl?: string;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export async function getNetworkConfig(): Promise<NetworkConfig> {
|
|
14
|
+
const params = new URLSearchParams(window.location.search);
|
|
15
|
+
|
|
16
|
+
const supportedChains: MudChain[] = [foundry, latticeTestnet];
|
|
17
|
+
const deploys = [latestLocalhostDeploy, latestLatticeTestnetDeploy];
|
|
18
|
+
|
|
19
|
+
const chainId = Number(params.get("chainId") || import.meta.env.VITE_CHAIN_ID);
|
|
20
|
+
const chainIndex = supportedChains.findIndex((c) => c.id === chainId);
|
|
21
|
+
const chain = supportedChains[chainIndex];
|
|
22
|
+
if (!chain) {
|
|
23
|
+
throw new Error(`Chain ${chainId} not found`);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const deploy = deploys[chainIndex];
|
|
27
|
+
if (!deploy) {
|
|
28
|
+
throw new Error(`No deployment found for chain ${chainId}. Did you run \`mud deploy\`?`);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const worldAddress = params.get("worldAddress") || deploy.worldAddress;
|
|
32
|
+
if (!worldAddress) {
|
|
33
|
+
throw new Error("No world address provided");
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return {
|
|
37
|
+
clock: {
|
|
38
|
+
period: 1000,
|
|
39
|
+
initialTime: 0,
|
|
40
|
+
syncInterval: 5000,
|
|
41
|
+
},
|
|
42
|
+
provider: {
|
|
43
|
+
chainId,
|
|
44
|
+
jsonRpcUrl: params.get("rpc") ?? chain.rpcUrls.default.http[0],
|
|
45
|
+
wsRpcUrl: params.get("wsRpc") ?? chain.rpcUrls.default.webSocket?.[0],
|
|
46
|
+
},
|
|
47
|
+
privateKey: getBurnerWallet().value,
|
|
48
|
+
chainId,
|
|
49
|
+
modeUrl: params.get("mode") ?? chain.modeUrl,
|
|
50
|
+
faucetServiceUrl: params.get("faucet") ?? chain.faucetUrl,
|
|
51
|
+
worldAddress,
|
|
52
|
+
initialBlockNumber: Number(params.get("initialBlockNumber")) || deploy.blockNumber || 0,
|
|
53
|
+
devMode: params.get("dev") === "true",
|
|
54
|
+
};
|
|
55
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { setupMUDV2Network } from "@latticexyz/std-client";
|
|
2
|
+
import { createFastTxExecutor, createFaucetService } from "@latticexyz/network";
|
|
3
|
+
import { getNetworkConfig } from "./getNetworkConfig";
|
|
4
|
+
import { defineContractComponents } from "./contractComponents";
|
|
5
|
+
import { clientComponents } from "./clientComponents";
|
|
6
|
+
import { world } from "./world";
|
|
7
|
+
import { Contract, Signer, utils } from "ethers";
|
|
8
|
+
import { JsonRpcProvider } from "@ethersproject/providers";
|
|
9
|
+
import { IWorld__factory } from "contracts/types/ethers-contracts/factories/IWorld__factory";
|
|
10
|
+
|
|
11
|
+
export type SetupResult = Awaited<ReturnType<typeof setup>>;
|
|
12
|
+
|
|
13
|
+
export async function setup() {
|
|
14
|
+
const contractComponents = defineContractComponents(world);
|
|
15
|
+
const networkConfig = await getNetworkConfig();
|
|
16
|
+
const result = await setupMUDV2Network<typeof contractComponents>({
|
|
17
|
+
networkConfig,
|
|
18
|
+
world,
|
|
19
|
+
contractComponents,
|
|
20
|
+
syncThread: "main",
|
|
21
|
+
worldAbi: IWorld__factory.abi,
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
result.startSync();
|
|
25
|
+
|
|
26
|
+
// Request drip from faucet
|
|
27
|
+
const signer = result.network.signer.get();
|
|
28
|
+
if (networkConfig.faucetServiceUrl && signer) {
|
|
29
|
+
const address = await signer.getAddress();
|
|
30
|
+
console.info("[Dev Faucet]: Player address -> ", address);
|
|
31
|
+
|
|
32
|
+
const faucet = createFaucetService(networkConfig.faucetServiceUrl);
|
|
33
|
+
|
|
34
|
+
const requestDrip = async () => {
|
|
35
|
+
const balance = await signer.getBalance();
|
|
36
|
+
console.info(`[Dev Faucet]: Player balance -> ${balance}`);
|
|
37
|
+
const lowBalance = balance?.lte(utils.parseEther("1"));
|
|
38
|
+
if (lowBalance) {
|
|
39
|
+
console.info("[Dev Faucet]: Balance is low, dripping funds to player");
|
|
40
|
+
// Double drip
|
|
41
|
+
await faucet.dripDev({ address });
|
|
42
|
+
await faucet.dripDev({ address });
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
requestDrip();
|
|
47
|
+
// Request a drip every 20 seconds
|
|
48
|
+
setInterval(requestDrip, 20000);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Create a World contract instance
|
|
52
|
+
const worldContract = IWorld__factory.connect(
|
|
53
|
+
networkConfig.worldAddress,
|
|
54
|
+
signer ?? result.network.providers.get().json
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
// Create a fast tx executor
|
|
58
|
+
const fastTxExecutor =
|
|
59
|
+
signer?.provider instanceof JsonRpcProvider
|
|
60
|
+
? await createFastTxExecutor(signer as Signer & { provider: JsonRpcProvider })
|
|
61
|
+
: null;
|
|
62
|
+
|
|
63
|
+
// TODO: infer this from fastTxExecute signature?
|
|
64
|
+
type BoundFastTxExecuteFn<C extends Contract> = <F extends keyof C>(
|
|
65
|
+
func: F,
|
|
66
|
+
args: Parameters<C[F]>,
|
|
67
|
+
options?: {
|
|
68
|
+
retryCount?: number;
|
|
69
|
+
}
|
|
70
|
+
) => Promise<ReturnType<C[F]>>;
|
|
71
|
+
|
|
72
|
+
function bindFastTxExecute<C extends Contract>(contract: C): BoundFastTxExecuteFn<C> {
|
|
73
|
+
return async function (...args) {
|
|
74
|
+
if (!fastTxExecutor) {
|
|
75
|
+
throw new Error("no signer");
|
|
76
|
+
}
|
|
77
|
+
const { tx } = await fastTxExecutor.fastTxExecute(contract, ...args);
|
|
78
|
+
return await tx;
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return {
|
|
83
|
+
...result,
|
|
84
|
+
components: {
|
|
85
|
+
...result.components,
|
|
86
|
+
...clientComponents,
|
|
87
|
+
},
|
|
88
|
+
worldContract,
|
|
89
|
+
worldSend: bindFastTxExecute(worldContract),
|
|
90
|
+
fastTxExecutor,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { MudChain } from "./types";
|
|
2
|
+
|
|
3
|
+
const latticeTestnet = {
|
|
4
|
+
name: "Lattice Testnet",
|
|
5
|
+
id: 4242,
|
|
6
|
+
network: "lattice-testnet",
|
|
7
|
+
nativeCurrency: { decimals: 18, name: "Ether", symbol: "ETH" },
|
|
8
|
+
rpcUrls: {
|
|
9
|
+
default: {
|
|
10
|
+
http: ["https://follower.testnet-chain.linfra.xyz"],
|
|
11
|
+
webSocket: ["wss://follower.testnet-chain.linfra.xyz"],
|
|
12
|
+
},
|
|
13
|
+
public: {
|
|
14
|
+
http: ["https://follower.testnet-chain.linfra.xyz"],
|
|
15
|
+
webSocket: ["wss://follower.testnet-chain.linfra.xyz"],
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
modeUrl: "https://mode.testnet-mud-services.linfra.xyz",
|
|
19
|
+
faucetUrl: "https://faucet.testnet-mud-services.linfra.xyz",
|
|
20
|
+
} as const satisfies MudChain;
|
|
21
|
+
|
|
22
|
+
export default latticeTestnet;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# This .env file is for demonstration purposes only.
|
|
2
|
+
#
|
|
3
|
+
# This should usually be excluded via .gitignore and the env vars attached to
|
|
4
|
+
# your deployment enviroment, but we're including this here for ease of local
|
|
5
|
+
# development. Please do not commit changes to this file!
|
|
6
|
+
#
|
|
7
|
+
# Anvil default private key:
|
|
8
|
+
PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
|
|
@@ -6,6 +6,14 @@ optimizer = true
|
|
|
6
6
|
optimizer_runs = 3000
|
|
7
7
|
verbosity = 1
|
|
8
8
|
src = "src"
|
|
9
|
-
test = "
|
|
9
|
+
test = "test"
|
|
10
10
|
out = "out"
|
|
11
11
|
allow_paths = ["../../node_modules", "../../../../packages"]
|
|
12
|
+
extra_output_files = [
|
|
13
|
+
"abi",
|
|
14
|
+
"evm.bytecode"
|
|
15
|
+
]
|
|
16
|
+
fs_permissions = [{ access = "read", path = "./"}]
|
|
17
|
+
|
|
18
|
+
[profile.lattice-testnet]
|
|
19
|
+
eth_rpc_url = "https://follower.testnet-chain.linfra.xyz"
|
|
@@ -4,37 +4,40 @@
|
|
|
4
4
|
"private": true,
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"build": "
|
|
8
|
-
"deploy": "mud deploy-
|
|
9
|
-
"
|
|
7
|
+
"build": "forge clean && forge build",
|
|
8
|
+
"deploy": "pnpm run initialize && mud deploy-v2",
|
|
9
|
+
"deploy:testnet": "pnpm run initialize && mud deploy-v2 --profile=lattice-testnet",
|
|
10
|
+
"dev": "pnpm run deploy",
|
|
10
11
|
"devnode": "mud devnode",
|
|
11
|
-
"
|
|
12
|
+
"initialize": "pnpm run tablegen && pnpm run worldgen && pnpm run build && pnpm run worldtypes && pnpm run tsgen",
|
|
13
|
+
"lint": "pnpm run prettier && pnpm run solhint",
|
|
12
14
|
"prettier": "prettier --write 'src/**/*.sol'",
|
|
13
15
|
"solhint": "solhint --config ./.solhint.json 'src/**/*.sol' --fix",
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
+
"tablegen": "mud tablegen",
|
|
17
|
+
"test": "tsc --noEmit && mud test-v2",
|
|
18
|
+
"tsgen": "mud tsgen --configPath mud.config.ts --out ../client/src/mud",
|
|
19
|
+
"worldgen": "mud worldgen",
|
|
20
|
+
"worldtypes": "rimraf types && typechain --target=ethers-v5 out/IWorld.sol/IWorld.json"
|
|
16
21
|
},
|
|
17
|
-
"
|
|
22
|
+
"dependencies": {
|
|
18
23
|
"@ethersproject/abi": "^5.7.0",
|
|
19
24
|
"@ethersproject/bytes": "^5.7.0",
|
|
20
25
|
"@ethersproject/providers": "^5.7.2",
|
|
21
26
|
"@latticexyz/cli": "{{mud-version}}",
|
|
22
|
-
"@latticexyz/
|
|
27
|
+
"@latticexyz/schema-type": "{{mud-version}}",
|
|
23
28
|
"@latticexyz/std-contracts": "{{mud-version}}",
|
|
24
|
-
"@
|
|
29
|
+
"@latticexyz/store": "{{mud-version}}",
|
|
30
|
+
"@latticexyz/world": "{{mud-version}}",
|
|
31
|
+
"ethers": "^5.7.2"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
25
34
|
"@typechain/ethers-v5": "^10.2.0",
|
|
26
35
|
"@types/node": "^18.15.11",
|
|
27
36
|
"ds-test": "https://github.com/dapphub/ds-test.git#c9ce3f25bde29fc5eb9901842bf02850dfd2d084",
|
|
28
|
-
"ethers": "^5.7.2",
|
|
29
37
|
"forge-std": "https://github.com/foundry-rs/forge-std.git#b4f121555729b3afb3c5ffccb62ff4b6e2818fd3",
|
|
30
|
-
"
|
|
31
|
-
"prettier": "^
|
|
32
|
-
"prettier-plugin-solidity": "^1.1.2",
|
|
33
|
-
"rimraf": "^3.0.2",
|
|
34
|
-
"run-pty": "^4.0.3",
|
|
38
|
+
"prettier": "^2.6.2",
|
|
39
|
+
"prettier-plugin-solidity": "^1.0.0-beta.19",
|
|
35
40
|
"solhint": "^3.3.7",
|
|
36
|
-
"typechain": "^8.1.1"
|
|
37
|
-
"typescript": "^4.9.5",
|
|
38
|
-
"wait-on": "^6.0.1"
|
|
41
|
+
"typechain": "^8.1.1"
|
|
39
42
|
}
|
|
40
43
|
}
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
std-contracts/=node_modules/@latticexyz/std-contracts/src/
|
|
5
|
-
solecs/=node_modules/@latticexyz/solecs/src/
|
|
6
|
-
memmove/=node_modules/memmove/src/
|
|
7
|
-
ds-test/=node_modules/ds-test/src/
|
|
8
|
-
forge-std/=node_modules/forge-std/src/
|
|
9
|
-
@solidstate/=node_modules/@solidstate/
|
|
1
|
+
ds-test/=./node_modules/ds-test/src/
|
|
2
|
+
forge-std/=./node_modules/forge-std/src/
|
|
3
|
+
@latticexyz/=./node_modules/@latticexyz/
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity >=0.8.0;
|
|
3
|
+
|
|
4
|
+
import { Script } from "forge-std/Script.sol";
|
|
5
|
+
import { console } from "forge-std/console.sol";
|
|
6
|
+
import { IWorld } from "../src/codegen/world/IWorld.sol";
|
|
7
|
+
|
|
8
|
+
contract PostDeploy is Script {
|
|
9
|
+
function run(address worldAddress) external {
|
|
10
|
+
// Load the private key from the `PRIVATE_KEY` environment variable (in .env)
|
|
11
|
+
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
|
|
12
|
+
|
|
13
|
+
// Start broadcasting transactions from the deployer account
|
|
14
|
+
vm.startBroadcast(deployerPrivateKey);
|
|
15
|
+
|
|
16
|
+
// ------------------ EXAMPLES ------------------
|
|
17
|
+
|
|
18
|
+
// Call increment on the world via the registered function selector
|
|
19
|
+
uint32 newValue = IWorld(worldAddress).increment();
|
|
20
|
+
console.log("Increment via IWorld:", newValue);
|
|
21
|
+
|
|
22
|
+
vm.stopBroadcast();
|
|
23
|
+
}
|
|
24
|
+
}
|