From 251170e1ef0b07466c597ea84df0cb49de7d6a23 Mon Sep 17 00:00:00 2001 From: alvarius Date: Mon, 25 Sep 2023 01:01:53 +0100 Subject: [PATCH] refactor(world,world-modules): move optional modules from `world` to `world-modules` package (#1591) Co-authored-by: Kevin Ingersoll --- .changeset/unlucky-cups-fetch.md | 8 + .../minimal/packages/contracts/package.json | 1 + .../contracts/test/ChatNamespaced.t.sol | 2 +- .../packages/contracts/test/CounterTest.t.sol | 2 +- .../packages/contracts/test/StructTest.t.sol | 2 +- examples/minimal/pnpm-lock.yaml | 4 + packages/cli/package.json | 1 + packages/cli/src/utils/modules/constants.ts | 6 +- packages/world-modules/.gitignore | 9 + packages/world-modules/.npmignore | 10 + packages/world-modules/.solhint.json | 8 + packages/world-modules/CHANGELOG.md | 1 + packages/world-modules/README.md | 1 + packages/world-modules/foundry.toml | 15 ++ packages/world-modules/gas-report.json | 242 ++++++++++++++++++ packages/world-modules/mud.config.ts | 77 ++++++ packages/world-modules/package.json | 60 +++++ packages/world-modules/remappings.txt | 3 + packages/world-modules/src/index.sol | 11 + .../src/interfaces/IBaseWorld.sol | 17 ++ .../src/interfaces/IUniqueEntitySystem.sol | 8 + .../modules/keysintable/KeysInTableHook.sol | 0 .../modules/keysintable/KeysInTableModule.sol | 8 +- .../src/modules/keysintable/constants.sol | 0 .../modules/keysintable/getKeysInTable.sol | 0 .../src/modules/keysintable/hasKey.sol | 0 .../src/modules/keysintable/query.sol | 0 .../keysintable/tables/KeysInTable.sol | 0 .../keysintable/tables/UsedKeysIndex.sol | 0 .../keyswithvalue/KeysWithValueHook.sol | 4 +- .../keyswithvalue/KeysWithValueModule.sol | 10 +- .../src/modules/keyswithvalue/constants.sol | 0 .../keyswithvalue/getKeysWithValue.sol | 0 .../keyswithvalue/getTargetTableId.sol | 4 +- .../keyswithvalue/tables/KeysWithValue.sol | 0 .../CallboundDelegationControl.sol | 4 +- .../StandardDelegationsModule.sol | 8 +- .../TimeboundDelegationControl.sol | 4 +- .../src/modules/std-delegations/constants.sol | 4 +- .../tables/CallboundDelegations.sol | 0 .../tables/TimeboundDelegations.sol | 0 .../uniqueentity/UniqueEntityModule.sol | 8 +- .../uniqueentity/UniqueEntitySystem.sol | 2 +- .../src/modules/uniqueentity/constants.sol | 4 +- .../modules/uniqueentity/getUniqueEntity.sol | 4 +- .../uniqueentity/tables/UniqueEntity.sol | 0 .../src/modules/utils/ArrayLib.sol | 0 .../test/KeysInTableModule.t.sol | 12 +- .../test/KeysWithValueModule.t.sol | 12 +- .../test/StandardDelegationsModule.t.sol | 20 +- .../test/UniqueEntityModule.t.sol | 12 +- .../{world => world-modules}/test/query.t.sol | 12 +- packages/world-modules/ts/scripts/tablegen.ts | 11 + packages/world-modules/ts/scripts/worldgen.ts | 30 +++ packages/world-modules/tsconfig.json | 19 ++ packages/world-modules/tsup.config.ts | 11 + packages/world/gas-report.json | 240 ----------------- packages/world/hardhat.config.ts | 19 -- packages/world/mud.config.ts | 67 +---- packages/world/package.json | 1 - packages/world/src/index.sol | 6 - packages/world/tasks/compile.ts | 38 --- pnpm-lock.yaml | 202 ++++++++++++++- .../phaser/packages/contracts/package.json | 3 +- .../packages/contracts/test/CounterTest.t.sol | 2 +- .../react/packages/contracts/package.json | 3 +- .../packages/contracts/test/CounterTest.t.sol | 2 +- .../vanilla/packages/contracts/package.json | 3 +- .../packages/contracts/test/CounterTest.t.sol | 2 +- 69 files changed, 826 insertions(+), 453 deletions(-) create mode 100644 .changeset/unlucky-cups-fetch.md create mode 100644 packages/world-modules/.gitignore create mode 100644 packages/world-modules/.npmignore create mode 100644 packages/world-modules/.solhint.json create mode 100644 packages/world-modules/CHANGELOG.md create mode 100644 packages/world-modules/README.md create mode 100644 packages/world-modules/foundry.toml create mode 100644 packages/world-modules/gas-report.json create mode 100644 packages/world-modules/mud.config.ts create mode 100644 packages/world-modules/package.json create mode 100644 packages/world-modules/remappings.txt create mode 100644 packages/world-modules/src/index.sol create mode 100644 packages/world-modules/src/interfaces/IBaseWorld.sol create mode 100644 packages/world-modules/src/interfaces/IUniqueEntitySystem.sol rename packages/{world => world-modules}/src/modules/keysintable/KeysInTableHook.sol (100%) rename packages/{world => world-modules}/src/modules/keysintable/KeysInTableModule.sol (92%) rename packages/{world => world-modules}/src/modules/keysintable/constants.sol (100%) rename packages/{world => world-modules}/src/modules/keysintable/getKeysInTable.sol (100%) rename packages/{world => world-modules}/src/modules/keysintable/hasKey.sol (100%) rename packages/{world => world-modules}/src/modules/keysintable/query.sol (100%) rename packages/{world => world-modules}/src/modules/keysintable/tables/KeysInTable.sol (100%) rename packages/{world => world-modules}/src/modules/keysintable/tables/UsedKeysIndex.sol (100%) rename packages/{world => world-modules}/src/modules/keyswithvalue/KeysWithValueHook.sol (97%) rename packages/{world => world-modules}/src/modules/keyswithvalue/KeysWithValueModule.sol (89%) rename packages/{world => world-modules}/src/modules/keyswithvalue/constants.sol (100%) rename packages/{world => world-modules}/src/modules/keyswithvalue/getKeysWithValue.sol (100%) rename packages/{world => world-modules}/src/modules/keyswithvalue/getTargetTableId.sol (92%) rename packages/{world => world-modules}/src/modules/keyswithvalue/tables/KeysWithValue.sol (100%) rename packages/{world => world-modules}/src/modules/std-delegations/CallboundDelegationControl.sol (92%) rename packages/{world => world-modules}/src/modules/std-delegations/StandardDelegationsModule.sol (85%) rename packages/{world => world-modules}/src/modules/std-delegations/TimeboundDelegationControl.sol (87%) rename packages/{world => world-modules}/src/modules/std-delegations/constants.sol (77%) rename packages/{world => world-modules}/src/modules/std-delegations/tables/CallboundDelegations.sol (100%) rename packages/{world => world-modules}/src/modules/std-delegations/tables/TimeboundDelegations.sol (100%) rename packages/{world => world-modules}/src/modules/uniqueentity/UniqueEntityModule.sol (85%) rename packages/{world => world-modules}/src/modules/uniqueentity/UniqueEntitySystem.sol (88%) rename packages/{world => world-modules}/src/modules/uniqueentity/constants.sol (74%) rename packages/{world => world-modules}/src/modules/uniqueentity/getUniqueEntity.sol (81%) rename packages/{world => world-modules}/src/modules/uniqueentity/tables/UniqueEntity.sol (100%) rename packages/{world => world-modules}/src/modules/utils/ArrayLib.sol (100%) rename packages/{world => world-modules}/test/KeysInTableModule.t.sol (97%) rename packages/{world => world-modules}/test/KeysWithValueModule.t.sol (95%) rename packages/{world => world-modules}/test/StandardDelegationsModule.t.sol (86%) rename packages/{world => world-modules}/test/UniqueEntityModule.t.sol (88%) rename packages/{world => world-modules}/test/query.t.sol (97%) create mode 100644 packages/world-modules/ts/scripts/tablegen.ts create mode 100644 packages/world-modules/ts/scripts/worldgen.ts create mode 100644 packages/world-modules/tsconfig.json create mode 100644 packages/world-modules/tsup.config.ts delete mode 100644 packages/world/hardhat.config.ts delete mode 100644 packages/world/tasks/compile.ts diff --git a/.changeset/unlucky-cups-fetch.md b/.changeset/unlucky-cups-fetch.md new file mode 100644 index 0000000000..237f8fe266 --- /dev/null +++ b/.changeset/unlucky-cups-fetch.md @@ -0,0 +1,8 @@ +--- +"@latticexyz/cli": patch +"@latticexyz/world": major +"@latticexyz/world-modules": major +--- + +All optional modules have been moved from `@latticexyz/world` to `@latticexyz/world-modules`. +If you're using the MUD CLI, the import is already updated and no changes are necessary. diff --git a/examples/minimal/packages/contracts/package.json b/examples/minimal/packages/contracts/package.json index 21abadfe78..95c7037b70 100644 --- a/examples/minimal/packages/contracts/package.json +++ b/examples/minimal/packages/contracts/package.json @@ -24,6 +24,7 @@ "@latticexyz/schema-type": "link:../../../../packages/schema-type", "@latticexyz/store": "link:../../../../packages/store", "@latticexyz/world": "link:../../../../packages/world", + "@latticexyz/world-modules": "link:../../../../packages/world-modules", "@solidstate/contracts": "^0.0.52", "@types/node": "^18.15.11", "ds-test": "https://github.com/dapphub/ds-test.git#e282159d5170298eb2455a6c05280ab5a73a4ef0", diff --git a/examples/minimal/packages/contracts/test/ChatNamespaced.t.sol b/examples/minimal/packages/contracts/test/ChatNamespaced.t.sol index d22d8dd57c..c87c3e4304 100644 --- a/examples/minimal/packages/contracts/test/ChatNamespaced.t.sol +++ b/examples/minimal/packages/contracts/test/ChatNamespaced.t.sol @@ -3,7 +3,7 @@ pragma solidity >=0.8.21; import "forge-std/Test.sol"; import { MudTest } from "@latticexyz/world/test/MudTest.t.sol"; -import { getKeysWithValue } from "@latticexyz/world/src/modules/keyswithvalue/getKeysWithValue.sol"; +import { getKeysWithValue } from "@latticexyz/world-modules/src/modules/keyswithvalue/getKeysWithValue.sol"; import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; import { IWorld } from "../src/codegen/world/IWorld.sol"; diff --git a/examples/minimal/packages/contracts/test/CounterTest.t.sol b/examples/minimal/packages/contracts/test/CounterTest.t.sol index 959655f295..6faea6b1b0 100644 --- a/examples/minimal/packages/contracts/test/CounterTest.t.sol +++ b/examples/minimal/packages/contracts/test/CounterTest.t.sol @@ -3,7 +3,7 @@ pragma solidity >=0.8.21; import "forge-std/Test.sol"; import { MudTest } from "@latticexyz/world/test/MudTest.t.sol"; -import { getKeysWithValue } from "@latticexyz/world/src/modules/keyswithvalue/getKeysWithValue.sol"; +import { getKeysWithValue } from "@latticexyz/world-modules/src/modules/keyswithvalue/getKeysWithValue.sol"; import { IWorld } from "../src/codegen/world/IWorld.sol"; import { CounterTable, CounterTableTableId } from "../src/codegen/index.sol"; diff --git a/examples/minimal/packages/contracts/test/StructTest.t.sol b/examples/minimal/packages/contracts/test/StructTest.t.sol index dc824e30bf..75528e759a 100644 --- a/examples/minimal/packages/contracts/test/StructTest.t.sol +++ b/examples/minimal/packages/contracts/test/StructTest.t.sol @@ -3,7 +3,7 @@ pragma solidity >=0.8.21; import "forge-std/Test.sol"; import { MudTest } from "@latticexyz/world/test/MudTest.t.sol"; -import { getKeysWithValue } from "@latticexyz/world/src/modules/keyswithvalue/getKeysWithValue.sol"; +import { getKeysWithValue } from "@latticexyz/world-modules/src/modules/keyswithvalue/getKeysWithValue.sol"; import { IWorld } from "../src/codegen/world/IWorld.sol"; import { CounterTable, CounterTableTableId } from "../src/codegen/index.sol"; diff --git a/examples/minimal/pnpm-lock.yaml b/examples/minimal/pnpm-lock.yaml index f480d20160..8e105674fa 100644 --- a/examples/minimal/pnpm-lock.yaml +++ b/examples/minimal/pnpm-lock.yaml @@ -320,6 +320,9 @@ importers: '@latticexyz/world': specifier: link:../../../../packages/world version: link:../../../../packages/world + '@latticexyz/world-modules': + specifier: link:../../../../packages/world-modules + version: link:../../../../packages/world-modules '@solidstate/contracts': specifier: ^0.0.52 version: 0.0.52 @@ -1985,6 +1988,7 @@ packages: /esm@3.2.25: resolution: {integrity: sha512-U1suiZ2oDVWv4zPO56S0NcR5QriEahGtdN2OR6FiOG4WJvcjBVFB0qI4+eKoWFH483PKGuLuu6V8Z4T5g63UVA==} engines: {node: '>=6'} + requiresBuild: true dev: false optional: true diff --git a/packages/cli/package.json b/packages/cli/package.json index 4ebf52eae8..0c88d7b846 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -44,6 +44,7 @@ "@latticexyz/store": "workspace:*", "@latticexyz/utils": "workspace:*", "@latticexyz/world": "workspace:*", + "@latticexyz/world-modules": "workspace:*", "chalk": "^5.0.1", "chokidar": "^3.5.3", "dotenv": "^16.0.3", diff --git a/packages/cli/src/utils/modules/constants.ts b/packages/cli/src/utils/modules/constants.ts index ac84680fa2..f62292f7c9 100644 --- a/packages/cli/src/utils/modules/constants.ts +++ b/packages/cli/src/utils/modules/constants.ts @@ -1,6 +1,6 @@ -import KeysWithValueModuleData from "@latticexyz/world/out/KeysWithValueModule.sol/KeysWithValueModule.json" assert { type: "json" }; -import KeysInTableModuleData from "@latticexyz/world/out/KeysInTableModule.sol/KeysInTableModule.json" assert { type: "json" }; -import UniqueEntityModuleData from "@latticexyz/world/out/UniqueEntityModule.sol/UniqueEntityModule.json" assert { type: "json" }; +import KeysWithValueModuleData from "@latticexyz/world-modules/out/KeysWithValueModule.sol/KeysWithValueModule.json" assert { type: "json" }; +import KeysInTableModuleData from "@latticexyz/world-modules/out/KeysInTableModule.sol/KeysInTableModule.json" assert { type: "json" }; +import UniqueEntityModuleData from "@latticexyz/world-modules/out/UniqueEntityModule.sol/UniqueEntityModule.json" assert { type: "json" }; import { ContractCode } from "../utils/types"; // These modules are always deployed diff --git a/packages/world-modules/.gitignore b/packages/world-modules/.gitignore new file mode 100644 index 0000000000..4d69834442 --- /dev/null +++ b/packages/world-modules/.gitignore @@ -0,0 +1,9 @@ +cache +out +docs +_docs +DOCS.md +artifacts +yarn-error.log +API +dist diff --git a/packages/world-modules/.npmignore b/packages/world-modules/.npmignore new file mode 100644 index 0000000000..bf5a89e600 --- /dev/null +++ b/packages/world-modules/.npmignore @@ -0,0 +1,10 @@ +* + +!out/**/*.json +!out/**/*.abi.json +!out/**/*.abi.json.d.ts +!src/** +!ts/** +!package.json +!README.md +!dist/** diff --git a/packages/world-modules/.solhint.json b/packages/world-modules/.solhint.json new file mode 100644 index 0000000000..4e2baa8be7 --- /dev/null +++ b/packages/world-modules/.solhint.json @@ -0,0 +1,8 @@ +{ + "extends": "solhint:recommended", + "rules": { + "compiler-version": ["error", ">=0.8.0"], + "avoid-low-level-calls": "off", + "func-visibility": ["warn", { "ignoreConstructors": true }] + } +} diff --git a/packages/world-modules/CHANGELOG.md b/packages/world-modules/CHANGELOG.md new file mode 100644 index 0000000000..420e6f23d0 --- /dev/null +++ b/packages/world-modules/CHANGELOG.md @@ -0,0 +1 @@ +# Change Log diff --git a/packages/world-modules/README.md b/packages/world-modules/README.md new file mode 100644 index 0000000000..799ede0eba --- /dev/null +++ b/packages/world-modules/README.md @@ -0,0 +1 @@ +# World modules diff --git a/packages/world-modules/foundry.toml b/packages/world-modules/foundry.toml new file mode 100644 index 0000000000..3d2a6b756b --- /dev/null +++ b/packages/world-modules/foundry.toml @@ -0,0 +1,15 @@ +[profile.default] +solc = "0.8.21" +ffi = false +fuzz_runs = 256 +optimizer = true +optimizer_runs = 3000 +verbosity = 2 +allow_paths = ["../../node_modules", "../"] +src = "src" +out = "out" +bytecode_hash = "none" +extra_output_files = [ + "abi", + "evm.bytecode" +] diff --git a/packages/world-modules/gas-report.json b/packages/world-modules/gas-report.json new file mode 100644 index 0000000000..3e5655abe5 --- /dev/null +++ b/packages/world-modules/gas-report.json @@ -0,0 +1,242 @@ +[ + { + "file": "test/KeysInTableModule.t.sol", + "test": "testInstallComposite", + "name": "install keys in table module", + "gasUsed": 1408400 + }, + { + "file": "test/KeysInTableModule.t.sol", + "test": "testInstallGas", + "name": "install keys in table module", + "gasUsed": 1408400 + }, + { + "file": "test/KeysInTableModule.t.sol", + "test": "testInstallGas", + "name": "set a record on a table with keysInTableModule installed", + "gasUsed": 159030 + }, + { + "file": "test/KeysInTableModule.t.sol", + "test": "testInstallSingleton", + "name": "install keys in table module", + "gasUsed": 1408400 + }, + { + "file": "test/KeysInTableModule.t.sol", + "test": "testSetAndDeleteRecordHookCompositeGas", + "name": "install keys in table module", + "gasUsed": 1408400 + }, + { + "file": "test/KeysInTableModule.t.sol", + "test": "testSetAndDeleteRecordHookCompositeGas", + "name": "change a composite record on a table with keysInTableModule installed", + "gasUsed": 22571 + }, + { + "file": "test/KeysInTableModule.t.sol", + "test": "testSetAndDeleteRecordHookCompositeGas", + "name": "delete a composite record on a table with keysInTableModule installed", + "gasUsed": 156371 + }, + { + "file": "test/KeysInTableModule.t.sol", + "test": "testSetAndDeleteRecordHookGas", + "name": "install keys in table module", + "gasUsed": 1408400 + }, + { + "file": "test/KeysInTableModule.t.sol", + "test": "testSetAndDeleteRecordHookGas", + "name": "change a record on a table with keysInTableModule installed", + "gasUsed": 21293 + }, + { + "file": "test/KeysInTableModule.t.sol", + "test": "testSetAndDeleteRecordHookGas", + "name": "delete a record on a table with keysInTableModule installed", + "gasUsed": 85329 + }, + { + "file": "test/KeysWithValueModule.t.sol", + "test": "testGetKeysWithValueGas", + "name": "install keys with value module", + "gasUsed": 649560 + }, + { + "file": "test/KeysWithValueModule.t.sol", + "test": "testGetKeysWithValueGas", + "name": "Get list of keys with a given value", + "gasUsed": 5712 + }, + { + "file": "test/KeysWithValueModule.t.sol", + "test": "testGetTargetTableId", + "name": "compute the target table selector", + "gasUsed": 2624 + }, + { + "file": "test/KeysWithValueModule.t.sol", + "test": "testInstall", + "name": "install keys with value module", + "gasUsed": 649560 + }, + { + "file": "test/KeysWithValueModule.t.sol", + "test": "testInstall", + "name": "set a record on a table with KeysWithValueModule installed", + "gasUsed": 135698 + }, + { + "file": "test/KeysWithValueModule.t.sol", + "test": "testSetAndDeleteRecordHook", + "name": "install keys with value module", + "gasUsed": 649560 + }, + { + "file": "test/KeysWithValueModule.t.sol", + "test": "testSetAndDeleteRecordHook", + "name": "change a record on a table with KeysWithValueModule installed", + "gasUsed": 104082 + }, + { + "file": "test/KeysWithValueModule.t.sol", + "test": "testSetAndDeleteRecordHook", + "name": "delete a record on a table with KeysWithValueModule installed", + "gasUsed": 36693 + }, + { + "file": "test/KeysWithValueModule.t.sol", + "test": "testSetField", + "name": "install keys with value module", + "gasUsed": 649560 + }, + { + "file": "test/KeysWithValueModule.t.sol", + "test": "testSetField", + "name": "set a field on a table with KeysWithValueModule installed", + "gasUsed": 146907 + }, + { + "file": "test/KeysWithValueModule.t.sol", + "test": "testSetField", + "name": "change a field on a table with KeysWithValueModule installed", + "gasUsed": 111666 + }, + { + "file": "test/query.t.sol", + "test": "testCombinedHasHasValueNotQuery", + "name": "CombinedHasHasValueNotQuery", + "gasUsed": 105109 + }, + { + "file": "test/query.t.sol", + "test": "testCombinedHasHasValueQuery", + "name": "CombinedHasHasValueQuery", + "gasUsed": 53579 + }, + { + "file": "test/query.t.sol", + "test": "testCombinedHasNotQuery", + "name": "CombinedHasNotQuery", + "gasUsed": 131374 + }, + { + "file": "test/query.t.sol", + "test": "testCombinedHasQuery", + "name": "CombinedHasQuery", + "gasUsed": 84497 + }, + { + "file": "test/query.t.sol", + "test": "testCombinedHasValueNotQuery", + "name": "CombinedHasValueNotQuery", + "gasUsed": 85116 + }, + { + "file": "test/query.t.sol", + "test": "testCombinedHasValueQuery", + "name": "CombinedHasValueQuery", + "gasUsed": 15705 + }, + { + "file": "test/query.t.sol", + "test": "testHasQuery", + "name": "HasQuery", + "gasUsed": 18882 + }, + { + "file": "test/query.t.sol", + "test": "testHasQuery1000Keys", + "name": "HasQuery with 1000 keys", + "gasUsed": 5804585 + }, + { + "file": "test/query.t.sol", + "test": "testHasQuery100Keys", + "name": "HasQuery with 100 keys", + "gasUsed": 541538 + }, + { + "file": "test/query.t.sol", + "test": "testHasValueQuery", + "name": "HasValueQuery", + "gasUsed": 7521 + }, + { + "file": "test/query.t.sol", + "test": "testNotValueQuery", + "name": "NotValueQuery", + "gasUsed": 47175 + }, + { + "file": "test/StandardDelegationsModule.t.sol", + "test": "testCallFromCallboundDelegation", + "name": "register a callbound delegation", + "gasUsed": 117579 + }, + { + "file": "test/StandardDelegationsModule.t.sol", + "test": "testCallFromCallboundDelegation", + "name": "call a system via a callbound delegation", + "gasUsed": 36737 + }, + { + "file": "test/StandardDelegationsModule.t.sol", + "test": "testCallFromTimeboundDelegation", + "name": "register a timebound delegation", + "gasUsed": 112073 + }, + { + "file": "test/StandardDelegationsModule.t.sol", + "test": "testCallFromTimeboundDelegation", + "name": "call a system via a timebound delegation", + "gasUsed": 26822 + }, + { + "file": "test/UniqueEntityModule.t.sol", + "test": "testInstall", + "name": "install unique entity module", + "gasUsed": 676208 + }, + { + "file": "test/UniqueEntityModule.t.sol", + "test": "testInstall", + "name": "get a unique entity nonce (non-root module)", + "gasUsed": 51180 + }, + { + "file": "test/UniqueEntityModule.t.sol", + "test": "testInstallRoot", + "name": "installRoot unique entity module", + "gasUsed": 643472 + }, + { + "file": "test/UniqueEntityModule.t.sol", + "test": "testInstallRoot", + "name": "get a unique entity nonce (root module)", + "gasUsed": 51180 + } +] diff --git a/packages/world-modules/mud.config.ts b/packages/world-modules/mud.config.ts new file mode 100644 index 0000000000..4e273a4b90 --- /dev/null +++ b/packages/world-modules/mud.config.ts @@ -0,0 +1,77 @@ +import { mudConfig } from "@latticexyz/world/register"; + +export default mudConfig({ + worldgenDirectory: "interfaces", + worldInterfaceName: "IBaseWorld", + codegenDirectory: ".", + userTypes: { + ResourceId: { filePath: "@latticexyz/store/src/ResourceId.sol", internalType: "bytes32" }, + }, + tables: { + /************************************************************************ + * + * MODULE TABLES + * + ************************************************************************/ + KeysWithValue: { + directory: "modules/keyswithvalue/tables", + keySchema: { + valueHash: "bytes32", + }, + valueSchema: { + keysWithValue: "bytes32[]", // For now only supports 1 key per value + }, + tableIdArgument: true, + }, + KeysInTable: { + directory: "modules/keysintable/tables", + keySchema: { sourceTableId: "ResourceId" }, + valueSchema: { + keys0: "bytes32[]", + keys1: "bytes32[]", + keys2: "bytes32[]", + keys3: "bytes32[]", + keys4: "bytes32[]", + }, + }, + UsedKeysIndex: { + directory: "modules/keysintable/tables", + keySchema: { + sourceTableId: "ResourceId", + keysHash: "bytes32", + }, + valueSchema: { has: "bool", index: "uint40" }, + dataStruct: false, + }, + UniqueEntity: { + directory: "modules/uniqueentity/tables", + keySchema: {}, + valueSchema: "uint256", + tableIdArgument: true, + storeArgument: true, + }, + CallboundDelegations: { + directory: "modules/std-delegations/tables", + keySchema: { + delegator: "address", + delegatee: "address", + systemId: "ResourceId", + callDataHash: "bytes32", + }, + valueSchema: { + availableCalls: "uint256", + }, + }, + TimeboundDelegations: { + directory: "modules/std-delegations/tables", + keySchema: { + delegator: "address", + delegatee: "address", + }, + valueSchema: { + maxTimestamp: "uint256", + }, + }, + }, + excludeSystems: [], +}); diff --git a/packages/world-modules/package.json b/packages/world-modules/package.json new file mode 100644 index 0000000000..274e1f3536 --- /dev/null +++ b/packages/world-modules/package.json @@ -0,0 +1,60 @@ +{ + "name": "@latticexyz/world-modules", + "version": "2.0.0-next.8", + "description": "World modules", + "repository": { + "type": "git", + "url": "https://github.com/latticexyz/mud.git", + "directory": "packages/world-modules" + }, + "license": "MIT", + "type": "module", + "exports": { + "./out/*": "./out/*", + "./*": "./dist/*" + }, + "scripts": { + "build": "pnpm run build:mud && pnpm run build:abi && pnpm run build:abi-ts && pnpm run build:js", + "build:abi": "forge build --skip test script", + "build:abi-ts": "abi-ts && prettier --write '**/*.abi.json.d.ts'", + "build:js": "tsup", + "build:mud": "tsx ./ts/scripts/tablegen.ts && tsx ./ts/scripts/worldgen.ts", + "clean": "pnpm run clean:abi && pnpm run clean:js && pnpm run clean:mud", + "clean:abi": "forge clean", + "clean:js": "rimraf dist", + "clean:mud": "rimraf src/codegen", + "dev": "tsup --watch", + "gas-report": "gas-report --save gas-report.json", + "lint": "solhint --config ./.solhint.json 'src/**/*.sol'", + "test": "forge test", + "test:ci": "pnpm run test" + }, + "dependencies": { + "@latticexyz/common": "workspace:*", + "@latticexyz/config": "workspace:*", + "@latticexyz/schema-type": "workspace:*", + "@latticexyz/store": "workspace:*", + "@latticexyz/world": "workspace:*", + "zod": "^3.21.4" + }, + "devDependencies": { + "@latticexyz/abi-ts": "workspace:*", + "@latticexyz/gas-report": "workspace:*", + "@types/ejs": "^3.1.1", + "@types/glob": "^7.2.0", + "@types/mocha": "^9.1.1", + "@types/node": "^18.15.11", + "ds-test": "https://github.com/dapphub/ds-test.git#e282159d5170298eb2455a6c05280ab5a73a4ef0", + "ejs": "^3.1.8", + "forge-std": "https://github.com/foundry-rs/forge-std.git#74cfb77e308dd188d2f58864aaf44963ae6b88b1", + "glob": "^8.0.3", + "solhint": "^3.3.7", + "tsup": "^6.7.0", + "tsx": "^3.12.6", + "vitest": "0.31.4" + }, + "publishConfig": { + "access": "public" + }, + "gitHead": "914a1e0ae4a573d685841ca2ea921435057deb8f" +} diff --git a/packages/world-modules/remappings.txt b/packages/world-modules/remappings.txt new file mode 100644 index 0000000000..c4d992480e --- /dev/null +++ b/packages/world-modules/remappings.txt @@ -0,0 +1,3 @@ +ds-test/=node_modules/ds-test/src/ +forge-std/=node_modules/forge-std/src/ +@latticexyz/=node_modules/@latticexyz/ diff --git a/packages/world-modules/src/index.sol b/packages/world-modules/src/index.sol new file mode 100644 index 0000000000..e88b495bf3 --- /dev/null +++ b/packages/world-modules/src/index.sol @@ -0,0 +1,11 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.21; + +/* Autogenerated file. Do not edit manually. */ + +import { KeysWithValue } from "./modules/keyswithvalue/tables/KeysWithValue.sol"; +import { KeysInTable, KeysInTableData, KeysInTableTableId } from "./modules/keysintable/tables/KeysInTable.sol"; +import { UsedKeysIndex, UsedKeysIndexTableId } from "./modules/keysintable/tables/UsedKeysIndex.sol"; +import { UniqueEntity } from "./modules/uniqueentity/tables/UniqueEntity.sol"; +import { CallboundDelegations, CallboundDelegationsTableId } from "./modules/std-delegations/tables/CallboundDelegations.sol"; +import { TimeboundDelegations, TimeboundDelegationsTableId } from "./modules/std-delegations/tables/TimeboundDelegations.sol"; diff --git a/packages/world-modules/src/interfaces/IBaseWorld.sol b/packages/world-modules/src/interfaces/IBaseWorld.sol new file mode 100644 index 0000000000..c1f0001aeb --- /dev/null +++ b/packages/world-modules/src/interfaces/IBaseWorld.sol @@ -0,0 +1,17 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.21; + +/* Autogenerated file. Do not edit manually. */ + +import { IStore } from "@latticexyz/store/src/IStore.sol"; +import { IWorldKernel } from "@latticexyz/world/src/interfaces/IWorldKernel.sol"; + +import { IUniqueEntitySystem } from "./IUniqueEntitySystem.sol"; + +/** + * The IBaseWorld interface includes all systems dynamically added to the World + * during the deploy process. + */ +interface IBaseWorld is IStore, IWorldKernel, IUniqueEntitySystem { + +} diff --git a/packages/world-modules/src/interfaces/IUniqueEntitySystem.sol b/packages/world-modules/src/interfaces/IUniqueEntitySystem.sol new file mode 100644 index 0000000000..f0d650be73 --- /dev/null +++ b/packages/world-modules/src/interfaces/IUniqueEntitySystem.sol @@ -0,0 +1,8 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.21; + +/* Autogenerated file. Do not edit manually. */ + +interface IUniqueEntitySystem { + function getUniqueEntity() external returns (bytes32); +} diff --git a/packages/world/src/modules/keysintable/KeysInTableHook.sol b/packages/world-modules/src/modules/keysintable/KeysInTableHook.sol similarity index 100% rename from packages/world/src/modules/keysintable/KeysInTableHook.sol rename to packages/world-modules/src/modules/keysintable/KeysInTableHook.sol diff --git a/packages/world/src/modules/keysintable/KeysInTableModule.sol b/packages/world-modules/src/modules/keysintable/KeysInTableModule.sol similarity index 92% rename from packages/world/src/modules/keysintable/KeysInTableModule.sol rename to packages/world-modules/src/modules/keysintable/KeysInTableModule.sol index 2577ba0a7c..5031ae745c 100644 --- a/packages/world/src/modules/keysintable/KeysInTableModule.sol +++ b/packages/world-modules/src/modules/keysintable/KeysInTableModule.sol @@ -4,12 +4,12 @@ pragma solidity >=0.8.21; import { BEFORE_SET_RECORD, AFTER_SPLICE_STATIC_DATA, AFTER_SPLICE_DYNAMIC_DATA, BEFORE_DELETE_RECORD } from "@latticexyz/store/src/storeHookTypes.sol"; import { ResourceIds } from "@latticexyz/store/src/codegen/tables/ResourceIds.sol"; -import { Module } from "../../Module.sol"; +import { Module } from "@latticexyz/world/src/Module.sol"; -import { IBaseWorld } from "../../interfaces/IBaseWorld.sol"; +import { IBaseWorld } from "@latticexyz/world/src/interfaces/IBaseWorld.sol"; -import { ResourceId, WorldResourceIdInstance } from "../../WorldResourceId.sol"; -import { revertWithBytes } from "../../revertWithBytes.sol"; +import { ResourceId, WorldResourceIdInstance } from "@latticexyz/world/src/WorldResourceId.sol"; +import { revertWithBytes } from "@latticexyz/world/src/revertWithBytes.sol"; import { KeysInTableHook } from "./KeysInTableHook.sol"; import { KeysInTable, KeysInTableTableId } from "./tables/KeysInTable.sol"; diff --git a/packages/world/src/modules/keysintable/constants.sol b/packages/world-modules/src/modules/keysintable/constants.sol similarity index 100% rename from packages/world/src/modules/keysintable/constants.sol rename to packages/world-modules/src/modules/keysintable/constants.sol diff --git a/packages/world/src/modules/keysintable/getKeysInTable.sol b/packages/world-modules/src/modules/keysintable/getKeysInTable.sol similarity index 100% rename from packages/world/src/modules/keysintable/getKeysInTable.sol rename to packages/world-modules/src/modules/keysintable/getKeysInTable.sol diff --git a/packages/world/src/modules/keysintable/hasKey.sol b/packages/world-modules/src/modules/keysintable/hasKey.sol similarity index 100% rename from packages/world/src/modules/keysintable/hasKey.sol rename to packages/world-modules/src/modules/keysintable/hasKey.sol diff --git a/packages/world/src/modules/keysintable/query.sol b/packages/world-modules/src/modules/keysintable/query.sol similarity index 100% rename from packages/world/src/modules/keysintable/query.sol rename to packages/world-modules/src/modules/keysintable/query.sol diff --git a/packages/world/src/modules/keysintable/tables/KeysInTable.sol b/packages/world-modules/src/modules/keysintable/tables/KeysInTable.sol similarity index 100% rename from packages/world/src/modules/keysintable/tables/KeysInTable.sol rename to packages/world-modules/src/modules/keysintable/tables/KeysInTable.sol diff --git a/packages/world/src/modules/keysintable/tables/UsedKeysIndex.sol b/packages/world-modules/src/modules/keysintable/tables/UsedKeysIndex.sol similarity index 100% rename from packages/world/src/modules/keysintable/tables/UsedKeysIndex.sol rename to packages/world-modules/src/modules/keysintable/tables/UsedKeysIndex.sol diff --git a/packages/world/src/modules/keyswithvalue/KeysWithValueHook.sol b/packages/world-modules/src/modules/keyswithvalue/KeysWithValueHook.sol similarity index 97% rename from packages/world/src/modules/keyswithvalue/KeysWithValueHook.sol rename to packages/world-modules/src/modules/keyswithvalue/KeysWithValueHook.sol index cbac7f80cd..1655b2255d 100644 --- a/packages/world/src/modules/keyswithvalue/KeysWithValueHook.sol +++ b/packages/world-modules/src/modules/keyswithvalue/KeysWithValueHook.sol @@ -7,9 +7,9 @@ import { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol"; import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; import { PackedCounter } from "@latticexyz/store/src/PackedCounter.sol"; import { Tables } from "@latticexyz/store/src/codegen/tables/Tables.sol"; -import { IBaseWorld } from "../../interfaces/IBaseWorld.sol"; +import { IBaseWorld } from "@latticexyz/world/src/interfaces/IBaseWorld.sol"; -import { ResourceId, WorldResourceIdInstance } from "../../WorldResourceId.sol"; +import { ResourceId, WorldResourceIdInstance } from "@latticexyz/world/src/WorldResourceId.sol"; import { MODULE_NAMESPACE } from "./constants.sol"; import { KeysWithValue } from "./tables/KeysWithValue.sol"; diff --git a/packages/world/src/modules/keyswithvalue/KeysWithValueModule.sol b/packages/world-modules/src/modules/keyswithvalue/KeysWithValueModule.sol similarity index 89% rename from packages/world/src/modules/keyswithvalue/KeysWithValueModule.sol rename to packages/world-modules/src/modules/keyswithvalue/KeysWithValueModule.sol index 35a14aa3ba..f9aed943c7 100644 --- a/packages/world/src/modules/keyswithvalue/KeysWithValueModule.sol +++ b/packages/world-modules/src/modules/keyswithvalue/KeysWithValueModule.sol @@ -2,13 +2,13 @@ pragma solidity >=0.8.21; import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; import { BEFORE_SET_RECORD, BEFORE_SPLICE_STATIC_DATA, AFTER_SPLICE_STATIC_DATA, BEFORE_SPLICE_DYNAMIC_DATA, AFTER_SPLICE_DYNAMIC_DATA, BEFORE_DELETE_RECORD } from "@latticexyz/store/src/storeHookTypes.sol"; -import { Module } from "../../Module.sol"; +import { Module } from "@latticexyz/world/src/Module.sol"; -import { IBaseWorld } from "../../interfaces/IBaseWorld.sol"; +import { IBaseWorld } from "@latticexyz/world/src/interfaces/IBaseWorld.sol"; -import { WorldContextConsumer } from "../../WorldContext.sol"; -import { ResourceId, WorldResourceIdInstance } from "../../WorldResourceId.sol"; -import { revertWithBytes } from "../../revertWithBytes.sol"; +import { WorldContextConsumer } from "@latticexyz/world/src/WorldContext.sol"; +import { ResourceId, WorldResourceIdInstance } from "@latticexyz/world/src/WorldResourceId.sol"; +import { revertWithBytes } from "@latticexyz/world/src/revertWithBytes.sol"; import { MODULE_NAMESPACE } from "./constants.sol"; import { KeysWithValueHook } from "./KeysWithValueHook.sol"; diff --git a/packages/world/src/modules/keyswithvalue/constants.sol b/packages/world-modules/src/modules/keyswithvalue/constants.sol similarity index 100% rename from packages/world/src/modules/keyswithvalue/constants.sol rename to packages/world-modules/src/modules/keyswithvalue/constants.sol diff --git a/packages/world/src/modules/keyswithvalue/getKeysWithValue.sol b/packages/world-modules/src/modules/keyswithvalue/getKeysWithValue.sol similarity index 100% rename from packages/world/src/modules/keyswithvalue/getKeysWithValue.sol rename to packages/world-modules/src/modules/keyswithvalue/getKeysWithValue.sol diff --git a/packages/world/src/modules/keyswithvalue/getTargetTableId.sol b/packages/world-modules/src/modules/keyswithvalue/getTargetTableId.sol similarity index 92% rename from packages/world/src/modules/keyswithvalue/getTargetTableId.sol rename to packages/world-modules/src/modules/keyswithvalue/getTargetTableId.sol index 1a55f06612..f2d3f6b723 100644 --- a/packages/world/src/modules/keyswithvalue/getTargetTableId.sol +++ b/packages/world-modules/src/modules/keyswithvalue/getTargetTableId.sol @@ -2,8 +2,8 @@ pragma solidity >=0.8.21; import { TYPE_BITS } from "@latticexyz/store/src/ResourceId.sol"; -import { ResourceId, WorldResourceIdInstance, NAME_BITS } from "../../WorldResourceId.sol"; -import { RESOURCE_TABLE } from "../../worldResourceTypes.sol"; +import { ResourceId, WorldResourceIdInstance, NAME_BITS } from "@latticexyz/world/src/WorldResourceId.sol"; +import { RESOURCE_TABLE } from "@latticexyz/world/src/worldResourceTypes.sol"; uint256 constant MODULE_NAMESPACE_BITS = 7 * 8; uint256 constant TABLE_NAMESPACE_BITS = 7 * 8; diff --git a/packages/world/src/modules/keyswithvalue/tables/KeysWithValue.sol b/packages/world-modules/src/modules/keyswithvalue/tables/KeysWithValue.sol similarity index 100% rename from packages/world/src/modules/keyswithvalue/tables/KeysWithValue.sol rename to packages/world-modules/src/modules/keyswithvalue/tables/KeysWithValue.sol diff --git a/packages/world/src/modules/std-delegations/CallboundDelegationControl.sol b/packages/world-modules/src/modules/std-delegations/CallboundDelegationControl.sol similarity index 92% rename from packages/world/src/modules/std-delegations/CallboundDelegationControl.sol rename to packages/world-modules/src/modules/std-delegations/CallboundDelegationControl.sol index b489cf263d..e24c2940c1 100644 --- a/packages/world/src/modules/std-delegations/CallboundDelegationControl.sol +++ b/packages/world-modules/src/modules/std-delegations/CallboundDelegationControl.sol @@ -1,8 +1,8 @@ // SPDX-License-Identifier: MIT pragma solidity >=0.8.21; -import { DelegationControl } from "../../DelegationControl.sol"; -import { ResourceId } from "../../WorldResourceId.sol"; +import { DelegationControl } from "@latticexyz/world/src/DelegationControl.sol"; +import { ResourceId } from "@latticexyz/world/src/WorldResourceId.sol"; import { CallboundDelegations } from "./tables/CallboundDelegations.sol"; contract CallboundDelegationControl is DelegationControl { diff --git a/packages/world/src/modules/std-delegations/StandardDelegationsModule.sol b/packages/world-modules/src/modules/std-delegations/StandardDelegationsModule.sol similarity index 85% rename from packages/world/src/modules/std-delegations/StandardDelegationsModule.sol rename to packages/world-modules/src/modules/std-delegations/StandardDelegationsModule.sol index 3e2edbd09a..5b754d1dc5 100644 --- a/packages/world/src/modules/std-delegations/StandardDelegationsModule.sol +++ b/packages/world-modules/src/modules/std-delegations/StandardDelegationsModule.sol @@ -1,11 +1,11 @@ // SPDX-License-Identifier: MIT pragma solidity >=0.8.21; -import { IBaseWorld } from "../../interfaces/IBaseWorld.sol"; +import { IBaseWorld } from "@latticexyz/world/src/interfaces/IBaseWorld.sol"; -import { Module } from "../../Module.sol"; -import { WorldContextConsumer } from "../../WorldContext.sol"; -import { revertWithBytes } from "../../revertWithBytes.sol"; +import { Module } from "@latticexyz/world/src/Module.sol"; +import { WorldContextConsumer } from "@latticexyz/world/src/WorldContext.sol"; +import { revertWithBytes } from "@latticexyz/world/src/revertWithBytes.sol"; import { CallboundDelegationControl } from "./CallboundDelegationControl.sol"; import { TimeboundDelegationControl } from "./TimeboundDelegationControl.sol"; diff --git a/packages/world/src/modules/std-delegations/TimeboundDelegationControl.sol b/packages/world-modules/src/modules/std-delegations/TimeboundDelegationControl.sol similarity index 87% rename from packages/world/src/modules/std-delegations/TimeboundDelegationControl.sol rename to packages/world-modules/src/modules/std-delegations/TimeboundDelegationControl.sol index 72c908938c..99b4009ce8 100644 --- a/packages/world/src/modules/std-delegations/TimeboundDelegationControl.sol +++ b/packages/world-modules/src/modules/std-delegations/TimeboundDelegationControl.sol @@ -1,8 +1,8 @@ // SPDX-License-Identifier: MIT pragma solidity >=0.8.21; -import { DelegationControl } from "../../DelegationControl.sol"; -import { ResourceId } from "../../WorldResourceId.sol"; +import { DelegationControl } from "@latticexyz/world/src/DelegationControl.sol"; +import { ResourceId } from "@latticexyz/world/src/WorldResourceId.sol"; import { TimeboundDelegations } from "./tables/TimeboundDelegations.sol"; contract TimeboundDelegationControl is DelegationControl { diff --git a/packages/world/src/modules/std-delegations/constants.sol b/packages/world-modules/src/modules/std-delegations/constants.sol similarity index 77% rename from packages/world/src/modules/std-delegations/constants.sol rename to packages/world-modules/src/modules/std-delegations/constants.sol index 69a343c5ad..bc6b4096b9 100644 --- a/packages/world/src/modules/std-delegations/constants.sol +++ b/packages/world-modules/src/modules/std-delegations/constants.sol @@ -2,8 +2,8 @@ pragma solidity >=0.8.21; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; -import { RESOURCE_SYSTEM } from "../../worldResourceTypes.sol"; -import { ROOT_NAMESPACE } from "../../constants.sol"; +import { RESOURCE_SYSTEM } from "@latticexyz/world/src/worldResourceTypes.sol"; +import { ROOT_NAMESPACE } from "@latticexyz/world/src/constants.sol"; bytes16 constant MODULE_NAME = bytes16("stddelegations.m"); diff --git a/packages/world/src/modules/std-delegations/tables/CallboundDelegations.sol b/packages/world-modules/src/modules/std-delegations/tables/CallboundDelegations.sol similarity index 100% rename from packages/world/src/modules/std-delegations/tables/CallboundDelegations.sol rename to packages/world-modules/src/modules/std-delegations/tables/CallboundDelegations.sol diff --git a/packages/world/src/modules/std-delegations/tables/TimeboundDelegations.sol b/packages/world-modules/src/modules/std-delegations/tables/TimeboundDelegations.sol similarity index 100% rename from packages/world/src/modules/std-delegations/tables/TimeboundDelegations.sol rename to packages/world-modules/src/modules/std-delegations/tables/TimeboundDelegations.sol diff --git a/packages/world/src/modules/uniqueentity/UniqueEntityModule.sol b/packages/world-modules/src/modules/uniqueentity/UniqueEntityModule.sol similarity index 85% rename from packages/world/src/modules/uniqueentity/UniqueEntityModule.sol rename to packages/world-modules/src/modules/uniqueentity/UniqueEntityModule.sol index a869cee541..f1d4af8fdc 100644 --- a/packages/world/src/modules/uniqueentity/UniqueEntityModule.sol +++ b/packages/world-modules/src/modules/uniqueentity/UniqueEntityModule.sol @@ -1,11 +1,11 @@ // SPDX-License-Identifier: MIT pragma solidity >=0.8.21; -import { IBaseWorld } from "../../interfaces/IBaseWorld.sol"; +import { IBaseWorld } from "@latticexyz/world/src/interfaces/IBaseWorld.sol"; -import { Module } from "../../Module.sol"; -import { WorldContextConsumer } from "../../WorldContext.sol"; -import { revertWithBytes } from "../../revertWithBytes.sol"; +import { Module } from "@latticexyz/world/src/Module.sol"; +import { WorldContextConsumer } from "@latticexyz/world/src/WorldContext.sol"; +import { revertWithBytes } from "@latticexyz/world/src/revertWithBytes.sol"; import { UniqueEntity } from "./tables/UniqueEntity.sol"; import { UniqueEntitySystem } from "./UniqueEntitySystem.sol"; diff --git a/packages/world/src/modules/uniqueentity/UniqueEntitySystem.sol b/packages/world-modules/src/modules/uniqueentity/UniqueEntitySystem.sol similarity index 88% rename from packages/world/src/modules/uniqueentity/UniqueEntitySystem.sol rename to packages/world-modules/src/modules/uniqueentity/UniqueEntitySystem.sol index c002792035..478d263dea 100644 --- a/packages/world/src/modules/uniqueentity/UniqueEntitySystem.sol +++ b/packages/world-modules/src/modules/uniqueentity/UniqueEntitySystem.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity >=0.8.21; -import { System } from "../../System.sol"; +import { System } from "@latticexyz/world/src/System.sol"; import { TABLE_ID } from "./constants.sol"; import { UniqueEntity } from "./tables/UniqueEntity.sol"; diff --git a/packages/world/src/modules/uniqueentity/constants.sol b/packages/world-modules/src/modules/uniqueentity/constants.sol similarity index 74% rename from packages/world/src/modules/uniqueentity/constants.sol rename to packages/world-modules/src/modules/uniqueentity/constants.sol index 41b8d793c8..07c4691423 100644 --- a/packages/world/src/modules/uniqueentity/constants.sol +++ b/packages/world-modules/src/modules/uniqueentity/constants.sol @@ -1,8 +1,8 @@ // SPDX-License-Identifier: MIT pragma solidity >=0.8.21; -import { ResourceId } from "../../WorldResourceId.sol"; -import { RESOURCE_TABLE, RESOURCE_SYSTEM } from "../../worldResourceTypes.sol"; +import { ResourceId } from "@latticexyz/world/src/WorldResourceId.sol"; +import { RESOURCE_TABLE, RESOURCE_SYSTEM } from "@latticexyz/world/src/worldResourceTypes.sol"; bytes14 constant NAMESPACE = bytes14("uniqueEntity"); bytes16 constant MODULE_NAME = bytes16("uniqueEntity"); diff --git a/packages/world/src/modules/uniqueentity/getUniqueEntity.sol b/packages/world-modules/src/modules/uniqueentity/getUniqueEntity.sol similarity index 81% rename from packages/world/src/modules/uniqueentity/getUniqueEntity.sol rename to packages/world-modules/src/modules/uniqueentity/getUniqueEntity.sol index cb4dd1981b..5486cc5043 100644 --- a/packages/world/src/modules/uniqueentity/getUniqueEntity.sol +++ b/packages/world-modules/src/modules/uniqueentity/getUniqueEntity.sol @@ -3,8 +3,8 @@ pragma solidity >=0.8.21; import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; -import { IBaseWorld } from "../../interfaces/IBaseWorld.sol"; -import { IUniqueEntitySystem } from "../../interfaces/IUniqueEntitySystem.sol"; +import { IBaseWorld } from "@latticexyz/world/src/interfaces/IBaseWorld.sol"; +import { IUniqueEntitySystem } from "@latticexyz/world/src/interfaces/IUniqueEntitySystem.sol"; /** * Increment and get an entity nonce. diff --git a/packages/world/src/modules/uniqueentity/tables/UniqueEntity.sol b/packages/world-modules/src/modules/uniqueentity/tables/UniqueEntity.sol similarity index 100% rename from packages/world/src/modules/uniqueentity/tables/UniqueEntity.sol rename to packages/world-modules/src/modules/uniqueentity/tables/UniqueEntity.sol diff --git a/packages/world/src/modules/utils/ArrayLib.sol b/packages/world-modules/src/modules/utils/ArrayLib.sol similarity index 100% rename from packages/world/src/modules/utils/ArrayLib.sol rename to packages/world-modules/src/modules/utils/ArrayLib.sol diff --git a/packages/world/test/KeysInTableModule.t.sol b/packages/world-modules/test/KeysInTableModule.t.sol similarity index 97% rename from packages/world/test/KeysInTableModule.t.sol rename to packages/world-modules/test/KeysInTableModule.t.sol index 80cbd901b7..80b79f3968 100644 --- a/packages/world/test/KeysInTableModule.t.sol +++ b/packages/world-modules/test/KeysInTableModule.t.sol @@ -11,13 +11,13 @@ import { PackedCounter } from "@latticexyz/store/src/PackedCounter.sol"; import { SchemaEncodeHelper } from "@latticexyz/store/test/SchemaEncodeHelper.sol"; import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; -import { World } from "../src/World.sol"; -import { IBaseWorld } from "../src/interfaces/IBaseWorld.sol"; -import { ResourceId, WorldResourceIdLib, WorldResourceIdInstance } from "../src/WorldResourceId.sol"; -import { ROOT_NAMESPACE } from "../src/constants.sol"; -import { RESOURCE_TABLE } from "../src/worldResourceTypes.sol"; +import { World } from "@latticexyz/world/src/World.sol"; +import { IBaseWorld } from "@latticexyz/world/src/interfaces/IBaseWorld.sol"; +import { ResourceId, WorldResourceIdLib, WorldResourceIdInstance } from "@latticexyz/world/src/WorldResourceId.sol"; +import { ROOT_NAMESPACE } from "@latticexyz/world/src/constants.sol"; +import { RESOURCE_TABLE } from "@latticexyz/world/src/worldResourceTypes.sol"; -import { CoreModule } from "../src/modules/core/CoreModule.sol"; +import { CoreModule } from "@latticexyz/world/src/modules/core/CoreModule.sol"; import { KeysInTableModule } from "../src/modules/keysintable/KeysInTableModule.sol"; import { getKeysInTable } from "../src/modules/keysintable/getKeysInTable.sol"; import { hasKey } from "../src/modules/keysintable/hasKey.sol"; diff --git a/packages/world/test/KeysWithValueModule.t.sol b/packages/world-modules/test/KeysWithValueModule.t.sol similarity index 95% rename from packages/world/test/KeysWithValueModule.t.sol rename to packages/world-modules/test/KeysWithValueModule.t.sol index 8be0d88fe4..0e4ef27a30 100644 --- a/packages/world/test/KeysWithValueModule.t.sol +++ b/packages/world-modules/test/KeysWithValueModule.t.sol @@ -13,13 +13,13 @@ import { SchemaEncodeHelper } from "@latticexyz/store/test/SchemaEncodeHelper.so import { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol"; import { FieldLayoutEncodeHelper } from "@latticexyz/store/test/FieldLayoutEncodeHelper.sol"; -import { World } from "../src/World.sol"; -import { IBaseWorld } from "../src/interfaces/IBaseWorld.sol"; -import { WorldResourceIdLib, WorldResourceIdInstance, NAME_BITS, TYPE_BITS } from "../src/WorldResourceId.sol"; -import { ROOT_NAMESPACE } from "../src/constants.sol"; -import { RESOURCE_TABLE } from "../src/worldResourceTypes.sol"; +import { World } from "@latticexyz/world/src/World.sol"; +import { IBaseWorld } from "@latticexyz/world/src/interfaces/IBaseWorld.sol"; +import { WorldResourceIdLib, WorldResourceIdInstance, NAME_BITS, TYPE_BITS } from "@latticexyz/world/src/WorldResourceId.sol"; +import { ROOT_NAMESPACE } from "@latticexyz/world/src/constants.sol"; +import { RESOURCE_TABLE } from "@latticexyz/world/src/worldResourceTypes.sol"; -import { CoreModule } from "../src/modules/core/CoreModule.sol"; +import { CoreModule } from "@latticexyz/world/src/modules/core/CoreModule.sol"; import { KeysWithValueModule } from "../src/modules/keyswithvalue/KeysWithValueModule.sol"; import { MODULE_NAMESPACE } from "../src/modules/keyswithvalue/constants.sol"; import { KeysWithValue } from "../src/modules/keyswithvalue/tables/KeysWithValue.sol"; diff --git a/packages/world/test/StandardDelegationsModule.t.sol b/packages/world-modules/test/StandardDelegationsModule.t.sol similarity index 86% rename from packages/world/test/StandardDelegationsModule.t.sol rename to packages/world-modules/test/StandardDelegationsModule.t.sol index 42e49f5372..b95d5d7225 100644 --- a/packages/world/test/StandardDelegationsModule.t.sol +++ b/packages/world-modules/test/StandardDelegationsModule.t.sol @@ -4,24 +4,24 @@ pragma solidity >=0.8.21; import { Test } from "forge-std/Test.sol"; import { GasReporter } from "@latticexyz/gas-report/src/GasReporter.sol"; -import { World } from "../src/World.sol"; -import { ResourceId, WorldResourceIdLib, WorldResourceIdInstance } from "../src/WorldResourceId.sol"; -import { System } from "../src/System.sol"; -import { RESOURCE_SYSTEM } from "../src/worldResourceTypes.sol"; +import { World } from "@latticexyz/world/src/World.sol"; +import { ResourceId, WorldResourceIdLib, WorldResourceIdInstance } from "@latticexyz/world/src/WorldResourceId.sol"; +import { System } from "@latticexyz/world/src/System.sol"; +import { RESOURCE_SYSTEM } from "@latticexyz/world/src/worldResourceTypes.sol"; -import { IBaseWorld } from "../src/interfaces/IBaseWorld.sol"; -import { IWorldErrors } from "../src/interfaces/IWorldErrors.sol"; -import { DELEGATION_CONTROL_INTERFACE_ID } from "../src/interfaces/IDelegationControl.sol"; +import { IBaseWorld } from "@latticexyz/world/src/interfaces/IBaseWorld.sol"; +import { IWorldErrors } from "@latticexyz/world/src/interfaces/IWorldErrors.sol"; +import { DELEGATION_CONTROL_INTERFACE_ID } from "@latticexyz/world/src/interfaces/IDelegationControl.sol"; -import { CoreModule } from "../src/modules/core/CoreModule.sol"; -import { Systems } from "../src/modules/core/tables/Systems.sol"; +import { CoreModule } from "@latticexyz/world/src/modules/core/CoreModule.sol"; +import { Systems } from "@latticexyz/world/src/modules/core/tables/Systems.sol"; import { StandardDelegationsModule } from "../src/modules/std-delegations/StandardDelegationsModule.sol"; import { CallboundDelegationControl } from "../src/modules/std-delegations/CallboundDelegationControl.sol"; import { TimeboundDelegationControl } from "../src/modules/std-delegations/TimeboundDelegationControl.sol"; import { CALLBOUND_DELEGATION, TIMEBOUND_DELEGATION } from "../src/modules/std-delegations/StandardDelegationsModule.sol"; -import { WorldTestSystem } from "./World.t.sol"; +import { WorldTestSystem } from "@latticexyz/world/test/World.t.sol"; contract StandardDelegationsModuleTest is Test, GasReporter { IBaseWorld private world; diff --git a/packages/world/test/UniqueEntityModule.t.sol b/packages/world-modules/test/UniqueEntityModule.t.sol similarity index 88% rename from packages/world/test/UniqueEntityModule.t.sol rename to packages/world-modules/test/UniqueEntityModule.t.sol index d9bec364d6..0b1f549ad1 100644 --- a/packages/world/test/UniqueEntityModule.t.sol +++ b/packages/world-modules/test/UniqueEntityModule.t.sol @@ -4,18 +4,18 @@ pragma solidity >=0.8.21; import { Test } from "forge-std/Test.sol"; import { GasReporter } from "@latticexyz/gas-report/src/GasReporter.sol"; -import { World } from "../src/World.sol"; -import { IBaseWorld } from "../src/interfaces/IBaseWorld.sol"; -import { IWorldErrors } from "../src/interfaces/IWorldErrors.sol"; +import { World } from "@latticexyz/world/src/World.sol"; +import { IBaseWorld } from "@latticexyz/world/src/interfaces/IBaseWorld.sol"; +import { IWorldErrors } from "@latticexyz/world/src/interfaces/IWorldErrors.sol"; -import { CoreModule } from "../src/modules/core/CoreModule.sol"; +import { CoreModule } from "@latticexyz/world/src/modules/core/CoreModule.sol"; import { UniqueEntityModule } from "../src/modules/uniqueentity/UniqueEntityModule.sol"; import { UniqueEntity } from "../src/modules/uniqueentity/tables/UniqueEntity.sol"; import { getUniqueEntity } from "../src/modules/uniqueentity/getUniqueEntity.sol"; import { NAMESPACE, TABLE_NAME } from "../src/modules/uniqueentity/constants.sol"; -import { ResourceId, WorldResourceIdLib, WorldResourceIdInstance } from "../src/WorldResourceId.sol"; -import { RESOURCE_TABLE } from "../src/worldResourceTypes.sol"; +import { ResourceId, WorldResourceIdLib, WorldResourceIdInstance } from "@latticexyz/world/src/WorldResourceId.sol"; +import { RESOURCE_TABLE } from "@latticexyz/world/src/worldResourceTypes.sol"; contract UniqueEntityModuleTest is Test, GasReporter { using WorldResourceIdInstance for ResourceId; diff --git a/packages/world/test/query.t.sol b/packages/world-modules/test/query.t.sol similarity index 97% rename from packages/world/test/query.t.sol rename to packages/world-modules/test/query.t.sol index 87d3d0e64b..c52f3488cc 100644 --- a/packages/world/test/query.t.sol +++ b/packages/world-modules/test/query.t.sol @@ -11,13 +11,13 @@ import { SchemaEncodeHelper } from "@latticexyz/store/test/SchemaEncodeHelper.so import { PackedCounter } from "@latticexyz/store/src/PackedCounter.sol"; import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; -import { World } from "../src/World.sol"; -import { IBaseWorld } from "../src/interfaces/IBaseWorld.sol"; -import { ResourceId, WorldResourceIdLib, WorldResourceIdInstance } from "../src/WorldResourceId.sol"; -import { ROOT_NAMESPACE } from "../src/constants.sol"; -import { RESOURCE_TABLE } from "../src/worldResourceTypes.sol"; +import { World } from "@latticexyz/world/src/World.sol"; +import { IBaseWorld } from "@latticexyz/world/src/interfaces/IBaseWorld.sol"; +import { ResourceId, WorldResourceIdLib, WorldResourceIdInstance } from "@latticexyz/world/src/WorldResourceId.sol"; +import { ROOT_NAMESPACE } from "@latticexyz/world/src/constants.sol"; +import { RESOURCE_TABLE } from "@latticexyz/world/src/worldResourceTypes.sol"; -import { CoreModule } from "../src/modules/core/CoreModule.sol"; +import { CoreModule } from "@latticexyz/world/src/modules/core/CoreModule.sol"; import { KeysInTableModule } from "../src/modules/keysintable/KeysInTableModule.sol"; import { KeysWithValueModule } from "../src/modules/keyswithvalue/KeysWithValueModule.sol"; import { query, QueryFragment, QueryType } from "../src/modules/keysintable/query.sol"; diff --git a/packages/world-modules/ts/scripts/tablegen.ts b/packages/world-modules/ts/scripts/tablegen.ts new file mode 100644 index 0000000000..5a91d6d119 --- /dev/null +++ b/packages/world-modules/ts/scripts/tablegen.ts @@ -0,0 +1,11 @@ +import path from "path"; +import { loadConfig } from "@latticexyz/config/node"; +import { getRemappings, getSrcDirectory } from "@latticexyz/common/foundry"; +import { StoreConfig } from "@latticexyz/store"; +import { tablegen } from "@latticexyz/store/codegen"; + +const config = (await loadConfig()) as StoreConfig; +const srcDir = await getSrcDirectory(); +const remappings = await getRemappings(); + +await tablegen(config, path.join(srcDir, config.codegenDirectory), remappings); diff --git a/packages/world-modules/ts/scripts/worldgen.ts b/packages/world-modules/ts/scripts/worldgen.ts new file mode 100644 index 0000000000..09b2b09a2e --- /dev/null +++ b/packages/world-modules/ts/scripts/worldgen.ts @@ -0,0 +1,30 @@ +import glob from "glob"; +import path, { basename } from "path"; +import { rmSync } from "fs"; +import { loadConfig } from "@latticexyz/config/node"; +import { getSrcDirectory } from "@latticexyz/common/foundry"; +import { WorldConfig } from "@latticexyz/world"; +import { worldgen } from "@latticexyz/world/node"; +import { StoreConfig } from "@latticexyz/store"; + +// TODO dedupe this and cli's worldgen command +const configPath = undefined; +const clean = false; +const srcDir = await getSrcDirectory(); + +// Get a list of all contract names +const existingContracts = glob.sync(`${srcDir}/**/*.sol`).map((path) => ({ + path, + basename: basename(path, ".sol"), +})); + +// Load and resolve the config +const mudConfig = (await loadConfig(configPath)) as StoreConfig & WorldConfig; + +const outputBaseDirectory = path.join(srcDir, mudConfig.codegenDirectory); + +// clear the worldgen directory +if (clean) rmSync(path.join(outputBaseDirectory, mudConfig.worldgenDirectory), { recursive: true, force: true }); + +// generate new interfaces +await worldgen(mudConfig, existingContracts, outputBaseDirectory); diff --git a/packages/world-modules/tsconfig.json b/packages/world-modules/tsconfig.json new file mode 100644 index 0000000000..e8a23b77e4 --- /dev/null +++ b/packages/world-modules/tsconfig.json @@ -0,0 +1,19 @@ +{ + "compilerOptions": { + /* Visit https://aka.ms/tsconfig.json to read more about this file */ + "target": "es2021", + "types": ["node"], + "module": "esnext", + "moduleResolution": "node", + "declaration": true, + "sourceMap": true, + "outDir": "dist", + "isolatedModules": true, + "allowSyntheticDefaultImports": true, + "esModuleInterop": true, + "forceConsistentCasingInFileNames": true, + "strict": true, + "skipLibCheck": true + }, + "include": ["mud.config.ts"] +} diff --git a/packages/world-modules/tsup.config.ts b/packages/world-modules/tsup.config.ts new file mode 100644 index 0000000000..d2aa3e215e --- /dev/null +++ b/packages/world-modules/tsup.config.ts @@ -0,0 +1,11 @@ +import { defineConfig } from "tsup"; + +export default defineConfig({ + entry: ["mud.config.ts"], + target: "esnext", + format: ["esm"], + dts: false, + sourcemap: true, + clean: true, + minify: true, +}); diff --git a/packages/world/gas-report.json b/packages/world/gas-report.json index 6c69342159..d08185a933 100644 --- a/packages/world/gas-report.json +++ b/packages/world/gas-report.json @@ -47,246 +47,6 @@ "name": "call systems with callBatch", "gasUsed": 45264 }, - { - "file": "test/KeysInTableModule.t.sol", - "test": "testInstallComposite", - "name": "install keys in table module", - "gasUsed": 1408400 - }, - { - "file": "test/KeysInTableModule.t.sol", - "test": "testInstallGas", - "name": "install keys in table module", - "gasUsed": 1408400 - }, - { - "file": "test/KeysInTableModule.t.sol", - "test": "testInstallGas", - "name": "set a record on a table with keysInTableModule installed", - "gasUsed": 159030 - }, - { - "file": "test/KeysInTableModule.t.sol", - "test": "testInstallSingleton", - "name": "install keys in table module", - "gasUsed": 1408400 - }, - { - "file": "test/KeysInTableModule.t.sol", - "test": "testSetAndDeleteRecordHookCompositeGas", - "name": "install keys in table module", - "gasUsed": 1408400 - }, - { - "file": "test/KeysInTableModule.t.sol", - "test": "testSetAndDeleteRecordHookCompositeGas", - "name": "change a composite record on a table with keysInTableModule installed", - "gasUsed": 22571 - }, - { - "file": "test/KeysInTableModule.t.sol", - "test": "testSetAndDeleteRecordHookCompositeGas", - "name": "delete a composite record on a table with keysInTableModule installed", - "gasUsed": 156371 - }, - { - "file": "test/KeysInTableModule.t.sol", - "test": "testSetAndDeleteRecordHookGas", - "name": "install keys in table module", - "gasUsed": 1408400 - }, - { - "file": "test/KeysInTableModule.t.sol", - "test": "testSetAndDeleteRecordHookGas", - "name": "change a record on a table with keysInTableModule installed", - "gasUsed": 21293 - }, - { - "file": "test/KeysInTableModule.t.sol", - "test": "testSetAndDeleteRecordHookGas", - "name": "delete a record on a table with keysInTableModule installed", - "gasUsed": 85329 - }, - { - "file": "test/KeysWithValueModule.t.sol", - "test": "testGetKeysWithValueGas", - "name": "install keys with value module", - "gasUsed": 649560 - }, - { - "file": "test/KeysWithValueModule.t.sol", - "test": "testGetKeysWithValueGas", - "name": "Get list of keys with a given value", - "gasUsed": 5712 - }, - { - "file": "test/KeysWithValueModule.t.sol", - "test": "testGetTargetTableId", - "name": "compute the target table selector", - "gasUsed": 2624 - }, - { - "file": "test/KeysWithValueModule.t.sol", - "test": "testInstall", - "name": "install keys with value module", - "gasUsed": 649560 - }, - { - "file": "test/KeysWithValueModule.t.sol", - "test": "testInstall", - "name": "set a record on a table with KeysWithValueModule installed", - "gasUsed": 135698 - }, - { - "file": "test/KeysWithValueModule.t.sol", - "test": "testSetAndDeleteRecordHook", - "name": "install keys with value module", - "gasUsed": 649560 - }, - { - "file": "test/KeysWithValueModule.t.sol", - "test": "testSetAndDeleteRecordHook", - "name": "change a record on a table with KeysWithValueModule installed", - "gasUsed": 104082 - }, - { - "file": "test/KeysWithValueModule.t.sol", - "test": "testSetAndDeleteRecordHook", - "name": "delete a record on a table with KeysWithValueModule installed", - "gasUsed": 36693 - }, - { - "file": "test/KeysWithValueModule.t.sol", - "test": "testSetField", - "name": "install keys with value module", - "gasUsed": 649560 - }, - { - "file": "test/KeysWithValueModule.t.sol", - "test": "testSetField", - "name": "set a field on a table with KeysWithValueModule installed", - "gasUsed": 146907 - }, - { - "file": "test/KeysWithValueModule.t.sol", - "test": "testSetField", - "name": "change a field on a table with KeysWithValueModule installed", - "gasUsed": 111666 - }, - { - "file": "test/query.t.sol", - "test": "testCombinedHasHasValueNotQuery", - "name": "CombinedHasHasValueNotQuery", - "gasUsed": 105109 - }, - { - "file": "test/query.t.sol", - "test": "testCombinedHasHasValueQuery", - "name": "CombinedHasHasValueQuery", - "gasUsed": 53579 - }, - { - "file": "test/query.t.sol", - "test": "testCombinedHasNotQuery", - "name": "CombinedHasNotQuery", - "gasUsed": 131374 - }, - { - "file": "test/query.t.sol", - "test": "testCombinedHasQuery", - "name": "CombinedHasQuery", - "gasUsed": 84497 - }, - { - "file": "test/query.t.sol", - "test": "testCombinedHasValueNotQuery", - "name": "CombinedHasValueNotQuery", - "gasUsed": 85116 - }, - { - "file": "test/query.t.sol", - "test": "testCombinedHasValueQuery", - "name": "CombinedHasValueQuery", - "gasUsed": 15705 - }, - { - "file": "test/query.t.sol", - "test": "testHasQuery", - "name": "HasQuery", - "gasUsed": 18882 - }, - { - "file": "test/query.t.sol", - "test": "testHasQuery1000Keys", - "name": "HasQuery with 1000 keys", - "gasUsed": 5804585 - }, - { - "file": "test/query.t.sol", - "test": "testHasQuery100Keys", - "name": "HasQuery with 100 keys", - "gasUsed": 541538 - }, - { - "file": "test/query.t.sol", - "test": "testHasValueQuery", - "name": "HasValueQuery", - "gasUsed": 7521 - }, - { - "file": "test/query.t.sol", - "test": "testNotValueQuery", - "name": "NotValueQuery", - "gasUsed": 47175 - }, - { - "file": "test/StandardDelegationsModule.t.sol", - "test": "testCallFromCallboundDelegation", - "name": "register a callbound delegation", - "gasUsed": 117579 - }, - { - "file": "test/StandardDelegationsModule.t.sol", - "test": "testCallFromCallboundDelegation", - "name": "call a system via a callbound delegation", - "gasUsed": 36737 - }, - { - "file": "test/StandardDelegationsModule.t.sol", - "test": "testCallFromTimeboundDelegation", - "name": "register a timebound delegation", - "gasUsed": 112073 - }, - { - "file": "test/StandardDelegationsModule.t.sol", - "test": "testCallFromTimeboundDelegation", - "name": "call a system via a timebound delegation", - "gasUsed": 26822 - }, - { - "file": "test/UniqueEntityModule.t.sol", - "test": "testInstall", - "name": "install unique entity module", - "gasUsed": 676208 - }, - { - "file": "test/UniqueEntityModule.t.sol", - "test": "testInstall", - "name": "get a unique entity nonce (non-root module)", - "gasUsed": 51180 - }, - { - "file": "test/UniqueEntityModule.t.sol", - "test": "testInstallRoot", - "name": "installRoot unique entity module", - "gasUsed": 643472 - }, - { - "file": "test/UniqueEntityModule.t.sol", - "test": "testInstallRoot", - "name": "get a unique entity nonce (root module)", - "gasUsed": 51180 - }, { "file": "test/World.t.sol", "test": "testCall", diff --git a/packages/world/hardhat.config.ts b/packages/world/hardhat.config.ts deleted file mode 100644 index 32338a8fe1..0000000000 --- a/packages/world/hardhat.config.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { HardhatUserConfig } from "hardhat/config"; -import "./tasks/compile"; - -const config: HardhatUserConfig = { - paths: { - sources: "./src", - }, - solidity: { - version: "0.8.13", - settings: { - optimizer: { - enabled: true, - runs: 200, - }, - }, - }, -}; - -export default config; diff --git a/packages/world/mud.config.ts b/packages/world/mud.config.ts index f6efdff18b..fdb06c586e 100644 --- a/packages/world/mud.config.ts +++ b/packages/world/mud.config.ts @@ -59,7 +59,7 @@ export default mudConfig({ }, /************************************************************************ * - * MODULE TABLES + * CORE MODULE TABLES * ************************************************************************/ Balances: { @@ -119,65 +119,6 @@ export default mudConfig({ }, offchainOnly: true, }, - KeysWithValue: { - directory: "modules/keyswithvalue/tables", - keySchema: { - valueHash: "bytes32", - }, - valueSchema: { - keysWithValue: "bytes32[]", // For now only supports 1 key per value - }, - tableIdArgument: true, - }, - KeysInTable: { - directory: "modules/keysintable/tables", - keySchema: { sourceTableId: "ResourceId" }, - valueSchema: { - keys0: "bytes32[]", - keys1: "bytes32[]", - keys2: "bytes32[]", - keys3: "bytes32[]", - keys4: "bytes32[]", - }, - }, - UsedKeysIndex: { - directory: "modules/keysintable/tables", - keySchema: { - sourceTableId: "ResourceId", - keysHash: "bytes32", - }, - valueSchema: { has: "bool", index: "uint40" }, - dataStruct: false, - }, - UniqueEntity: { - directory: "modules/uniqueentity/tables", - keySchema: {}, - valueSchema: "uint256", - tableIdArgument: true, - storeArgument: true, - }, - CallboundDelegations: { - directory: "modules/std-delegations/tables", - keySchema: { - delegator: "address", - delegatee: "address", - systemId: "ResourceId", - callDataHash: "bytes32", - }, - valueSchema: { - availableCalls: "uint256", - }, - }, - TimeboundDelegations: { - directory: "modules/std-delegations/tables", - keySchema: { - delegator: "address", - delegatee: "address", - }, - valueSchema: { - maxTimestamp: "uint256", - }, - }, /************************************************************************ * * TEST TABLES @@ -207,12 +148,6 @@ export default mudConfig({ }, }, excludeSystems: [ - // IUniqueEntitySystem is not part of the root namespace and - // installed separately by UniqueEntityModule. - // TODO: Move optional modules into a separate package - // (see https://github.com/latticexyz/mud/pull/584) - "UniqueEntitySystem", - // Worldgen currently does not support systems inheriting logic // from other contracts, so all parts of CoreSystem are named // System too to be included in the IBaseWorld interface. diff --git a/packages/world/package.json b/packages/world/package.json index 6860b09f41..2a725cd877 100644 --- a/packages/world/package.json +++ b/packages/world/package.json @@ -63,7 +63,6 @@ "ejs": "^3.1.8", "forge-std": "https://github.com/foundry-rs/forge-std.git#74cfb77e308dd188d2f58864aaf44963ae6b88b1", "glob": "^8.0.3", - "hardhat": "^2.10.2", "solhint": "^3.3.7", "tsup": "^6.7.0", "tsx": "^3.12.6", diff --git a/packages/world/src/index.sol b/packages/world/src/index.sol index 6dc7d28033..5d61620cac 100644 --- a/packages/world/src/index.sol +++ b/packages/world/src/index.sol @@ -14,12 +14,6 @@ import { SystemRegistry, SystemRegistryTableId } from "./modules/core/tables/Sys import { SystemHooks, SystemHooksTableId } from "./modules/core/tables/SystemHooks.sol"; import { FunctionSelectors, FunctionSelectorsTableId } from "./modules/core/tables/FunctionSelectors.sol"; import { FunctionSignatures, FunctionSignaturesTableId } from "./modules/core/tables/FunctionSignatures.sol"; -import { KeysWithValue } from "./modules/keyswithvalue/tables/KeysWithValue.sol"; -import { KeysInTable, KeysInTableData, KeysInTableTableId } from "./modules/keysintable/tables/KeysInTable.sol"; -import { UsedKeysIndex, UsedKeysIndexTableId } from "./modules/keysintable/tables/UsedKeysIndex.sol"; -import { UniqueEntity } from "./modules/uniqueentity/tables/UniqueEntity.sol"; -import { CallboundDelegations, CallboundDelegationsTableId } from "./modules/std-delegations/tables/CallboundDelegations.sol"; -import { TimeboundDelegations, TimeboundDelegationsTableId } from "./modules/std-delegations/tables/TimeboundDelegations.sol"; import { Bool } from "./../test/tables/Bool.sol"; import { TwoFields, TwoFieldsData } from "./../test/tables/TwoFields.sol"; import { AddressArray } from "./../test/tables/AddressArray.sol"; diff --git a/packages/world/tasks/compile.ts b/packages/world/tasks/compile.ts deleted file mode 100644 index 65335021b4..0000000000 --- a/packages/world/tasks/compile.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { TASK_COMPILE_SOLIDITY } from "hardhat/builtin-tasks/task-names"; -import * as fs from "fs"; -import * as path from "path"; -import { subtask } from "hardhat/config"; - -subtask(TASK_COMPILE_SOLIDITY).setAction(async (_: { force: boolean; quiet: boolean }, { config }, runSuper) => { - console.log("Symlinking forge-style libraries"); - const symlinks: string[] = []; - const remappings = fs - .readFileSync("remappings.txt") - .toString() - .split("\n") - .filter((r) => r.length > 0) - .map((r) => r.split("=")); - - console.log("remappings", remappings); - for (const [library, libraryPath] of remappings) { - const symlinkPath = path.join(process.cwd(), library.replace("/", "")); - console.log("Adding symlink at path: " + symlinkPath); - if (fs.existsSync(symlinkPath)) { - console.warn("symlink already exists!"); - } else { - const libPath = path.join(config.paths.sources, "..", libraryPath); - fs.symlinkSync(libPath, symlinkPath, "dir"); - } - symlinks.push(symlinkPath); - } - try { - await runSuper(); - } catch (e) { - console.error(e); - } finally { - for (const symlink of symlinks) { - console.log("Removing symlink at path: " + symlink); - fs.unlinkSync(symlink); - } - } -}); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index bbdbb441ca..dd45ad64f3 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -157,6 +157,9 @@ importers: '@latticexyz/world': specifier: workspace:* version: link:../world + '@latticexyz/world-modules': + specifier: workspace:* + version: link:../world-modules chalk: specifier: ^5.0.1 version: 5.2.0 @@ -1017,9 +1020,70 @@ importers: glob: specifier: ^8.0.3 version: 8.0.3 - hardhat: - specifier: ^2.10.2 - version: 2.10.2(typescript@5.1.6) + solhint: + specifier: ^3.3.7 + version: 3.3.7 + tsup: + specifier: ^6.7.0 + version: 6.7.0 + tsx: + specifier: ^3.12.6 + version: 3.12.6 + vitest: + specifier: 0.31.4 + version: 0.31.4 + + packages/world-modules: + dependencies: + '@latticexyz/common': + specifier: workspace:* + version: link:../common + '@latticexyz/config': + specifier: workspace:* + version: link:../config + '@latticexyz/schema-type': + specifier: workspace:* + version: link:../schema-type + '@latticexyz/store': + specifier: workspace:* + version: link:../store + '@latticexyz/world': + specifier: workspace:* + version: link:../world + zod: + specifier: ^3.21.4 + version: 3.21.4 + devDependencies: + '@latticexyz/abi-ts': + specifier: workspace:* + version: link:../abi-ts + '@latticexyz/gas-report': + specifier: workspace:* + version: link:../gas-report + '@types/ejs': + specifier: ^3.1.1 + version: 3.1.1 + '@types/glob': + specifier: ^7.2.0 + version: 7.2.0 + '@types/mocha': + specifier: ^9.1.1 + version: 9.1.1 + '@types/node': + specifier: ^18.15.11 + version: 18.15.11 + ds-test: + specifier: https://github.com/dapphub/ds-test.git#e282159d5170298eb2455a6c05280ab5a73a4ef0 + version: github.com/dapphub/ds-test/e282159d5170298eb2455a6c05280ab5a73a4ef0 + ejs: + specifier: ^3.1.8 + version: 3.1.8 + forge-std: + specifier: https://github.com/foundry-rs/forge-std.git#74cfb77e308dd188d2f58864aaf44963ae6b88b1 + version: github.com/foundry-rs/forge-std/74cfb77e308dd188d2f58864aaf44963ae6b88b1 + glob: + specifier: ^8.0.3 + version: 8.0.3 solhint: specifier: ^3.3.7 version: 3.3.7 @@ -4812,6 +4876,18 @@ packages: time-zone: 1.0.0 dev: true + /debug@4.3.4: + resolution: {integrity: sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==} + engines: {node: '>=6.0'} + peerDependencies: + supports-color: '*' + peerDependenciesMeta: + supports-color: + optional: true + dependencies: + ms: 2.1.2 + dev: true + /debug@4.3.4(supports-color@8.1.1): resolution: {integrity: sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==} engines: {node: '>=6.0'} @@ -5487,7 +5563,7 @@ packages: ajv: 6.12.6 chalk: 2.4.2 cross-spawn: 6.0.5 - debug: 4.3.4(supports-color@8.1.1) + debug: 4.3.4 doctrine: 3.0.0 eslint-scope: 4.0.3 eslint-utils: 1.4.3 @@ -8929,6 +9005,22 @@ packages: postcss: 8.4.23 dev: true + /postcss-load-config@3.1.4: + resolution: {integrity: sha512-6DiM4E7v4coTE4uzA8U//WhtPwyhiim3eyjEMFCnUpzbrkK9wJHgKDT2mR+HbtSrd/NubVaYTOpSpjUl8NQeRg==} + engines: {node: '>= 10'} + peerDependencies: + postcss: '>=8.0.9' + ts-node: '>=9.0.0' + peerDependenciesMeta: + postcss: + optional: true + ts-node: + optional: true + dependencies: + lilconfig: 2.1.0 + yaml: 1.10.2 + dev: true + /postcss-load-config@3.1.4(postcss@8.4.23): resolution: {integrity: sha512-6DiM4E7v4coTE4uzA8U//WhtPwyhiim3eyjEMFCnUpzbrkK9wJHgKDT2mR+HbtSrd/NubVaYTOpSpjUl8NQeRg==} engines: {node: '>= 10'} @@ -10495,6 +10587,41 @@ packages: resolution: {integrity: sha512-Tyrf5mxF8Ofs1tNoxA13lFeZ2Zrbd6cKbuH3V+MQ5sb6DtBj5FjrXVsRWT8YvNAQTqNoz66dz1WsbigI22aEnw==} dev: true + /tsup@6.7.0: + resolution: {integrity: sha512-L3o8hGkaHnu5TdJns+mCqFsDBo83bJ44rlK7e6VdanIvpea4ArPcU3swWGsLVbXak1PqQx/V+SSmFPujBK+zEQ==} + engines: {node: '>=14.18'} + hasBin: true + peerDependencies: + '@swc/core': ^1 + postcss: ^8.4.12 + typescript: '>=4.1.0' + peerDependenciesMeta: + '@swc/core': + optional: true + postcss: + optional: true + typescript: + optional: true + dependencies: + bundle-require: 4.0.1(esbuild@0.17.17) + cac: 6.7.14 + chokidar: 3.5.3 + debug: 4.3.4 + esbuild: 0.17.17 + execa: 5.1.1 + globby: 11.1.0 + joycon: 3.1.1 + postcss-load-config: 3.1.4 + resolve-from: 5.0.0 + rollup: 3.21.8 + source-map: 0.8.0-beta.0 + sucrase: 3.32.0 + tree-kill: 1.2.2 + transitivePeerDependencies: + - supports-color + - ts-node + dev: true + /tsup@6.7.0(postcss@8.4.23)(typescript@5.1.6): resolution: {integrity: sha512-L3o8hGkaHnu5TdJns+mCqFsDBo83bJ44rlK7e6VdanIvpea4ArPcU3swWGsLVbXak1PqQx/V+SSmFPujBK+zEQ==} engines: {node: '>=14.18'} @@ -10857,7 +10984,7 @@ packages: hasBin: true dependencies: cac: 6.7.14 - debug: 4.3.4(supports-color@8.1.1) + debug: 4.3.4 mlly: 1.2.0 pathe: 1.1.0 picocolors: 1.0.0 @@ -10905,6 +11032,71 @@ packages: fsevents: 2.3.2 dev: true + /vitest@0.31.4: + resolution: {integrity: sha512-GoV0VQPmWrUFOZSg3RpQAPN+LPmHg2/gxlMNJlyxJihkz6qReHDV6b0pPDcqFLNEPya4tWJ1pgwUNP9MLmUfvQ==} + engines: {node: '>=v14.18.0'} + hasBin: true + peerDependencies: + '@edge-runtime/vm': '*' + '@vitest/browser': '*' + '@vitest/ui': '*' + happy-dom: '*' + jsdom: '*' + playwright: '*' + safaridriver: '*' + webdriverio: '*' + peerDependenciesMeta: + '@edge-runtime/vm': + optional: true + '@vitest/browser': + optional: true + '@vitest/ui': + optional: true + happy-dom: + optional: true + jsdom: + optional: true + playwright: + optional: true + safaridriver: + optional: true + webdriverio: + optional: true + dependencies: + '@types/chai': 4.3.5 + '@types/chai-subset': 1.3.3 + '@types/node': 18.15.11 + '@vitest/expect': 0.31.4 + '@vitest/runner': 0.31.4 + '@vitest/snapshot': 0.31.4 + '@vitest/spy': 0.31.4 + '@vitest/utils': 0.31.4 + acorn: 8.8.2 + acorn-walk: 8.2.0 + cac: 6.7.14 + chai: 4.3.7 + concordance: 5.0.4 + debug: 4.3.4 + local-pkg: 0.4.3 + magic-string: 0.30.0 + pathe: 1.1.0 + picocolors: 1.0.0 + std-env: 3.3.2 + strip-literal: 1.0.1 + tinybench: 2.5.0 + tinypool: 0.5.0 + vite: 4.3.6(@types/node@18.15.11) + vite-node: 0.31.4(@types/node@18.15.11) + why-is-node-running: 2.2.2 + transitivePeerDependencies: + - less + - sass + - stylus + - sugarss + - supports-color + - terser + dev: true + /vitest@0.31.4(jsdom@22.1.0): resolution: {integrity: sha512-GoV0VQPmWrUFOZSg3RpQAPN+LPmHg2/gxlMNJlyxJihkz6qReHDV6b0pPDcqFLNEPya4tWJ1pgwUNP9MLmUfvQ==} engines: {node: '>=v14.18.0'} diff --git a/templates/phaser/packages/contracts/package.json b/templates/phaser/packages/contracts/package.json index c3d56ce47e..fc500fe7c6 100644 --- a/templates/phaser/packages/contracts/package.json +++ b/templates/phaser/packages/contracts/package.json @@ -20,7 +20,8 @@ "@latticexyz/cli": "link:../../../../packages/cli", "@latticexyz/schema-type": "link:../../../../packages/schema-type", "@latticexyz/store": "link:../../../../packages/store", - "@latticexyz/world": "link:../../../../packages/world" + "@latticexyz/world": "link:../../../../packages/world", + "@latticexyz/world-modules": "link:../../../../packages/world-modules" }, "devDependencies": { "@types/node": "^18.15.11", diff --git a/templates/phaser/packages/contracts/test/CounterTest.t.sol b/templates/phaser/packages/contracts/test/CounterTest.t.sol index adcb89b4e8..21b38dc8e5 100644 --- a/templates/phaser/packages/contracts/test/CounterTest.t.sol +++ b/templates/phaser/packages/contracts/test/CounterTest.t.sol @@ -3,7 +3,7 @@ pragma solidity >=0.8.21; import "forge-std/Test.sol"; import { MudTest } from "@latticexyz/world/test/MudTest.t.sol"; -import { getKeysWithValue } from "@latticexyz/world/src/modules/keyswithvalue/getKeysWithValue.sol"; +import { getKeysWithValue } from "@latticexyz/world-modules/src/modules/keyswithvalue/getKeysWithValue.sol"; import { IWorld } from "../src/codegen/world/IWorld.sol"; import { Counter, CounterTableId } from "../src/codegen/index.sol"; diff --git a/templates/react/packages/contracts/package.json b/templates/react/packages/contracts/package.json index c3d56ce47e..fc500fe7c6 100644 --- a/templates/react/packages/contracts/package.json +++ b/templates/react/packages/contracts/package.json @@ -20,7 +20,8 @@ "@latticexyz/cli": "link:../../../../packages/cli", "@latticexyz/schema-type": "link:../../../../packages/schema-type", "@latticexyz/store": "link:../../../../packages/store", - "@latticexyz/world": "link:../../../../packages/world" + "@latticexyz/world": "link:../../../../packages/world", + "@latticexyz/world-modules": "link:../../../../packages/world-modules" }, "devDependencies": { "@types/node": "^18.15.11", diff --git a/templates/react/packages/contracts/test/CounterTest.t.sol b/templates/react/packages/contracts/test/CounterTest.t.sol index adcb89b4e8..21b38dc8e5 100644 --- a/templates/react/packages/contracts/test/CounterTest.t.sol +++ b/templates/react/packages/contracts/test/CounterTest.t.sol @@ -3,7 +3,7 @@ pragma solidity >=0.8.21; import "forge-std/Test.sol"; import { MudTest } from "@latticexyz/world/test/MudTest.t.sol"; -import { getKeysWithValue } from "@latticexyz/world/src/modules/keyswithvalue/getKeysWithValue.sol"; +import { getKeysWithValue } from "@latticexyz/world-modules/src/modules/keyswithvalue/getKeysWithValue.sol"; import { IWorld } from "../src/codegen/world/IWorld.sol"; import { Counter, CounterTableId } from "../src/codegen/index.sol"; diff --git a/templates/vanilla/packages/contracts/package.json b/templates/vanilla/packages/contracts/package.json index c3d56ce47e..fc500fe7c6 100644 --- a/templates/vanilla/packages/contracts/package.json +++ b/templates/vanilla/packages/contracts/package.json @@ -20,7 +20,8 @@ "@latticexyz/cli": "link:../../../../packages/cli", "@latticexyz/schema-type": "link:../../../../packages/schema-type", "@latticexyz/store": "link:../../../../packages/store", - "@latticexyz/world": "link:../../../../packages/world" + "@latticexyz/world": "link:../../../../packages/world", + "@latticexyz/world-modules": "link:../../../../packages/world-modules" }, "devDependencies": { "@types/node": "^18.15.11", diff --git a/templates/vanilla/packages/contracts/test/CounterTest.t.sol b/templates/vanilla/packages/contracts/test/CounterTest.t.sol index adcb89b4e8..21b38dc8e5 100644 --- a/templates/vanilla/packages/contracts/test/CounterTest.t.sol +++ b/templates/vanilla/packages/contracts/test/CounterTest.t.sol @@ -3,7 +3,7 @@ pragma solidity >=0.8.21; import "forge-std/Test.sol"; import { MudTest } from "@latticexyz/world/test/MudTest.t.sol"; -import { getKeysWithValue } from "@latticexyz/world/src/modules/keyswithvalue/getKeysWithValue.sol"; +import { getKeysWithValue } from "@latticexyz/world-modules/src/modules/keyswithvalue/getKeysWithValue.sol"; import { IWorld } from "../src/codegen/world/IWorld.sol"; import { Counter, CounterTableId } from "../src/codegen/index.sol";