Skip to content

Commit

Permalink
wip(world): identify modules by addresses instead of names
Browse files Browse the repository at this point in the history
  • Loading branch information
yonadaa committed Jan 19, 2024
1 parent 61985bb commit 90c7acb
Show file tree
Hide file tree
Showing 11 changed files with 77 additions and 95 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { createPuppet } from "../puppet/createPuppet.sol";
import { MODULE_NAME as PUPPET_MODULE_NAME } from "../puppet/constants.sol";
import { Balances } from "../tokens/tables/Balances.sol";

import { MODULE_NAME, MODULE_NAMESPACE, MODULE_NAMESPACE_ID, ERC20_REGISTRY_TABLE_ID } from "./constants.sol";
import { MODULE_NAMESPACE, MODULE_NAMESPACE_ID, ERC20_REGISTRY_TABLE_ID } from "./constants.sol";
import { _allowancesTableId, _balancesTableId, _metadataTableId, _erc20SystemId } from "./utils.sol";
import { ERC20System } from "./ERC20System.sol";

Expand All @@ -26,10 +26,6 @@ contract ERC20Module is Module {

address immutable registrationLibrary = address(new ERC20ModuleRegistrationLibrary());

function getName() public pure override returns (bytes16) {
return MODULE_NAME;
}

function _requireDependencies() internal view {
// Require PuppetModule to be installed
if (!isInstalled(PUPPET_MODULE_NAME, new bytes(0))) {
Expand Down
6 changes: 3 additions & 3 deletions packages/world/gas-report.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@
"file": "test/Factories.t.sol",
"test": "testCreate2Factory",
"name": "deploy contract via Create2",
"gasUsed": 4659744
"gasUsed": 4618211
},
{
"file": "test/Factories.t.sol",
"test": "testWorldFactory",
"name": "deploy world via WorldFactory",
"gasUsed": 12642949
"gasUsed": 12601160
},
{
"file": "test/World.t.sol",
Expand Down Expand Up @@ -111,7 +111,7 @@
"file": "test/World.t.sol",
"test": "testRegisterNamespace",
"name": "Register a new namespace",
"gasUsed": 120969
"gasUsed": 120951
},
{
"file": "test/World.t.sol",
Expand Down
4 changes: 2 additions & 2 deletions packages/world/mud.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ export default mudConfig({
},
InstalledModules: {
keySchema: {
moduleName: "bytes16",
moduleAddress: "address",
argumentsHash: "bytes32", // Hash of the params passed to the `install` function
},
valueSchema: {
moduleAddress: "address",
isInstalled: "bool",
},
},
UserDelegationControl: {
Expand Down
7 changes: 0 additions & 7 deletions packages/world/src/IModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,6 @@ interface IModule is IERC165 {
error Module_AlreadyInstalled();
error Module_MissingDependency(string dependency);

/**
* @notice Return the name of the module.
* @dev Provides a way to identify the module by a unique name.
* @return name The name of the module as a bytes16.
*/
function getName() external view returns (bytes16 name);

/**
* @notice Installs the module as a root module.
* @dev This function is invoked by the World contract during `installRootModule` process.
Expand Down
12 changes: 6 additions & 6 deletions packages/world/src/Module.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,21 @@ abstract contract Module is IModule, WorldContextConsumer {

/**
* @dev Check if a module with the given name and arguments is installed.
* @param moduleName The name of the module.
* @param moduleAddress The address of the module.
* @param args The arguments for the module installation.
* @return true if the module is installed, false otherwise.
*/
function isInstalled(bytes16 moduleName, bytes memory args) internal view returns (bool) {
return InstalledModules.get(moduleName, keccak256(args)) != address(0);
function isInstalled(address moduleAddress, bytes memory args) internal view returns (bool) {
return InstalledModules.get(moduleAddress, keccak256(args));
}

/**
* @dev Revert if the module with the given name and arguments is already installed.
* @param moduleName The name of the module.
* @param moduleAddress The name of the module.
* @param args The arguments for the module installation.
*/
function requireNotInstalled(bytes16 moduleName, bytes memory args) internal view {
if (isInstalled(moduleName, args)) {
function requireNotInstalled(address moduleAddress, bytes memory args) internal view {
if (isInstalled(moduleAddress, args)) {
revert Module_AlreadyInstalled();
}
}
Expand Down
5 changes: 2 additions & 3 deletions packages/world/src/World.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import { IWorldKernel } from "./IWorldKernel.sol";

import { FunctionSelectors } from "./codegen/tables/FunctionSelectors.sol";
import { Balances } from "./codegen/tables/Balances.sol";
import { CORE_MODULE_NAME } from "./modules/core/constants.sol";

/**
* @title World Contract
Expand Down Expand Up @@ -71,7 +70,7 @@ contract World is StoreData, IWorldKernel {
}

// The World can only be initialized once
if (InstalledModules._get(CORE_MODULE_NAME, keccak256("")) != address(0)) {
if (InstalledModules._get(address(coreModule), keccak256(""))) {
revert World_AlreadyInitialized();
}

Expand Down Expand Up @@ -107,7 +106,7 @@ contract World is StoreData, IWorldKernel {
});

// Register the module in the InstalledModules table
InstalledModules._set(module.getName(), keccak256(args), address(module));
InstalledModules._set(address(module), keccak256(args), true);
}

/************************************************************************
Expand Down
106 changes: 59 additions & 47 deletions packages/world/src/codegen/tables/InstalledModules.sol

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 1 addition & 9 deletions packages/world/src/modules/core/CoreModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { BalanceTransferSystem } from "./implementations/BalanceTransferSystem.s
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 { 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";
Expand Down Expand Up @@ -56,14 +56,6 @@ contract CoreModule is Module {
coreRegistrationSystem = address(_coreRegistrationSystem);
}

/**
* @notice Get the name of the module.
* @return Module name as bytes16.
*/
function getName() public pure returns (bytes16) {
return CORE_MODULE_NAME;
}

/**
* @notice Root installation of the module.
* @dev Registers core tables, systems, and function selectors in the World.
Expand Down
Loading

0 comments on commit 90c7acb

Please sign in to comment.