Skip to content

Commit

Permalink
feat: delete installedModules, world initialized flag
Browse files Browse the repository at this point in the history
  • Loading branch information
yonadaa committed Jan 22, 2024
1 parent 61985bb commit 056dce2
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 154 deletions.
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": 4695103
},
{
"file": "test/Factories.t.sol",
"test": "testWorldFactory",
"name": "deploy world via WorldFactory",
"gasUsed": 12642949
"gasUsed": 12497522
},
{
"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
15 changes: 6 additions & 9 deletions packages/world/mud.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,6 @@ export default mudConfig({
access: "bool",
},
},
InstalledModules: {
keySchema: {
moduleName: "bytes16",
argumentsHash: "bytes32", // Hash of the params passed to the `install` function
},
valueSchema: {
moduleAddress: "address",
},
},
UserDelegationControl: {
keySchema: {
delegator: "address",
Expand Down Expand Up @@ -103,6 +94,12 @@ export default mudConfig({
},
offchainOnly: true,
},
WorldInitialized: {
keySchema: {},
valueSchema: {
isInitialized: "bool",
},
},
},
excludeSystems: [
// Worldgen currently does not support systems inheriting logic
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
22 changes: 0 additions & 22 deletions packages/world/src/Module.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { WorldContextConsumer } from "./WorldContext.sol";
import { IWorldContextConsumer } from "./IWorldContextConsumer.sol";
import { IModule, IModule } from "./IModule.sol";
import { IERC165 } from "./IERC165.sol";
import { InstalledModules } from "./codegen/tables/InstalledModules.sol";

/**
* @title Module
Expand All @@ -26,25 +25,4 @@ abstract contract Module is IModule, WorldContextConsumer {
interfaceId == type(IWorldContextConsumer).interfaceId ||
interfaceId == type(IERC165).interfaceId;
}

/**
* @dev Check if a module with the given name and arguments is installed.
* @param moduleName The name 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);
}

/**
* @dev Revert if the module with the given name and arguments is already installed.
* @param moduleName 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)) {
revert Module_AlreadyInstalled();
}
}
}
10 changes: 4 additions & 6 deletions packages/world/src/World.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,15 @@ import { WorldContextProviderLib } from "./WorldContext.sol";
import { Delegation } from "./Delegation.sol";
import { requireInterface } from "./requireInterface.sol";

import { InstalledModules } from "./codegen/tables/InstalledModules.sol";
import { UserDelegationControl } from "./codegen/tables/UserDelegationControl.sol";
import { NamespaceDelegationControl } from "./codegen/tables/NamespaceDelegationControl.sol";
import { WorldInitialized } from "./codegen/tables/WorldInitialized.sol";

import { IModule, IModule } from "./IModule.sol";
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,10 +70,12 @@ contract World is StoreData, IWorldKernel {
}

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

WorldInitialized.set(true);

// Initialize the World by installing the core module
_installRootModule(coreModule, new bytes(0));
}
Expand Down Expand Up @@ -105,9 +106,6 @@ contract World is StoreData, IWorldKernel {
target: address(module),
callData: abi.encodeCall(IModule.installRoot, (args))
});

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

/************************************************************************
Expand Down
2 changes: 1 addition & 1 deletion packages/world/src/codegen/index.sol

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

Loading

0 comments on commit 056dce2

Please sign in to comment.