Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: v2 - add store, world and schema-type, cli table code generation (
#422) BREAKING CHANGE: This commit removes the deprecated `mud deploy` CLI command. Use `mud deploy-contracts` instead. --------- Co-authored-by: alvarius <89248902+alvrs@users.noreply.github.com> Co-authored-by: alvrs <alvrs@users.noreply.github.com> Co-authored-by: alvrs <alvarius@lattice.xyz> Co-authored-by: dk1a <dk1a@protonmail.com> Co-authored-by: dk1a <dk1a@users.noreply.github.com>
- Loading branch information
1 parent
3fdaa98
commit cb731e0
Showing
176 changed files
with
20,917 additions
and
1,713 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,34 @@ | ||
# .github/workflows/gasreport.yml | ||
name: Gas report | ||
|
||
on: | ||
pull_request: | ||
paths: | ||
- packages/store/** | ||
- packages/world/** | ||
|
||
jobs: | ||
gas-report: | ||
runs-on: ubuntu-22.04 | ||
name: Generate gas report | ||
steps: | ||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: 16 | ||
|
||
- name: git-checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Install Foundry | ||
uses: foundry-rs/foundry-toolchain@v1 | ||
with: | ||
version: nightly | ||
|
||
- name: Install dependencies | ||
run: yarn install --network-concurrency 1 | ||
|
||
- name: Install local CLI | ||
run: cd packages/cli && yarn build && npm link && cd ../.. | ||
|
||
- name: Verify that gas report is up to date | ||
run: yarn workspace @latticexyz/store run gasreport && yarn workspace @latticexyz/world run gasreport && if [ -n "$(git status --porcelain)" ]; then exit 0; fi |
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 |
---|---|---|
|
@@ -5,6 +5,7 @@ on: | |
push: | ||
branches: | ||
- main | ||
- v2 | ||
pull_request: | ||
merge_group: | ||
|
||
|
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
declare module "netlify"; | ||
declare module "inquirer-prompt-suggest"; | ||
declare module "prettier-plugin-solidity"; | ||
declare module "long"; |
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 |
---|---|---|
@@ -1,44 +1,50 @@ | ||
import { Arguments, CommandBuilder } from "yargs"; | ||
import { execa } from "execa"; | ||
import path from "path"; | ||
import type { CommandModule } from "yargs"; | ||
|
||
const importExeca = eval('import("execa")') as Promise<typeof import("execa")>; | ||
const contractsDirectory = new URL("../src/contracts", import.meta.url).pathname; | ||
|
||
type Options = { | ||
statePath: string; | ||
worldAddress: string; | ||
rpc: string; | ||
}; | ||
|
||
export const command = "bulkupload"; | ||
export const desc = "Uploads the provided ECS state to the provided World"; | ||
|
||
export const builder: CommandBuilder<Options, Options> = (yargs) => | ||
yargs.options({ | ||
statePath: { type: "string", demandOption: true, desc: "Path to the ECS state to upload" }, | ||
worldAddress: { type: "string", demandOption: true, desc: "Contract address of the World to upload to" }, | ||
rpc: { type: "string", demandOption: true, desc: "JSON RPC endpoint" }, | ||
}); | ||
|
||
export const handler = async (argv: Arguments<Options>): Promise<void> => { | ||
const { execa } = await importExeca; | ||
const { statePath, worldAddress, rpc } = argv; | ||
console.log("Uploading state at ", statePath, "to", worldAddress, "on", rpc); | ||
const url = __dirname + "/../../src/contracts/BulkUpload.sol"; | ||
console.log("Using BulkUpload script from", url); | ||
|
||
try { | ||
await execa("forge", [ | ||
"script", | ||
"--sig", | ||
'"run(string, address)"', | ||
"--rpc-url", | ||
rpc, | ||
`${url}:BulkUpload`, | ||
statePath, | ||
worldAddress, | ||
]); | ||
} catch (e) { | ||
console.error(e); | ||
} | ||
|
||
process.exit(0); | ||
const commandModule: CommandModule<Options, Options> = { | ||
command: "bulkupload", | ||
|
||
describe: "Uploads the provided ECS state to the provided World", | ||
|
||
builder(yargs) { | ||
return yargs.options({ | ||
statePath: { type: "string", demandOption: true, desc: "Path to the ECS state to upload" }, | ||
worldAddress: { type: "string", demandOption: true, desc: "Contract address of the World to upload to" }, | ||
rpc: { type: "string", demandOption: true, desc: "JSON RPC endpoint" }, | ||
}); | ||
}, | ||
|
||
async handler({ statePath, worldAddress, rpc }) { | ||
console.log("Uploading state at ", statePath, "to", worldAddress, "on", rpc); | ||
const url = path.join(contractsDirectory, "BulkUpload.sol"); | ||
console.log("Using BulkUpload script from", url); | ||
|
||
try { | ||
await execa("forge", [ | ||
"script", | ||
"--sig", | ||
'"run(string, address)"', | ||
"--rpc-url", | ||
rpc, | ||
`${url}:BulkUpload`, | ||
statePath, | ||
worldAddress, | ||
]); | ||
} catch (e) { | ||
console.error(e); | ||
} | ||
|
||
process.exit(0); | ||
}, | ||
}; | ||
|
||
export default commandModule; |
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 |
---|---|---|
@@ -1,66 +1,70 @@ | ||
import { defaultAbiCoder as abi } from "ethers/lib/utils"; | ||
import { defaultAbiCoder as abi } from "ethers/lib/utils.js"; | ||
import path from "path"; | ||
import { Arguments, CommandBuilder } from "yargs"; | ||
import { execLog } from "../utils"; | ||
import { getTestDirectory } from "../utils/forgeConfig"; | ||
import type { CommandModule } from "yargs"; | ||
import { execLog } from "../utils/index.js"; | ||
import { getTestDirectory } from "../utils/forgeConfig.js"; | ||
|
||
type Options = { | ||
rpc?: string; | ||
caller?: string; | ||
world: string; | ||
systemId?: string; | ||
systemAddress?: string; | ||
argTypes?: any[]; | ||
args?: any[]; | ||
argTypes?: string[]; | ||
args?: (string | number)[]; | ||
calldata?: string; | ||
broadcast?: boolean; | ||
callerPrivateKey?: string; | ||
debug?: boolean; | ||
}; | ||
|
||
export const command = "call-system"; | ||
export const desc = "Execute a mud system"; | ||
const commandModule: CommandModule<Options, Options> = { | ||
command: "call-system", | ||
|
||
export const builder: CommandBuilder<Options, Options> = (yargs) => | ||
yargs.options({ | ||
rpc: { type: "string", description: "json rpc endpoint, defaults to http://localhost:8545" }, | ||
caller: { type: "string", description: "caller address" }, | ||
world: { type: "string", required: true, description: "world contract address" }, | ||
systemId: { type: "string", description: "system id preimage (eg mud.system.Move)" }, | ||
systemAddress: { type: "string", description: "system address (alternative to system id)" }, | ||
argTypes: { type: "array", description: "system argument types for abi encoding" }, | ||
args: { type: "array", description: "system arguments" }, | ||
calldata: { type: "string", description: "abi encoded system arguments (instead of args/argTypes)" }, | ||
broadcast: { type: "boolean", description: "send txs to the chain" }, | ||
callerPrivateKey: { | ||
type: "string", | ||
description: "must be set if broadcast is set, must correspond to caller address", | ||
}, | ||
debug: { type: "boolean", description: "open debugger" }, | ||
}); | ||
describe: "Execute a mud system", | ||
|
||
export const handler = async (argv: Arguments<Options>): Promise<void> => { | ||
const { rpc, caller, world, systemId, argTypes, args, calldata, broadcast, callerPrivateKey, debug } = argv; | ||
const encodedArgs = calldata ?? (argTypes && args && abi.encode(argTypes, args)) ?? ""; | ||
const testDir = await getTestDirectory(); | ||
builder(yargs) { | ||
return yargs.options({ | ||
rpc: { type: "string", description: "json rpc endpoint, defaults to http://localhost:8545" }, | ||
caller: { type: "string", description: "caller address" }, | ||
world: { type: "string", required: true, description: "world contract address" }, | ||
systemId: { type: "string", description: "system id preimage (eg mud.system.Move)" }, | ||
systemAddress: { type: "string", description: "system address (alternative to system id)" }, | ||
argTypes: { type: "array", string: true, description: "system argument types for abi encoding" }, | ||
args: { type: "array", description: "system arguments" }, | ||
calldata: { type: "string", description: "abi encoded system arguments (instead of args/argTypes)" }, | ||
broadcast: { type: "boolean", description: "send txs to the chain" }, | ||
callerPrivateKey: { | ||
type: "string", | ||
description: "must be set if broadcast is set, must correspond to caller address", | ||
}, | ||
debug: { type: "boolean", description: "open debugger" }, | ||
}); | ||
}, | ||
|
||
await execLog("forge", [ | ||
"script", | ||
"--fork-url", | ||
rpc ?? "http://localhost:8545", // default anvil rpc | ||
"--sig", | ||
"debug(address,address,string,bytes,bool)", | ||
path.join(testDir, "utils/Debug.sol"), // the cli expects the Debug.sol file at this path | ||
caller ?? "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266", // default anvil deployer | ||
world, | ||
systemId || "", | ||
encodedArgs, | ||
broadcast ? "true" : "false", | ||
"-vvvvv", | ||
broadcast ? "--broadcast" : "", | ||
callerPrivateKey ? `--private-key ${callerPrivateKey}` : "", | ||
debug ? "--debug" : "", | ||
]); | ||
async handler({ rpc, caller, world, systemId, argTypes, args, calldata, broadcast, callerPrivateKey, debug }) { | ||
const encodedArgs = calldata ?? (argTypes && args && abi.encode(argTypes, args)) ?? ""; | ||
const testDir = await getTestDirectory(); | ||
await execLog("forge", [ | ||
"script", | ||
"--fork-url", | ||
rpc ?? "http://localhost:8545", // default anvil rpc | ||
"--sig", | ||
"debug(address,address,string,bytes,bool)", | ||
path.join(testDir, "utils/Debug.sol"), // the cli expects the Debug.sol file at this path | ||
caller ?? "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266", // default anvil deployer | ||
world, | ||
systemId || "", | ||
encodedArgs, | ||
broadcast ? "true" : "false", | ||
"-vvvvv", | ||
broadcast ? "--broadcast" : "", | ||
callerPrivateKey ? `--private-key ${callerPrivateKey}` : "", | ||
debug ? "--debug" : "", | ||
]); | ||
|
||
process.exit(0); | ||
process.exit(0); | ||
}, | ||
}; | ||
|
||
export default commandModule; |
Oops, something went wrong.