diff --git a/packages/world-module-metadata/src/DelegatorContext.sol b/packages/world-module-metadata/src/DelegatorContext.sol deleted file mode 100644 index 3559b308b3..0000000000 --- a/packages/world-module-metadata/src/DelegatorContext.sol +++ /dev/null @@ -1,69 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity >=0.8.24; - -import { IBaseWorld } from "@latticexyz/world/src/codegen/interfaces/IBaseWorld.sol"; -import { ResourceId } from "@latticexyz/world/src/WorldResourceId.sol"; -import { REGISTRATION_SYSTEM_ID } from "@latticexyz/world/src/modules/init/constants.sol"; -import { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol"; -import { Schema } from "@latticexyz/store/src/Schema.sol"; -import { System } from "@latticexyz/world/src/System.sol"; - -// TODO: move this into world? or codegen it? would be nice to have this for every system - -// TODO: name? -struct DelegatorContext { - IBaseWorld world; - address delegator; -} - -library DelegatedRegistrationSystemLib { - function registerNamespace(DelegatorContext memory context, ResourceId namespace) internal { - context.world.callFrom( - context.delegator, - REGISTRATION_SYSTEM_ID, - abi.encodeCall(context.world.registerNamespace, (namespace)) - ); - } - - function registerTable( - DelegatorContext memory context, - ResourceId tableId, - FieldLayout fieldLayout, - Schema keySchema, - Schema valueSchema, - string[] memory keyNames, - string[] memory fieldNames - ) internal { - context.world.callFrom( - context.delegator, - REGISTRATION_SYSTEM_ID, - abi.encodeCall(context.world.registerTable, (tableId, fieldLayout, keySchema, valueSchema, keyNames, fieldNames)) - ); - } - - function registerSystem( - DelegatorContext memory context, - ResourceId systemId, - System system, - bool publicAccess - ) internal { - context.world.callFrom( - context.delegator, - REGISTRATION_SYSTEM_ID, - abi.encodeCall(context.world.registerSystem, (systemId, system, publicAccess)) - ); - } - - function registerFunctionSelector( - DelegatorContext memory context, - ResourceId systemId, - string memory systemFunctionSignature - ) internal returns (bytes4 worldFunctionSelector) { - bytes memory returnData = context.world.callFrom( - context.delegator, - REGISTRATION_SYSTEM_ID, - abi.encodeCall(context.world.registerFunctionSelector, (systemId, systemFunctionSignature)) - ); - return bytes4(returnData); - } -} diff --git a/packages/world-module-metadata/src/MetadataModule.sol b/packages/world-module-metadata/src/MetadataModule.sol index 04c982fb6d..6df3fff282 100644 --- a/packages/world-module-metadata/src/MetadataModule.sol +++ b/packages/world-module-metadata/src/MetadataModule.sol @@ -8,10 +8,11 @@ import { ResourceId, WorldResourceIdLib, WorldResourceIdInstance } from "@lattic import { ResourceIds } from "@latticexyz/store/src/codegen/tables/ResourceIds.sol"; import { RESOURCE_SYSTEM } from "@latticexyz/world/src/worldResourceTypes.sol"; import { REGISTRATION_SYSTEM_ID } from "@latticexyz/world/src/modules/init/constants.sol"; +import { worldRegistrationSystem } from "@latticexyz/world/src/codegen/systems/WorldRegistrationSystemLib.sol"; +import { storeRegistrationSystem } from "@latticexyz/world/src/codegen/systems/StoreRegistrationSystemLib.sol"; import { MetadataSystem } from "./MetadataSystem.sol"; import { ResourceTag } from "./codegen/tables/ResourceTag.sol"; -import { DelegatorContext, DelegatedRegistrationSystemLib } from "./DelegatorContext.sol"; /** * @title MetadataModule @@ -21,22 +22,19 @@ import { DelegatorContext, DelegatedRegistrationSystemLib } from "./DelegatorCon */ contract MetadataModule is Module { using WorldResourceIdInstance for ResourceId; - using DelegatedRegistrationSystemLib for DelegatorContext; MetadataSystem private immutable metadataSystem = new MetadataSystem(); function install(bytes memory args) public override { - DelegatorContext memory world = DelegatorContext(IBaseWorld(_world()), _msgSender()); - ResourceId namespace = ResourceTag._tableId.getNamespaceId(); if (!ResourceIds.getExists(namespace)) { - world.registerNamespace(namespace); + worldRegistrationSystem.callFrom(_msgSender()).registerNamespace(namespace); } - AccessControl.requireOwner(namespace, world.delegator); + AccessControl.requireOwner(namespace, _msgSender()); if (!ResourceIds.getExists(ResourceTag._tableId)) { // TODO: add a `ResourceTag.getTableDef()` that returns a struct that can be used to register? - world.registerTable( + storeRegistrationSystem.callFrom(_msgSender()).registerTable( ResourceTag._tableId, ResourceTag._fieldLayout, ResourceTag._keySchema, @@ -53,10 +51,19 @@ contract MetadataModule is Module { ); // TODO: add support for upgrading system and registering new function selectors if (!ResourceIds.getExists(metadataSystemId)) { - world.registerSystem(metadataSystemId, metadataSystem, true); - world.registerFunctionSelector(metadataSystemId, "getResourceTag(bytes32,bytes32)"); - world.registerFunctionSelector(metadataSystemId, "setResourceTag(bytes32,bytes32,bytes)"); - world.registerFunctionSelector(metadataSystemId, "deleteResourceTag(bytes32,bytes32)"); + worldRegistrationSystem.callFrom(_msgSender()).registerSystem(metadataSystemId, metadataSystem, true); + worldRegistrationSystem.callFrom(_msgSender()).registerFunctionSelector( + metadataSystemId, + "getResourceTag(bytes32,bytes32)" + ); + worldRegistrationSystem.callFrom(_msgSender()).registerFunctionSelector( + metadataSystemId, + "setResourceTag(bytes32,bytes32,bytes)" + ); + worldRegistrationSystem.callFrom(_msgSender()).registerFunctionSelector( + metadataSystemId, + "deleteResourceTag(bytes32,bytes32)" + ); } } }