-
Notifications
You must be signed in to change notification settings - Fork 189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: v2 - add store, world and schema-type, cli table code generation #422
Merged
Changes from 18 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
9ed6f2a
feat(store): add foundation for v2 data model (#352)
alvrs e5d1195
ci: add v2 to github test action
alvrs 3b58a1f
fix(store): emit store events before early return (#381)
alvrs 217e817
refactor(store): optimize storage library (#386)
dk1a 53b2b62
fix(store): emit MudStoreSetRecord event when registering a new schem…
alvrs 4e04c00
Merge remote-tracking branch 'origin/main' into v2
holic 3a3a18a
test(store): avoid fuzzy storage slot clash with test assertion failu…
dk1a 3c7fb35
refactor(store): rename events (#398)
holic ede04c3
feat(store): replace Buffer with Slice and reorganize custom coders (…
dk1a 25fc99f
feat(store): add missing schema types (#395)
dk1a a7adbbb
refactor(store): change tableId type from bytes32 to uint256 (#416)
alvrs 7cce250
chore: merge main into v2 (#430)
alvrs b686e08
feat(store): add codegen for all types for tightcoder (#396)
dk1a 32a56f7
feat(schema-type): create schema-type package (#429)
dk1a 8998ae4
refactor(cli): refactor to esm (#417)
dk1a c4ea97b
feat(world): add World prototype (#405)
alvrs 78c197d
feat(cli): add store config parser and basic schema generator (#402)
dk1a 4777719
feat(cli): refactor tablegen and add more advanced features (#437)
dk1a 7534096
chore: v2 polishes
alvrs 5aa602d
Merge branch 'main' into v2
alvrs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: fix gas report action (right now it just passes even if the gas report is out of date)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#442