-
Couldn't load subscription status.
- Fork 218
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| cache | ||
| out |
| 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 }] | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| # BatchStore world module |
| 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" | ||
| ] |
| 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, | ||
| }, | ||
| }, | ||
| }, | ||
| }); |
| 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" | ||
| } | ||
| } |
| 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/ |
| 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); | ||
| } | ||
| } | ||
| } |
| 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()); | ||
|
|
||
|
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()); | ||
|
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); | ||
| } | ||
| } | ||
| } | ||
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