From 57d8965dfaa5275bd803a48c22d42b50b83c23ed Mon Sep 17 00:00:00 2001 From: dk1a Date: Tue, 16 Jan 2024 15:50:47 +0300 Subject: [PATCH] refactor(cli,world,world-modules): split and separately deploy core systems (#2128) Co-authored-by: alvarius Co-authored-by: Kevin Ingersoll --- .changeset/quiet-guests-approve.md | 5 + .changeset/silver-ligers-grin.md | 9 ++ packages/cli/src/deploy/ensureWorldFactory.ts | 79 +++++++++++- packages/world-modules/gas-report.json | 28 ++--- packages/world-modules/test/ERC20.t.sol | 4 +- packages/world-modules/test/ERC721.t.sol | 4 +- .../test/KeysInTableModule.t.sol | 4 +- .../test/KeysWithValueModule.t.sol | 4 +- .../world-modules/test/PuppetModule.t.sol | 4 +- .../test/StandardDelegationsModule.t.sol | 4 +- .../world-modules/test/SystemSwitch.t.sol | 4 +- .../test/UniqueEntityModule.t.sol | 4 +- packages/world-modules/test/query.t.sol | 4 +- packages/world/gas-report.json | 18 +-- .../src/codegen/interfaces/IBaseWorld.sol | 4 +- ...System.sol => ICoreRegistrationSystem.sol} | 4 +- .../world/src/modules/core/CoreModule.sol | 115 +++++++++++++----- ...eSystem.sol => CoreRegistrationSystem.sol} | 12 +- packages/world/src/modules/core/constants.sol | 32 ++++- .../StoreRegistrationSystem.sol | 2 +- packages/world/test/BatchCall.t.sol | 5 +- packages/world/test/CoreModule.t.sol | 4 +- packages/world/test/Factories.t.sol | 5 +- packages/world/test/Utils.t.sol | 4 +- packages/world/test/World.t.sol | 55 +++++---- packages/world/test/WorldBalance.t.sol | 4 +- packages/world/test/WorldDynamicUpdate.t.sol | 4 +- packages/world/test/createCoreModule.sol | 19 +++ 28 files changed, 314 insertions(+), 130 deletions(-) create mode 100644 .changeset/quiet-guests-approve.md create mode 100644 .changeset/silver-ligers-grin.md rename packages/world/src/codegen/interfaces/{ICoreSystem.sol => ICoreRegistrationSystem.sol} (76%) rename packages/world/src/modules/core/{CoreSystem.sol => CoreRegistrationSystem.sol} (55%) create mode 100644 packages/world/test/createCoreModule.sol diff --git a/.changeset/quiet-guests-approve.md b/.changeset/quiet-guests-approve.md new file mode 100644 index 0000000000..79b08e487c --- /dev/null +++ b/.changeset/quiet-guests-approve.md @@ -0,0 +1,5 @@ +--- +"@latticexyz/cli": major +--- + +Separated core systems deployment from `CoreModule`, and added the systems as arguments to `CoreModule` diff --git a/.changeset/silver-ligers-grin.md b/.changeset/silver-ligers-grin.md new file mode 100644 index 0000000000..7296243015 --- /dev/null +++ b/.changeset/silver-ligers-grin.md @@ -0,0 +1,9 @@ +--- +"@latticexyz/world": major +--- + +- Split `CoreSystem` into `AccessManagementSystem`, `BalanceTransferSystem`, `BatchCallSystem`, `CoreRegistrationSystem` +- Changed `CoreModule` to receive the addresses of these systems as arguments, instead of deploying them +- Replaced `CORE_SYSTEM_ID` constant with `ACCESS_MANAGEMENT_SYSTEM_ID`, `BALANCE_TRANSFER_SYSTEM_ID`, `BATCH_CALL_SYSTEM_ID`, `CORE_REGISTRATION_SYSTEM_ID`, for each respective system + +These changes separate the initcode of `CoreModule` from the bytecode of core systems, which effectively removes a limit on the total bytecode of all core systems. diff --git a/packages/cli/src/deploy/ensureWorldFactory.ts b/packages/cli/src/deploy/ensureWorldFactory.ts index 2f321260d2..edd2d84b2d 100644 --- a/packages/cli/src/deploy/ensureWorldFactory.ts +++ b/packages/cli/src/deploy/ensureWorldFactory.ts @@ -1,15 +1,68 @@ +import accessManagementSystemBuild from "@latticexyz/world/out/AccessManagementSystem.sol/AccessManagementSystem.json" assert { type: "json" }; +import balanceTransferSystemBuild from "@latticexyz/world/out/BalanceTransferSystem.sol/BalanceTransferSystem.json" assert { type: "json" }; +import batchCallSystemBuild from "@latticexyz/world/out/BatchCallSystem.sol/BatchCallSystem.json" assert { type: "json" }; +import coreRegistrationSystemBuild from "@latticexyz/world/out/CoreRegistrationSystem.sol/CoreRegistrationSystem.json" assert { type: "json" }; import coreModuleBuild from "@latticexyz/world/out/CoreModule.sol/CoreModule.json" assert { type: "json" }; +import coreModuleAbi from "@latticexyz/world/out/CoreModule.sol/CoreModule.abi.json" assert { type: "json" }; import worldFactoryBuild from "@latticexyz/world/out/WorldFactory.sol/WorldFactory.json" assert { type: "json" }; -import { Client, Transport, Chain, Account, Hex, parseAbi, getCreate2Address, encodeDeployData, size } from "viem"; +import worldFactoryAbi from "@latticexyz/world/out/WorldFactory.sol/WorldFactory.abi.json" assert { type: "json" }; +import { Client, Transport, Chain, Account, Hex, getCreate2Address, encodeDeployData, size } from "viem"; import { deployer } from "./ensureDeployer"; import { salt } from "./common"; import { ensureContractsDeployed } from "./ensureContractsDeployed"; import { Contract } from "./ensureContract"; +export const accessManagementSystemDeployedBytecodeSize = size( + accessManagementSystemBuild.deployedBytecode.object as Hex +); +export const accessManagementSystemBytecode = encodeDeployData({ + bytecode: accessManagementSystemBuild.bytecode.object as Hex, + abi: [], +}); +export const accessManagementSystem = getCreate2Address({ + from: deployer, + bytecode: accessManagementSystemBytecode, + salt, +}); + +export const balanceTransferSystemDeployedBytecodeSize = size( + balanceTransferSystemBuild.deployedBytecode.object as Hex +); +export const balanceTransferSystemBytecode = encodeDeployData({ + bytecode: balanceTransferSystemBuild.bytecode.object as Hex, + abi: [], +}); +export const balanceTransferSystem = getCreate2Address({ + from: deployer, + bytecode: balanceTransferSystemBytecode, + salt, +}); + +export const batchCallSystemDeployedBytecodeSize = size(batchCallSystemBuild.deployedBytecode.object as Hex); +export const batchCallSystemBytecode = encodeDeployData({ + bytecode: batchCallSystemBuild.bytecode.object as Hex, + abi: [], +}); +export const batchCallSystem = getCreate2Address({ from: deployer, bytecode: batchCallSystemBytecode, salt }); + +export const coreRegistrationSystemDeployedBytecodeSize = size( + coreRegistrationSystemBuild.deployedBytecode.object as Hex +); +export const coreRegistrationSystemBytecode = encodeDeployData({ + bytecode: coreRegistrationSystemBuild.bytecode.object as Hex, + abi: [], +}); +export const coreRegistrationSystem = getCreate2Address({ + from: deployer, + bytecode: coreRegistrationSystemBytecode, + salt, +}); + export const coreModuleDeployedBytecodeSize = size(coreModuleBuild.deployedBytecode.object as Hex); export const coreModuleBytecode = encodeDeployData({ bytecode: coreModuleBuild.bytecode.object as Hex, - abi: [], + abi: coreModuleAbi, + args: [accessManagementSystem, balanceTransferSystem, batchCallSystem, coreRegistrationSystem], }); export const coreModule = getCreate2Address({ from: deployer, bytecode: coreModuleBytecode, salt }); @@ -17,13 +70,33 @@ export const coreModule = getCreate2Address({ from: deployer, bytecode: coreModu export const worldFactoryDeployedBytecodeSize = size(worldFactoryBuild.deployedBytecode.object as Hex); export const worldFactoryBytecode = encodeDeployData({ bytecode: worldFactoryBuild.bytecode.object as Hex, - abi: parseAbi(["constructor(address)"]), + abi: worldFactoryAbi, args: [coreModule], }); export const worldFactory = getCreate2Address({ from: deployer, bytecode: worldFactoryBytecode, salt }); export const worldFactoryContracts: readonly Contract[] = [ + { + bytecode: accessManagementSystemBytecode, + deployedBytecodeSize: accessManagementSystemDeployedBytecodeSize, + label: "access management system", + }, + { + bytecode: balanceTransferSystemBytecode, + deployedBytecodeSize: balanceTransferSystemDeployedBytecodeSize, + label: "balance transfer system", + }, + { + bytecode: batchCallSystemBytecode, + deployedBytecodeSize: batchCallSystemDeployedBytecodeSize, + label: "batch call system", + }, + { + bytecode: coreRegistrationSystemBytecode, + deployedBytecodeSize: coreRegistrationSystemDeployedBytecodeSize, + label: "core registration system", + }, { bytecode: coreModuleBytecode, deployedBytecodeSize: coreModuleDeployedBytecodeSize, diff --git a/packages/world-modules/gas-report.json b/packages/world-modules/gas-report.json index 417529465d..24157d1541 100644 --- a/packages/world-modules/gas-report.json +++ b/packages/world-modules/gas-report.json @@ -75,13 +75,13 @@ "file": "test/KeysInTableModule.t.sol", "test": "testInstallComposite", "name": "install keys in table module", - "gasUsed": 1413360 + "gasUsed": 1419104 }, { "file": "test/KeysInTableModule.t.sol", "test": "testInstallGas", "name": "install keys in table module", - "gasUsed": 1413360 + "gasUsed": 1419104 }, { "file": "test/KeysInTableModule.t.sol", @@ -93,13 +93,13 @@ "file": "test/KeysInTableModule.t.sol", "test": "testInstallSingleton", "name": "install keys in table module", - "gasUsed": 1413360 + "gasUsed": 1419104 }, { "file": "test/KeysInTableModule.t.sol", "test": "testSetAndDeleteRecordHookCompositeGas", "name": "install keys in table module", - "gasUsed": 1413360 + "gasUsed": 1419104 }, { "file": "test/KeysInTableModule.t.sol", @@ -117,7 +117,7 @@ "file": "test/KeysInTableModule.t.sol", "test": "testSetAndDeleteRecordHookGas", "name": "install keys in table module", - "gasUsed": 1413360 + "gasUsed": 1419104 }, { "file": "test/KeysInTableModule.t.sol", @@ -135,7 +135,7 @@ "file": "test/KeysWithValueModule.t.sol", "test": "testGetKeysWithValueGas", "name": "install keys with value module", - "gasUsed": 668171 + "gasUsed": 674298 }, { "file": "test/KeysWithValueModule.t.sol", @@ -153,7 +153,7 @@ "file": "test/KeysWithValueModule.t.sol", "test": "testInstall", "name": "install keys with value module", - "gasUsed": 668171 + "gasUsed": 674298 }, { "file": "test/KeysWithValueModule.t.sol", @@ -165,7 +165,7 @@ "file": "test/KeysWithValueModule.t.sol", "test": "testSetAndDeleteRecordHook", "name": "install keys with value module", - "gasUsed": 668171 + "gasUsed": 674298 }, { "file": "test/KeysWithValueModule.t.sol", @@ -183,7 +183,7 @@ "file": "test/KeysWithValueModule.t.sol", "test": "testSetField", "name": "install keys with value module", - "gasUsed": 668171 + "gasUsed": 674298 }, { "file": "test/KeysWithValueModule.t.sol", @@ -267,7 +267,7 @@ "file": "test/StandardDelegationsModule.t.sol", "test": "testCallFromCallboundDelegation", "name": "register a callbound delegation", - "gasUsed": 118347 + "gasUsed": 118172 }, { "file": "test/StandardDelegationsModule.t.sol", @@ -279,7 +279,7 @@ "file": "test/StandardDelegationsModule.t.sol", "test": "testCallFromSystemDelegation", "name": "register a systembound delegation", - "gasUsed": 115900 + "gasUsed": 115725 }, { "file": "test/StandardDelegationsModule.t.sol", @@ -291,7 +291,7 @@ "file": "test/StandardDelegationsModule.t.sol", "test": "testCallFromTimeboundDelegation", "name": "register a timebound delegation", - "gasUsed": 112823 + "gasUsed": 112648 }, { "file": "test/StandardDelegationsModule.t.sol", @@ -303,7 +303,7 @@ "file": "test/UniqueEntityModule.t.sol", "test": "testInstall", "name": "install unique entity module", - "gasUsed": 694879 + "gasUsed": 694710 }, { "file": "test/UniqueEntityModule.t.sol", @@ -315,7 +315,7 @@ "file": "test/UniqueEntityModule.t.sol", "test": "testInstallRoot", "name": "installRoot unique entity module", - "gasUsed": 663830 + "gasUsed": 663729 }, { "file": "test/UniqueEntityModule.t.sol", diff --git a/packages/world-modules/test/ERC20.t.sol b/packages/world-modules/test/ERC20.t.sol index 9416e8aacd..e720751ce7 100644 --- a/packages/world-modules/test/ERC20.t.sol +++ b/packages/world-modules/test/ERC20.t.sol @@ -8,7 +8,7 @@ import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; import { World } from "@latticexyz/world/src/World.sol"; import { WorldResourceIdLib } from "@latticexyz/world/src/WorldResourceId.sol"; -import { CoreModule } from "@latticexyz/world/src/modules/core/CoreModule.sol"; +import { createCoreModule } from "@latticexyz/world/test/createCoreModule.sol"; import { IBaseWorld } from "@latticexyz/world/src/codegen/interfaces/IBaseWorld.sol"; import { NamespaceOwner } from "@latticexyz/world/src/codegen/tables/NamespaceOwner.sol"; import { GasReporter } from "@latticexyz/gas-report/src/GasReporter.sol"; @@ -31,7 +31,7 @@ contract ERC20Test is Test, GasReporter, IERC20Events, IERC20Errors { function setUp() public { world = IBaseWorld(address(new World())); - world.initialize(new CoreModule()); + world.initialize(createCoreModule()); world.installModule(new PuppetModule(), new bytes(0)); StoreSwitch.setStoreAddress(address(world)); diff --git a/packages/world-modules/test/ERC721.t.sol b/packages/world-modules/test/ERC721.t.sol index 81f696659b..b9793f40ff 100644 --- a/packages/world-modules/test/ERC721.t.sol +++ b/packages/world-modules/test/ERC721.t.sol @@ -8,7 +8,7 @@ import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; import { World } from "@latticexyz/world/src/World.sol"; import { WorldResourceIdLib, WorldResourceIdInstance } from "@latticexyz/world/src/WorldResourceId.sol"; -import { CoreModule } from "@latticexyz/world/src/modules/core/CoreModule.sol"; +import { createCoreModule } from "@latticexyz/world/test/createCoreModule.sol"; import { IBaseWorld } from "@latticexyz/world/src/codegen/interfaces/IBaseWorld.sol"; import { NamespaceOwner } from "@latticexyz/world/src/codegen/tables/NamespaceOwner.sol"; import { IWorldErrors } from "@latticexyz/world/src/IWorldErrors.sol"; @@ -73,7 +73,7 @@ contract ERC721Test is Test, GasReporter, IERC721Events, IERC721Errors { function setUp() public { world = IBaseWorld(address(new World())); - world.initialize(new CoreModule()); + world.initialize(createCoreModule()); world.installModule(new PuppetModule(), new bytes(0)); StoreSwitch.setStoreAddress(address(world)); diff --git a/packages/world-modules/test/KeysInTableModule.t.sol b/packages/world-modules/test/KeysInTableModule.t.sol index 1393b78e23..797cb8079d 100644 --- a/packages/world-modules/test/KeysInTableModule.t.sol +++ b/packages/world-modules/test/KeysInTableModule.t.sol @@ -18,7 +18,7 @@ import { ResourceId, WorldResourceIdLib, WorldResourceIdInstance } from "@lattic import { ROOT_NAMESPACE } from "@latticexyz/world/src/constants.sol"; import { RESOURCE_TABLE } from "@latticexyz/world/src/worldResourceTypes.sol"; -import { CoreModule } from "@latticexyz/world/src/modules/core/CoreModule.sol"; +import { createCoreModule } from "@latticexyz/world/test/createCoreModule.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"; @@ -63,7 +63,7 @@ contract KeysInTableModuleTest is Test, GasReporter { singletonKeySchema = SchemaLib.encode(new SchemaType[](0)); world = IBaseWorld(address(new World())); - world.initialize(new CoreModule()); + world.initialize(createCoreModule()); keyTuple1 = new bytes32[](1); keyTuple1[0] = key1; keyTuple2 = new bytes32[](1); diff --git a/packages/world-modules/test/KeysWithValueModule.t.sol b/packages/world-modules/test/KeysWithValueModule.t.sol index d50a70326f..1f43c39911 100644 --- a/packages/world-modules/test/KeysWithValueModule.t.sol +++ b/packages/world-modules/test/KeysWithValueModule.t.sol @@ -21,7 +21,7 @@ import { WorldResourceIdLib, WorldResourceIdInstance, NAME_BITS, TYPE_BITS } fro import { ROOT_NAMESPACE } from "@latticexyz/world/src/constants.sol"; import { RESOURCE_TABLE } from "@latticexyz/world/src/worldResourceTypes.sol"; -import { CoreModule } from "@latticexyz/world/src/modules/core/CoreModule.sol"; +import { createCoreModule } from "@latticexyz/world/test/createCoreModule.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"; @@ -56,7 +56,7 @@ contract KeysWithValueModuleTest is Test, GasReporter { targetTableId = getTargetTableId(MODULE_NAMESPACE, sourceTableId); world = IBaseWorld(address(new World())); - world.initialize(new CoreModule()); + world.initialize(createCoreModule()); StoreSwitch.setStoreAddress(address(world)); keyTuple1 = new bytes32[](1); diff --git a/packages/world-modules/test/PuppetModule.t.sol b/packages/world-modules/test/PuppetModule.t.sol index 5025d49866..6a7383ab3e 100644 --- a/packages/world-modules/test/PuppetModule.t.sol +++ b/packages/world-modules/test/PuppetModule.t.sol @@ -13,7 +13,7 @@ import { IBaseWorld } from "@latticexyz/world/src/codegen/interfaces/IBaseWorld. import { IWorldErrors } from "@latticexyz/world/src/IWorldErrors.sol"; import { DELEGATION_CONTROL_INTERFACE_ID } from "@latticexyz/world/src/IDelegationControl.sol"; -import { CoreModule } from "@latticexyz/world/src/modules/core/CoreModule.sol"; +import { createCoreModule } from "@latticexyz/world/test/createCoreModule.sol"; import { Systems } from "@latticexyz/world/src/codegen/tables/Systems.sol"; import { PuppetModule } from "../src/modules/puppet/PuppetModule.sol"; @@ -48,7 +48,7 @@ contract PuppetModuleTest is Test, GasReporter { function setUp() public { world = IBaseWorld(address(new World())); - world.initialize(new CoreModule()); + world.initialize(createCoreModule()); } function _setupPuppet() internal { diff --git a/packages/world-modules/test/StandardDelegationsModule.t.sol b/packages/world-modules/test/StandardDelegationsModule.t.sol index adfc7d613e..8422838268 100644 --- a/packages/world-modules/test/StandardDelegationsModule.t.sol +++ b/packages/world-modules/test/StandardDelegationsModule.t.sol @@ -13,7 +13,7 @@ import { IBaseWorld } from "@latticexyz/world/src/codegen/interfaces/IBaseWorld. import { IWorldErrors } from "@latticexyz/world/src/IWorldErrors.sol"; import { DELEGATION_CONTROL_INTERFACE_ID } from "@latticexyz/world/src/IDelegationControl.sol"; -import { CoreModule } from "@latticexyz/world/src/modules/core/CoreModule.sol"; +import { createCoreModule } from "@latticexyz/world/test/createCoreModule.sol"; import { Systems } from "@latticexyz/world/src/codegen/tables/Systems.sol"; import { StandardDelegationsModule } from "../src/modules/std-delegations/StandardDelegationsModule.sol"; @@ -34,7 +34,7 @@ contract StandardDelegationsModuleTest is Test, GasReporter { function setUp() public { world = IBaseWorld(address(new World())); - world.initialize(new CoreModule()); + world.initialize(createCoreModule()); world.installRootModule(new StandardDelegationsModule(), new bytes(0)); // Register a new system diff --git a/packages/world-modules/test/SystemSwitch.t.sol b/packages/world-modules/test/SystemSwitch.t.sol index 6f8cf04f76..cbc3663ed3 100644 --- a/packages/world-modules/test/SystemSwitch.t.sol +++ b/packages/world-modules/test/SystemSwitch.t.sol @@ -7,7 +7,7 @@ import { GasReporter } from "@latticexyz/gas-report/src/GasReporter.sol"; import { System } from "@latticexyz/world/src/System.sol"; import { IBaseWorld } from "@latticexyz/world/src/codegen/interfaces/IBaseWorld.sol"; import { World } from "@latticexyz/world/src/World.sol"; -import { CoreModule } from "@latticexyz/world/src/modules/core/CoreModule.sol"; +import { createCoreModule } from "@latticexyz/world/test/createCoreModule.sol"; import { ResourceId, WorldResourceIdLib, WorldResourceIdInstance } from "@latticexyz/world/src/WorldResourceId.sol"; import { RESOURCE_SYSTEM } from "@latticexyz/world/src/worldResourceTypes.sol"; import { ROOT_NAMESPACE } from "@latticexyz/world/src/constants.sol"; @@ -55,7 +55,7 @@ contract SystemSwitchTest is Test, GasReporter { function setUp() public { // Deploy world World _world = new World(); - _world.initialize(new CoreModule()); + _world.initialize(createCoreModule()); world = IBaseWorld(address(_world)); // Deploy systems diff --git a/packages/world-modules/test/UniqueEntityModule.t.sol b/packages/world-modules/test/UniqueEntityModule.t.sol index 9808e28743..77dd9e2ed6 100644 --- a/packages/world-modules/test/UniqueEntityModule.t.sol +++ b/packages/world-modules/test/UniqueEntityModule.t.sol @@ -12,7 +12,7 @@ import { IWorldErrors } from "@latticexyz/world/src/IWorldErrors.sol"; import { System } from "@latticexyz/world/src/System.sol"; import { RESOURCE_SYSTEM } from "@latticexyz/world/src/worldResourceTypes.sol"; -import { CoreModule } from "@latticexyz/world/src/modules/core/CoreModule.sol"; +import { createCoreModule } from "@latticexyz/world/test/createCoreModule.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"; @@ -37,7 +37,7 @@ contract UniqueEntityModuleTest is Test, GasReporter { function setUp() public { world = IBaseWorld(address(new World())); - world.initialize(new CoreModule()); + world.initialize(createCoreModule()); StoreSwitch.setStoreAddress(address(world)); } diff --git a/packages/world-modules/test/query.t.sol b/packages/world-modules/test/query.t.sol index f5b62e14f1..5703da7c61 100644 --- a/packages/world-modules/test/query.t.sol +++ b/packages/world-modules/test/query.t.sol @@ -17,7 +17,7 @@ import { ResourceId, WorldResourceIdLib, WorldResourceIdInstance } from "@lattic import { ROOT_NAMESPACE } from "@latticexyz/world/src/constants.sol"; import { RESOURCE_TABLE } from "@latticexyz/world/src/worldResourceTypes.sol"; -import { CoreModule } from "@latticexyz/world/src/modules/core/CoreModule.sol"; +import { createCoreModule } from "@latticexyz/world/test/createCoreModule.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"; @@ -53,7 +53,7 @@ contract QueryTest is Test, GasReporter { tableKeySchema = SchemaEncodeHelper.encode(SchemaType.BYTES32); tableValueSchema = SchemaEncodeHelper.encode(SchemaType.UINT256); world = IBaseWorld(address(new World())); - world.initialize(new CoreModule()); + world.initialize(createCoreModule()); key1[0] = "test1"; key2[0] = "test2"; diff --git a/packages/world/gas-report.json b/packages/world/gas-report.json index c679ce966c..93aa67a001 100644 --- a/packages/world/gas-report.json +++ b/packages/world/gas-report.json @@ -45,13 +45,13 @@ "file": "test/BatchCall.t.sol", "test": "testBatchCallFromReturnData", "name": "call systems with batchCallFrom", - "gasUsed": 46444 + "gasUsed": 52561 }, { "file": "test/BatchCall.t.sol", "test": "testBatchCallReturnData", "name": "call systems with batchCall", - "gasUsed": 45206 + "gasUsed": 51407 }, { "file": "test/Factories.t.sol", @@ -63,7 +63,7 @@ "file": "test/Factories.t.sol", "test": "testWorldFactory", "name": "deploy world via WorldFactory", - "gasUsed": 11933749 + "gasUsed": 12321908 }, { "file": "test/World.t.sol", @@ -81,7 +81,7 @@ "file": "test/World.t.sol", "test": "testCallFromUnlimitedDelegation", "name": "register an unlimited delegation", - "gasUsed": 47651 + "gasUsed": 47552 }, { "file": "test/World.t.sol", @@ -105,31 +105,31 @@ "file": "test/World.t.sol", "test": "testRegisterFunctionSelector", "name": "Register a function selector", - "gasUsed": 83156 + "gasUsed": 83123 }, { "file": "test/World.t.sol", "test": "testRegisterNamespace", "name": "Register a new namespace", - "gasUsed": 120962 + "gasUsed": 120895 }, { "file": "test/World.t.sol", "test": "testRegisterRootFunctionSelector", "name": "Register a root function selector", - "gasUsed": 80457 + "gasUsed": 80424 }, { "file": "test/World.t.sol", "test": "testRegisterSystem", "name": "register a system", - "gasUsed": 164349 + "gasUsed": 164348 }, { "file": "test/World.t.sol", "test": "testRegisterTable", "name": "Register a new table in the namespace", - "gasUsed": 528384 + "gasUsed": 528266 }, { "file": "test/World.t.sol", diff --git a/packages/world/src/codegen/interfaces/IBaseWorld.sol b/packages/world/src/codegen/interfaces/IBaseWorld.sol index 473db3a675..b770d4b6a1 100644 --- a/packages/world/src/codegen/interfaces/IBaseWorld.sol +++ b/packages/world/src/codegen/interfaces/IBaseWorld.sol @@ -6,7 +6,7 @@ pragma solidity >=0.8.21; import { IStore } from "@latticexyz/store/src/IStore.sol"; import { IWorldKernel } from "../../IWorldKernel.sol"; -import { ICoreSystem } from "./ICoreSystem.sol"; +import { ICoreRegistrationSystem } from "./ICoreRegistrationSystem.sol"; import { IAccessManagementSystem } from "./IAccessManagementSystem.sol"; import { IBalanceTransferSystem } from "./IBalanceTransferSystem.sol"; import { IBatchCallSystem } from "./IBatchCallSystem.sol"; @@ -22,7 +22,7 @@ import { IWorldRegistrationSystem } from "./IWorldRegistrationSystem.sol"; interface IBaseWorld is IStore, IWorldKernel, - ICoreSystem, + ICoreRegistrationSystem, IAccessManagementSystem, IBalanceTransferSystem, IBatchCallSystem, diff --git a/packages/world/src/codegen/interfaces/ICoreSystem.sol b/packages/world/src/codegen/interfaces/ICoreRegistrationSystem.sol similarity index 76% rename from packages/world/src/codegen/interfaces/ICoreSystem.sol rename to packages/world/src/codegen/interfaces/ICoreRegistrationSystem.sol index 448f0fa54c..83ab3319ee 100644 --- a/packages/world/src/codegen/interfaces/ICoreSystem.sol +++ b/packages/world/src/codegen/interfaces/ICoreRegistrationSystem.sol @@ -4,9 +4,9 @@ pragma solidity >=0.8.21; /* Autogenerated file. Do not edit manually. */ /** - * @title ICoreSystem + * @title ICoreRegistrationSystem * @dev This interface is automatically generated from the corresponding system contract. Do not edit manually. */ -interface ICoreSystem { +interface ICoreRegistrationSystem { } diff --git a/packages/world/src/modules/core/CoreModule.sol b/packages/world/src/modules/core/CoreModule.sol index 405312f30a..632a87a1b7 100644 --- a/packages/world/src/modules/core/CoreModule.sol +++ b/packages/world/src/modules/core/CoreModule.sol @@ -1,11 +1,12 @@ // SPDX-License-Identifier: MIT pragma solidity >=0.8.21; -import { WorldContextProviderLib } from "../../WorldContext.sol"; +import { WorldContextProviderLib, WorldContextConsumer } from "../../WorldContext.sol"; import { ROOT_NAMESPACE_ID, STORE_NAMESPACE_ID, WORLD_NAMESPACE_ID } from "../../constants.sol"; import { Module } from "../../Module.sol"; import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; +import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; import { ResourceIds } from "@latticexyz/store/src/codegen/tables/ResourceIds.sol"; import { NamespaceOwner } from "../../codegen/tables/NamespaceOwner.sol"; @@ -14,8 +15,12 @@ import { InstalledModules } from "../../codegen/tables/InstalledModules.sol"; import { UserDelegationControl } from "../../codegen/tables/UserDelegationControl.sol"; import { NamespaceDelegationControl } from "../../codegen/tables/NamespaceDelegationControl.sol"; -import { CoreSystem } from "./CoreSystem.sol"; -import { CORE_MODULE_NAME, CORE_SYSTEM_ID } from "./constants.sol"; +import { AccessManagementSystem } from "./implementations/AccessManagementSystem.sol"; +import { BalanceTransferSystem } from "./implementations/BalanceTransferSystem.sol"; +import { BatchCallSystem } from "./implementations/BatchCallSystem.sol"; + +import { CoreRegistrationSystem } from "./CoreRegistrationSystem.sol"; +import { CORE_MODULE_NAME, ACCESS_MANAGEMENT_SYSTEM_ID, BALANCE_TRANSFER_SYSTEM_ID, BATCH_CALL_SYSTEM_ID, CORE_REGISTRATION_SYSTEM_ID } from "./constants.sol"; import { Systems } from "../../codegen/tables/Systems.sol"; import { FunctionSelectors } from "../../codegen/tables/FunctionSelectors.sol"; @@ -28,16 +33,27 @@ import { WorldRegistrationSystem } from "./implementations/WorldRegistrationSyst /** * @title Core Module - * @notice Registers internal World tables, the CoreSystem, and its function selectors. + * @notice Registers internal World tables, systems, and their function selectors. * @dev This module only supports `installRoot` because it installs root tables, systems and function selectors. */ contract CoreModule is Module { - /** - * @dev Since the CoreSystem only exists once per World and writes to - * known tables, we can deploy it once and register it in multiple Worlds. - */ - address internal immutable coreSystem = address(new CoreSystem()); + address internal immutable accessManagementSystem; + address internal immutable balanceTransferSystem; + address internal immutable batchCallSystem; + address internal immutable coreRegistrationSystem; + + constructor( + AccessManagementSystem _accessManagementSystem, + BalanceTransferSystem _balanceTransferSystem, + BatchCallSystem _batchCallSystem, + CoreRegistrationSystem _coreRegistrationSystem + ) { + accessManagementSystem = address(_accessManagementSystem); + balanceTransferSystem = address(_balanceTransferSystem); + batchCallSystem = address(_batchCallSystem); + coreRegistrationSystem = address(_coreRegistrationSystem); + } /** * @notice Get the name of the module. @@ -53,7 +69,7 @@ contract CoreModule is Module { */ function installRoot(bytes memory) public override { _registerCoreTables(); - _registerCoreSystem(); + _registerCoreSystems(); _registerFunctionSelectors(); } @@ -97,34 +113,62 @@ contract CoreModule is Module { } /** - * @notice Register the CoreSystem in the World. - * @dev Uses the CoreSystem's `registerSystem` implementation to register itself on the World. + * @notice Register the core systems in the World. */ - function _registerCoreSystem() internal { + function _registerCoreSystems() internal { + _registerSystem(accessManagementSystem, ACCESS_MANAGEMENT_SYSTEM_ID); + _registerSystem(balanceTransferSystem, BALANCE_TRANSFER_SYSTEM_ID); + _registerSystem(batchCallSystem, BATCH_CALL_SYSTEM_ID); + _registerSystem(coreRegistrationSystem, CORE_REGISTRATION_SYSTEM_ID); + } + + /** + * @notice Register the core system in the World. + * @dev Uses the CoreRegistrationSystem's `registerSystem` implementation to register the system on the World. + */ + function _registerSystem(address target, ResourceId systemId) internal { WorldContextProviderLib.delegatecallWithContextOrRevert({ msgSender: _msgSender(), msgValue: 0, - target: coreSystem, - callData: abi.encodeCall(WorldRegistrationSystem.registerSystem, (CORE_SYSTEM_ID, CoreSystem(coreSystem), true)) + target: coreRegistrationSystem, + callData: abi.encodeCall(WorldRegistrationSystem.registerSystem, (systemId, WorldContextConsumer(target), true)) }); } /** - * @notice Register function selectors for all CoreSystem functions in the World. + * @notice Register function selectors for all core system functions in the World. * @dev Iterates through known function signatures and registers them. */ function _registerFunctionSelectors() internal { - string[19] memory functionSignatures = [ + string[3] memory functionSignaturesAccessManagement = [ // --- AccessManagementSystem --- "grantAccess(bytes32,address)", "revokeAccess(bytes32,address)", - "transferOwnership(bytes32,address)", + "transferOwnership(bytes32,address)" + ]; + for (uint256 i = 0; i < functionSignaturesAccessManagement.length; i++) { + _registerRootFunctionSelector(ACCESS_MANAGEMENT_SYSTEM_ID, functionSignaturesAccessManagement[i]); + } + + string[2] memory functionSignaturesBalanceTransfer = [ // --- BalanceTransferSystem --- "transferBalanceToNamespace(bytes32,bytes32,uint256)", - "transferBalanceToAddress(bytes32,address,uint256)", + "transferBalanceToAddress(bytes32,address,uint256)" + ]; + for (uint256 i = 0; i < functionSignaturesBalanceTransfer.length; i++) { + _registerRootFunctionSelector(BALANCE_TRANSFER_SYSTEM_ID, functionSignaturesBalanceTransfer[i]); + } + + string[2] memory functionSignaturesBatchCall = [ // --- BatchCallSystem --- "batchCall((bytes32,bytes)[])", - "batchCallFrom((address,bytes32,bytes)[])", + "batchCallFrom((address,bytes32,bytes)[])" + ]; + for (uint256 i = 0; i < functionSignaturesBatchCall.length; i++) { + _registerRootFunctionSelector(BATCH_CALL_SYSTEM_ID, functionSignaturesBatchCall[i]); + } + + string[12] memory functionSignaturesCoreRegistration = [ // --- ModuleInstallationSystem --- "installModule(address,bytes)", // --- StoreRegistrationSystem --- @@ -141,19 +185,24 @@ contract CoreModule is Module { "registerDelegation(address,bytes32,bytes)", "registerNamespaceDelegation(bytes32,bytes32,bytes)" ]; - - for (uint256 i = 0; i < functionSignatures.length; i++) { - // Use the CoreSystem's `registerRootFunctionSelector` to register the - // root function selectors in the World. - WorldContextProviderLib.delegatecallWithContextOrRevert({ - msgSender: _msgSender(), - msgValue: 0, - target: coreSystem, - callData: abi.encodeCall( - WorldRegistrationSystem.registerRootFunctionSelector, - (CORE_SYSTEM_ID, functionSignatures[i], bytes4(keccak256(bytes(functionSignatures[i])))) - ) - }); + for (uint256 i = 0; i < functionSignaturesCoreRegistration.length; i++) { + _registerRootFunctionSelector(CORE_REGISTRATION_SYSTEM_ID, functionSignaturesCoreRegistration[i]); } } + + /** + * @notice Register the function selector in the World. + * @dev Uses the CoreRegistrationSystem's `registerRootFunctionSelector` to register the function selector. + */ + function _registerRootFunctionSelector(ResourceId systemId, string memory functionSignature) internal { + WorldContextProviderLib.delegatecallWithContextOrRevert({ + msgSender: _msgSender(), + msgValue: 0, + target: coreRegistrationSystem, + callData: abi.encodeCall( + WorldRegistrationSystem.registerRootFunctionSelector, + (systemId, functionSignature, bytes4(keccak256(bytes(functionSignature)))) + ) + }); + } } diff --git a/packages/world/src/modules/core/CoreSystem.sol b/packages/world/src/modules/core/CoreRegistrationSystem.sol similarity index 55% rename from packages/world/src/modules/core/CoreSystem.sol rename to packages/world/src/modules/core/CoreRegistrationSystem.sol index e1be0ae7d2..a53a697dbe 100644 --- a/packages/world/src/modules/core/CoreSystem.sol +++ b/packages/world/src/modules/core/CoreRegistrationSystem.sol @@ -3,23 +3,17 @@ pragma solidity >=0.8.21; import { IWorldErrors } from "../../IWorldErrors.sol"; -import { AccessManagementSystem } from "./implementations/AccessManagementSystem.sol"; -import { BalanceTransferSystem } from "./implementations/BalanceTransferSystem.sol"; -import { BatchCallSystem } from "./implementations/BatchCallSystem.sol"; import { ModuleInstallationSystem } from "./implementations/ModuleInstallationSystem.sol"; import { StoreRegistrationSystem } from "./implementations/StoreRegistrationSystem.sol"; import { WorldRegistrationSystem } from "./implementations/WorldRegistrationSystem.sol"; /** - * @title Core System for World - * @notice This system aggregates all World functionalities externalized from the World contract, aiming to keep the World contract's bytecode lean. + * @title Core Registration System for World + * @notice This system aggregates World registration and installation functionalities externalized from the World contract, aiming to keep the World contract's bytecode lean. * @dev Aggregates multiple system implementations for the World. */ -contract CoreSystem is +contract CoreRegistrationSystem is IWorldErrors, - AccessManagementSystem, - BalanceTransferSystem, - BatchCallSystem, ModuleInstallationSystem, StoreRegistrationSystem, WorldRegistrationSystem diff --git a/packages/world/src/modules/core/constants.sol b/packages/world/src/modules/core/constants.sol index 2673e1ae76..1be6c2f1d3 100644 --- a/packages/world/src/modules/core/constants.sol +++ b/packages/world/src/modules/core/constants.sol @@ -13,9 +13,33 @@ import { RESOURCE_SYSTEM } from "../../worldResourceTypes.sol"; bytes16 constant CORE_MODULE_NAME = bytes16("core"); /** - * @dev Resource ID for the core system. - * @dev This ID is derived from the RESOURCE_SYSTEM type, the ROOT_NAMESPACE, and the CORE_MODULE_NAME. + * @dev Resource ID for access management system. + * @dev This ID is derived from the RESOURCE_SYSTEM type, the ROOT_NAMESPACE, and the system name. */ -ResourceId constant CORE_SYSTEM_ID = ResourceId.wrap( - bytes32(abi.encodePacked(RESOURCE_SYSTEM, ROOT_NAMESPACE, CORE_MODULE_NAME)) +ResourceId constant ACCESS_MANAGEMENT_SYSTEM_ID = ResourceId.wrap( + bytes32(abi.encodePacked(RESOURCE_SYSTEM, ROOT_NAMESPACE, bytes16("AccessManagement"))) +); + +/** + * @dev Resource ID for balance transfer system. + * @dev This ID is derived from the RESOURCE_SYSTEM type, the ROOT_NAMESPACE, and the system name. + */ +ResourceId constant BALANCE_TRANSFER_SYSTEM_ID = ResourceId.wrap( + bytes32(abi.encodePacked(RESOURCE_SYSTEM, ROOT_NAMESPACE, bytes16("BalanceTransfer"))) +); + +/** + * @dev Resource ID for batch call system. + * @dev This ID is derived from the RESOURCE_SYSTEM type, the ROOT_NAMESPACE, and the system name. + */ +ResourceId constant BATCH_CALL_SYSTEM_ID = ResourceId.wrap( + bytes32(abi.encodePacked(RESOURCE_SYSTEM, ROOT_NAMESPACE, bytes16("BatchCall"))) +); + +/** + * @dev Resource ID for core registration system. + * @dev This ID is derived from the RESOURCE_SYSTEM type, the ROOT_NAMESPACE, and the system name. + */ +ResourceId constant CORE_REGISTRATION_SYSTEM_ID = ResourceId.wrap( + bytes32(abi.encodePacked(RESOURCE_SYSTEM, ROOT_NAMESPACE, bytes16("CoreRegistration"))) ); diff --git a/packages/world/src/modules/core/implementations/StoreRegistrationSystem.sol b/packages/world/src/modules/core/implementations/StoreRegistrationSystem.sol index c380ce0cdd..379850d5e9 100644 --- a/packages/world/src/modules/core/implementations/StoreRegistrationSystem.sol +++ b/packages/world/src/modules/core/implementations/StoreRegistrationSystem.sol @@ -15,7 +15,7 @@ import { revertWithBytes } from "../../../revertWithBytes.sol"; import { IWorldErrors } from "../../../IWorldErrors.sol"; -import { CORE_SYSTEM_ID } from "../constants.sol"; +import { CORE_REGISTRATION_SYSTEM_ID } from "../constants.sol"; import { WorldRegistrationSystem } from "./WorldRegistrationSystem.sol"; diff --git a/packages/world/test/BatchCall.t.sol b/packages/world/test/BatchCall.t.sol index e90b461f9f..0dcee4db9f 100644 --- a/packages/world/test/BatchCall.t.sol +++ b/packages/world/test/BatchCall.t.sol @@ -13,9 +13,10 @@ import { RESOURCE_SYSTEM } from "../src/worldResourceTypes.sol"; import { IWorldErrors } from "../src/IWorldErrors.sol"; import { IBaseWorld } from "../src/codegen/interfaces/IBaseWorld.sol"; -import { CoreModule } from "../src/modules/core/CoreModule.sol"; import { SystemCallData, SystemCallFromData } from "../src/modules/core/types.sol"; +import { createCoreModule } from "./createCoreModule.sol"; + address constant caller = address(1); address constant delegator = address(2); address constant delegatee = address(3); @@ -57,7 +58,7 @@ contract BatchCallTest is Test, GasReporter { function setUp() public { world = IBaseWorld(address(new World())); - world.initialize(new CoreModule()); + world.initialize(createCoreModule()); world.registerNamespace(systemId.getNamespaceId()); } diff --git a/packages/world/test/CoreModule.t.sol b/packages/world/test/CoreModule.t.sol index 384c24f2ed..be2aa929fc 100644 --- a/packages/world/test/CoreModule.t.sol +++ b/packages/world/test/CoreModule.t.sol @@ -11,6 +11,8 @@ import { WorldContextProviderLib } from "../src/WorldContext.sol"; import { CoreModule } from "../src/modules/core/CoreModule.sol"; import { ResourceId, WorldResourceIdInstance } from "../src/WorldResourceId.sol"; +import { createCoreModule } from "./createCoreModule.sol"; + contract WorldMock is StoreRead { constructor() { StoreSwitch.setStoreAddress(address(this)); @@ -31,7 +33,7 @@ contract CoreModuleTest is Test { WorldMock worldMock; function setUp() public { - coreModule = new CoreModule(); + coreModule = createCoreModule(); worldMock = new WorldMock(); StoreSwitch.setStoreAddress(address(worldMock)); } diff --git a/packages/world/test/Factories.t.sol b/packages/world/test/Factories.t.sol index a7fde9ba4e..b67de2b1ac 100644 --- a/packages/world/test/Factories.t.sol +++ b/packages/world/test/Factories.t.sol @@ -16,6 +16,7 @@ import { IWorldFactory } from "../src/IWorldFactory.sol"; import { InstalledModules } from "../src/codegen/tables/InstalledModules.sol"; import { NamespaceOwner } from "../src/codegen/tables/NamespaceOwner.sol"; import { ROOT_NAMESPACE_ID } from "../src/constants.sol"; +import { createCoreModule } from "./createCoreModule.sol"; contract FactoriesTest is Test, GasReporter { event ContractDeployed(address addr, uint256 salt); @@ -36,7 +37,7 @@ contract FactoriesTest is Test, GasReporter { Create2Factory create2Factory = new Create2Factory(); // Encode constructor arguments for WorldFactory - bytes memory encodedArguments = abi.encode(new CoreModule()); + bytes memory encodedArguments = abi.encode(createCoreModule()); bytes memory combinedBytes = abi.encodePacked(type(WorldFactory).creationCode, encodedArguments); // Address we expect for deployed WorldFactory @@ -56,7 +57,7 @@ contract FactoriesTest is Test, GasReporter { function testWorldFactory() public { // Deploy WorldFactory with current CoreModule - CoreModule coreModule = new CoreModule(); + CoreModule coreModule = createCoreModule(); address worldFactoryAddress = address(new WorldFactory(coreModule)); IWorldFactory worldFactory = IWorldFactory(worldFactoryAddress); diff --git a/packages/world/test/Utils.t.sol b/packages/world/test/Utils.t.sol index b2660f5210..6800510f6c 100644 --- a/packages/world/test/Utils.t.sol +++ b/packages/world/test/Utils.t.sol @@ -12,7 +12,7 @@ import { RESOURCE_SYSTEM } from "../src/worldResourceTypes.sol"; import { ResourceIds } from "@latticexyz/store/src/codegen/tables/ResourceIds.sol"; import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; -import { CoreModule } from "../src/modules/core/CoreModule.sol"; +import { createCoreModule } from "./createCoreModule.sol"; contract UtilsTestSystem is System { function systemNamespace() public view returns (bytes16) { @@ -28,7 +28,7 @@ contract UtilsTest is Test { function setUp() public { world = IBaseWorld(address(new World())); - world.initialize(new CoreModule()); + world.initialize(createCoreModule()); StoreSwitch.setStoreAddress(address(world)); } diff --git a/packages/world/test/World.t.sol b/packages/world/test/World.t.sol index c6651b360e..3bfca2ff7c 100644 --- a/packages/world/test/World.t.sol +++ b/packages/world/test/World.t.sol @@ -35,9 +35,13 @@ import { Module, MODULE_INTERFACE_ID } from "../src/Module.sol"; import { NamespaceOwner, NamespaceOwnerTableId } from "../src/codegen/tables/NamespaceOwner.sol"; import { ResourceAccess } from "../src/codegen/tables/ResourceAccess.sol"; +import { AccessManagementSystem } from "../src/modules/core/implementations/AccessManagementSystem.sol"; +import { BalanceTransferSystem } from "../src/modules/core/implementations/BalanceTransferSystem.sol"; +import { BatchCallSystem } from "../src/modules/core/implementations/BatchCallSystem.sol"; + import { CoreModule } from "../src/modules/core/CoreModule.sol"; -import { CoreSystem } from "../src/modules/core/CoreSystem.sol"; -import { CORE_SYSTEM_ID } from "../src/modules/core/constants.sol"; +import { CoreRegistrationSystem } from "../src/modules/core/CoreRegistrationSystem.sol"; +import { CORE_REGISTRATION_SYSTEM_ID } from "../src/modules/core/constants.sol"; import { Systems } from "../src/codegen/tables/Systems.sol"; import { SystemRegistry } from "../src/codegen/tables/SystemRegistry.sol"; import { FunctionSelectors } from "../src/codegen/tables/FunctionSelectors.sol"; @@ -50,6 +54,7 @@ import { Bool } from "./codegen/tables/Bool.sol"; import { TwoFields, TwoFieldsData } from "./codegen/tables/TwoFields.sol"; import { AddressArray } from "./codegen/tables/AddressArray.sol"; import { DelegationControlMock } from "./DelegationControlMock.sol"; +import { createCoreModule } from "./createCoreModule.sol"; interface IWorldTestSystem { function testNamespace_testSystem_err(string memory input) external pure; @@ -170,7 +175,7 @@ contract WorldTest is Test, GasReporter { function setUp() public { world = IBaseWorld(address(new World())); - world.initialize(new CoreModule()); + world.initialize(createCoreModule()); StoreSwitch.setStoreAddress(address(world)); key = "testKey"; @@ -192,7 +197,7 @@ contract WorldTest is Test, GasReporter { } function testConstructorAndInitialize() public { - CoreModule coreModule = new CoreModule(); + CoreModule coreModule = createCoreModule(); vm.expectEmit(true, true, true, true); emit HelloWorld(WORLD_VERSION); @@ -217,33 +222,35 @@ contract WorldTest is Test, GasReporter { newWorld.initialize(coreModule); // Should have registered the core system function selectors - CoreSystem coreSystem = CoreSystem(Systems.getSystem(CORE_SYSTEM_ID)); + CoreRegistrationSystem coreRegistrationSystem = CoreRegistrationSystem( + Systems.getSystem(CORE_REGISTRATION_SYSTEM_ID) + ); bytes4[19] memory coreFunctionSignatures = [ // --- AccessManagementSystem --- - coreSystem.grantAccess.selector, - coreSystem.revokeAccess.selector, - coreSystem.transferOwnership.selector, + AccessManagementSystem.grantAccess.selector, + AccessManagementSystem.revokeAccess.selector, + AccessManagementSystem.transferOwnership.selector, // --- BalanceTransferSystem --- - coreSystem.transferBalanceToNamespace.selector, - coreSystem.transferBalanceToAddress.selector, + BalanceTransferSystem.transferBalanceToNamespace.selector, + BalanceTransferSystem.transferBalanceToAddress.selector, // --- BatchCallSystem --- - coreSystem.batchCall.selector, - coreSystem.batchCallFrom.selector, + BatchCallSystem.batchCall.selector, + BatchCallSystem.batchCallFrom.selector, // --- ModuleInstallationSystem --- - coreSystem.installModule.selector, + coreRegistrationSystem.installModule.selector, // --- StoreRegistrationSystem --- - coreSystem.registerTable.selector, - coreSystem.registerStoreHook.selector, - coreSystem.unregisterStoreHook.selector, + coreRegistrationSystem.registerTable.selector, + coreRegistrationSystem.registerStoreHook.selector, + coreRegistrationSystem.unregisterStoreHook.selector, // --- WorldRegistrationSystem --- - coreSystem.registerNamespace.selector, - coreSystem.registerSystemHook.selector, - coreSystem.unregisterSystemHook.selector, - coreSystem.registerSystem.selector, - coreSystem.registerFunctionSelector.selector, - coreSystem.registerRootFunctionSelector.selector, - coreSystem.registerDelegation.selector, - coreSystem.registerNamespaceDelegation.selector + coreRegistrationSystem.registerNamespace.selector, + coreRegistrationSystem.registerSystemHook.selector, + coreRegistrationSystem.unregisterSystemHook.selector, + coreRegistrationSystem.registerSystem.selector, + coreRegistrationSystem.registerFunctionSelector.selector, + coreRegistrationSystem.registerRootFunctionSelector.selector, + coreRegistrationSystem.registerDelegation.selector, + coreRegistrationSystem.registerNamespaceDelegation.selector ]; for (uint256 i; i < coreFunctionSignatures.length; i++) { diff --git a/packages/world/test/WorldBalance.t.sol b/packages/world/test/WorldBalance.t.sol index 3e92b2b4bf..65a6c84500 100644 --- a/packages/world/test/WorldBalance.t.sol +++ b/packages/world/test/WorldBalance.t.sol @@ -9,10 +9,10 @@ import { System } from "../src/System.sol"; import { IBaseWorld } from "../src/codegen/interfaces/IBaseWorld.sol"; import { ResourceId, WorldResourceIdLib, WorldResourceIdInstance } from "../src/WorldResourceId.sol"; import { ROOT_NAMESPACE, ROOT_NAMESPACE_ID } from "../src/constants.sol"; -import { CoreModule } from "../src/modules/core/CoreModule.sol"; import { Balances } from "../src/codegen/tables/Balances.sol"; import { IWorldErrors } from "../src/IWorldErrors.sol"; import { RESOURCE_SYSTEM, RESOURCE_NAMESPACE } from "../src/worldResourceTypes.sol"; +import { createCoreModule } from "./createCoreModule.sol"; using WorldResourceIdInstance for ResourceId; @@ -36,7 +36,7 @@ contract WorldBalanceTest is Test, GasReporter { function setUp() public { world = IBaseWorld(address(new World())); - world.initialize(new CoreModule()); + world.initialize(createCoreModule()); StoreSwitch.setStoreAddress(address(world)); world.registerNamespace(namespaceId); diff --git a/packages/world/test/WorldDynamicUpdate.t.sol b/packages/world/test/WorldDynamicUpdate.t.sol index a70d6e7b5e..69e14e0c4f 100644 --- a/packages/world/test/WorldDynamicUpdate.t.sol +++ b/packages/world/test/WorldDynamicUpdate.t.sol @@ -21,7 +21,7 @@ import { RESOURCE_TABLE } from "../src/worldResourceTypes.sol"; import { AddressArray } from "./codegen/tables/AddressArray.sol"; -import { CoreModule } from "../src/modules/core/CoreModule.sol"; +import { createCoreModule } from "./createCoreModule.sol"; import { IBaseWorld } from "../src/codegen/interfaces/IBaseWorld.sol"; import { IWorldErrors } from "../src/IWorldErrors.sol"; @@ -47,7 +47,7 @@ contract UpdateInDynamicFieldTest is Test, GasReporter { function setUp() public { world = IBaseWorld(address(new World())); - world.initialize(new CoreModule()); + world.initialize(createCoreModule()); StoreSwitch.setStoreAddress(address(world)); key = "testKey"; diff --git a/packages/world/test/createCoreModule.sol b/packages/world/test/createCoreModule.sol new file mode 100644 index 0000000000..ffbb174849 --- /dev/null +++ b/packages/world/test/createCoreModule.sol @@ -0,0 +1,19 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.21; + +import { AccessManagementSystem } from "../src/modules/core/implementations/AccessManagementSystem.sol"; +import { BalanceTransferSystem } from "../src/modules/core/implementations/BalanceTransferSystem.sol"; +import { BatchCallSystem } from "../src/modules/core/implementations/BatchCallSystem.sol"; + +import { CoreModule } from "../src/modules/core/CoreModule.sol"; +import { CoreRegistrationSystem } from "../src/modules/core/CoreRegistrationSystem.sol"; + +function createCoreModule() returns (CoreModule) { + return + new CoreModule( + new AccessManagementSystem(), + new BalanceTransferSystem(), + new BatchCallSystem(), + new CoreRegistrationSystem() + ); +}