-
Notifications
You must be signed in to change notification settings - Fork 217
feat(cli): deploy BatchStoreModule #3813
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
Open
frolic
wants to merge
3
commits into
main
Choose a base branch
from
frolic/batch-records
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 hidden or 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 hidden or 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 @@ | ||
| cache | ||
| out |
This file contains hidden or 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 @@ | ||
| { | ||
| "extends": "solhint:recommended", | ||
| "rules": { | ||
| "compiler-version": ["error", ">=0.8.0"], | ||
| "avoid-low-level-calls": "off", | ||
| "func-visibility": ["warn", { "ignoreConstructors": true }] | ||
| } | ||
| } |
This file contains hidden or 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 @@ | ||
| # BatchStore world module |
This file contains hidden or 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,15 @@ | ||
| [profile.default] | ||
| solc = "0.8.24" | ||
| ffi = false | ||
| fuzz_runs = 256 | ||
| optimizer = true | ||
| optimizer_runs = 3000 | ||
| verbosity = 3 | ||
| allow_paths = ["../../node_modules", "../"] | ||
| src = "src" | ||
| out = "out" | ||
| bytecode_hash = "none" | ||
| extra_output_files = [ | ||
| "abi", | ||
| "evm.bytecode" | ||
| ] |
This file contains hidden or 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,17 @@ | ||
| import { defineWorld } from "@latticexyz/world"; | ||
|
|
||
| export default defineWorld({ | ||
| codegen: { | ||
| generateSystemLibraries: true, | ||
| // generate into experimental dir until these are stable/audited | ||
| systemLibrariesDirectory: "experimental/systems", | ||
| }, | ||
| systems: { | ||
| BatchStoreSystem: { | ||
| deploy: { | ||
| disabled: true, | ||
| registerWorldFunctions: false, | ||
| }, | ||
| }, | ||
| }, | ||
| }); |
This file contains hidden or 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,58 @@ | ||
| { | ||
| "name": "@latticexyz/world-module-batchstore", | ||
| "version": "2.2.23", | ||
| "description": "BatchStore world module", | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "https://github.com/latticexyz/mud.git", | ||
| "directory": "packages/world-module-batchstore" | ||
| }, | ||
| "license": "MIT", | ||
| "type": "module", | ||
| "exports": { | ||
| "./mud.config": "./dist/mud.config.js", | ||
| "./out/*": "./out/*" | ||
| }, | ||
| "typesVersions": { | ||
| "*": { | ||
| "mud.config": [ | ||
| "./dist/mud.config.d.ts" | ||
| ] | ||
| } | ||
| }, | ||
| "files": [ | ||
| "dist", | ||
| "out", | ||
| "src" | ||
| ], | ||
| "scripts": { | ||
| "build": "pnpm run build:mud && pnpm run build:abi && pnpm run build:abi-ts && pnpm run build:js", | ||
| "build:abi": "forge build", | ||
| "build:abi-ts": "abi-ts", | ||
| "build:js": "tsup", | ||
| "build:mud": "tsx ./ts/build.ts", | ||
| "clean": "pnpm run clean:abi && pnpm run clean:js && pnpm run clean:mud", | ||
| "clean:abi": "forge clean", | ||
| "clean:js": "shx rm -rf dist", | ||
| "clean:mud": "shx rm -rf src/**/codegen", | ||
| "dev": "tsup --watch", | ||
| "gas-report": "gas-report --save gas-report.json", | ||
| "lint": "solhint --config ./.solhint.json 'src/**/*.sol'", | ||
| "test": "tsc --noEmit && forge test", | ||
| "test:ci": "pnpm run test" | ||
| }, | ||
| "dependencies": { | ||
| "@latticexyz/schema-type": "workspace:*", | ||
| "@latticexyz/store": "workspace:*", | ||
| "@latticexyz/world": "workspace:*" | ||
| }, | ||
| "devDependencies": { | ||
| "@latticexyz/abi-ts": "workspace:*", | ||
| "@latticexyz/gas-report": "workspace:*", | ||
| "forge-std": "https://github.com/foundry-rs/forge-std.git#60acb7aaadcce2d68e52986a0a66fe79f07d138f", | ||
| "solhint": "^3.3.7" | ||
| }, | ||
| "publishConfig": { | ||
| "access": "public" | ||
| } | ||
| } |
This file contains hidden or 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 @@ | ||
| forge-std/=node_modules/forge-std/src/ | ||
| @latticexyz/=node_modules/@latticexyz/ |
This file contains hidden or 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,25 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity >=0.8.24; | ||
|
|
||
| import { IBaseWorld } from "@latticexyz/world/src/codegen/interfaces/IBaseWorld.sol"; | ||
|
|
||
| import { Module } from "@latticexyz/world/src/Module.sol"; | ||
| import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; | ||
| import { ResourceIds } from "@latticexyz/store/src/codegen/tables/ResourceIds.sol"; | ||
| import { worldRegistrationSystem } from "@latticexyz/world/src/codegen/experimental/systems/WorldRegistrationSystemLib.sol"; | ||
|
|
||
| import { BatchStoreSystem } from "./BatchStoreSystem.sol"; | ||
| import { batchStoreSystem } from "./codegen/experimental/systems/BatchStoreSystemLib.sol"; | ||
|
|
||
| contract BatchStoreModule is Module { | ||
| BatchStoreSystem private immutable systemAddress = new BatchStoreSystem(); | ||
|
|
||
| function installRoot(bytes memory encodedArgs) public override { | ||
| ResourceId systemId = batchStoreSystem.toResourceId(); | ||
|
|
||
| if (batchStoreSystem.getAddress() != address(systemAddress)) { | ||
| // install or upgrade system | ||
| worldRegistrationSystem.callAsRoot().registerSystem(systemId, systemAddress, true); | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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,60 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity >=0.8.24; | ||
|
|
||
| import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; | ||
| import { System } from "@latticexyz/world/src/System.sol"; | ||
| import { AccessControl } from "@latticexyz/world/src/AccessControl.sol"; | ||
| import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; | ||
| import { EncodedLengths } from "@latticexyz/store/src/EncodedLengths.sol"; | ||
| import { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol"; | ||
| import { TableRecord } from "./common.sol"; | ||
|
|
||
| contract BatchStoreSystem is System { | ||
| function getTableRecords( | ||
| ResourceId tableId, | ||
| bytes32[][] memory keyTuples | ||
| ) external view returns (TableRecord[] memory records) { | ||
| AccessControl._requireAccess(tableId, _msgSender()); | ||
|
|
||
| FieldLayout fieldLayout = StoreCore.getFieldLayout(tableId); | ||
| records = new TableRecord[](keyTuples.length); | ||
|
|
||
| for (uint256 i = 0; i < keyTuples.length; i++) { | ||
| (bytes memory staticData, EncodedLengths encodedLengths, bytes memory dynamicData) = StoreCore.getRecord( | ||
| tableId, | ||
| keyTuples[i], | ||
| fieldLayout | ||
| ); | ||
| records[i] = TableRecord({ | ||
| keyTuple: keyTuples[i], | ||
| staticData: staticData, | ||
| encodedLengths: encodedLengths, | ||
| dynamicData: dynamicData | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| function setTableRecords(ResourceId tableId, TableRecord[] memory records) external { | ||
| AccessControl._requireAccess(tableId, _msgSender()); | ||
|
|
||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. need to get field layout here to save gas |
||
| for (uint256 i = 0; i < records.length; i++) { | ||
| StoreCore.setRecord( | ||
| tableId, | ||
| records[i].keyTuple, | ||
| records[i].staticData, | ||
| records[i].encodedLengths, | ||
| records[i].dynamicData | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| function deleteTableRecords(ResourceId tableId, bytes32[][] memory keyTuples) external { | ||
| AccessControl._requireAccess(tableId, _msgSender()); | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should these be |
||
|
|
||
| FieldLayout fieldLayout = StoreCore.getFieldLayout(tableId); | ||
|
|
||
| for (uint256 i = 0; i < keyTuples.length; i++) { | ||
| StoreCore.deleteRecord(tableId, keyTuples[i], fieldLayout); | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
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.
do we need access control the read function?
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.
oh whoops, copy pasta mistake