Skip to content

Commit

Permalink
feat: add unregisterSystem
Browse files Browse the repository at this point in the history
  • Loading branch information
yonadaa committed Jan 18, 2024
1 parent dcaff7b commit 5881958
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 11 deletions.
10 changes: 5 additions & 5 deletions packages/world-modules/gas-report.json
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@
"file": "test/StandardDelegationsModule.t.sol",
"test": "testCallFromCallboundDelegation",
"name": "register a callbound delegation",
"gasUsed": 118161
"gasUsed": 118179
},
{
"file": "test/StandardDelegationsModule.t.sol",
Expand All @@ -279,7 +279,7 @@
"file": "test/StandardDelegationsModule.t.sol",
"test": "testCallFromSystemDelegation",
"name": "register a systembound delegation",
"gasUsed": 115714
"gasUsed": 115732
},
{
"file": "test/StandardDelegationsModule.t.sol",
Expand All @@ -291,7 +291,7 @@
"file": "test/StandardDelegationsModule.t.sol",
"test": "testCallFromTimeboundDelegation",
"name": "register a timebound delegation",
"gasUsed": 112637
"gasUsed": 112655
},
{
"file": "test/StandardDelegationsModule.t.sol",
Expand All @@ -303,7 +303,7 @@
"file": "test/UniqueEntityModule.t.sol",
"test": "testInstall",
"name": "install unique entity module",
"gasUsed": 702702
"gasUsed": 702743
},
{
"file": "test/UniqueEntityModule.t.sol",
Expand All @@ -315,7 +315,7 @@
"file": "test/UniqueEntityModule.t.sol",
"test": "testInstallRoot",
"name": "installRoot unique entity module",
"gasUsed": 671744
"gasUsed": 671762
},
{
"file": "test/UniqueEntityModule.t.sol",
Expand Down
8 changes: 4 additions & 4 deletions packages/world/gas-report.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"file": "test/Factories.t.sol",
"test": "testWorldFactory",
"name": "deploy world via WorldFactory",
"gasUsed": 12644240
"gasUsed": 12709748
},
{
"file": "test/World.t.sol",
Expand All @@ -81,7 +81,7 @@
"file": "test/World.t.sol",
"test": "testCallFromUnlimitedDelegation",
"name": "register an unlimited delegation",
"gasUsed": 47555
"gasUsed": 47561
},
{
"file": "test/World.t.sol",
Expand Down Expand Up @@ -117,13 +117,13 @@
"file": "test/World.t.sol",
"test": "testRegisterRootFunctionSelector",
"name": "Register a root function selector",
"gasUsed": 80402
"gasUsed": 80425
},
{
"file": "test/World.t.sol",
"test": "testRegisterSystem",
"name": "register a system",
"gasUsed": 164326
"gasUsed": 164344
},
{
"file": "test/World.t.sol",
Expand Down

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

3 changes: 2 additions & 1 deletion packages/world/src/modules/core/CoreModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ contract CoreModule is Module {
_registerRootFunctionSelector(BATCH_CALL_SYSTEM_ID, functionSignaturesBatchCall[i]);
}

string[14] memory functionSignaturesCoreRegistration = [
string[15] memory functionSignaturesCoreRegistration = [
// --- ModuleInstallationSystem ---
"installModule(address,bytes)",
// --- StoreRegistrationSystem ---
Expand All @@ -181,6 +181,7 @@ contract CoreModule is Module {
"registerSystemHook(bytes32,address,uint8)",
"unregisterSystemHook(bytes32,address)",
"registerSystem(bytes32,address,bool)",
"unregisterSystem(bytes32)",
"registerFunctionSelector(bytes32,string)",
"registerRootFunctionSelector(bytes32,string,bytes4)",
"registerDelegation(address,bytes32,bytes)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,40 @@ contract WorldRegistrationSystem is System, IWorldErrors {
ResourceAccess._set(namespaceId, address(system), true);
}

/**
* @notice Unregisters a system
* @dev Unregisters the system at the given ID
* @param systemId The unique identifier for the system
*/
function unregisterSystem(ResourceId systemId) public virtual {
// Require the provided system ID to have type RESOURCE_SYSTEM
if (systemId.getType() != RESOURCE_SYSTEM) {
revert World_InvalidResourceType(RESOURCE_SYSTEM, systemId, systemId.toString());
}

// Require the system's namespace to exist
ResourceId namespaceId = systemId.getNamespaceId();
AccessControl.requireExistence(namespaceId);

// Require the caller to own the namespace
AccessControl.requireOwner(namespaceId, _msgSender());

// Require the name to not be the namespace's root name
if (systemId.getName() == ROOT_NAME) revert World_InvalidResourceId(systemId, systemId.toString());

// Get the system at this system ID
address existingSystem = Systems._getSystem(systemId);

// Systems = mapping from system ID to system address and public access flag
Systems._deleteRecord(systemId);

// SystemRegistry = mapping from system address to system ID
SystemRegistry._deleteRecord(address(existingSystem));

// Grant the system access to its namespace
ResourceAccess._deleteRecord(namespaceId, address(existingSystem));
}

/**
* @notice Registers a new World function selector
* @dev Creates a mapping between a World function and its associated system function
Expand Down
3 changes: 2 additions & 1 deletion packages/world/test/World.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ contract WorldTest is Test, GasReporter {
CoreRegistrationSystem coreRegistrationSystem = CoreRegistrationSystem(
Systems.getSystem(CORE_REGISTRATION_SYSTEM_ID)
);
bytes4[22] memory coreFunctionSignatures = [
bytes4[23] memory coreFunctionSignatures = [
// --- AccessManagementSystem ---
AccessManagementSystem.grantAccess.selector,
AccessManagementSystem.revokeAccess.selector,
Expand All @@ -248,6 +248,7 @@ contract WorldTest is Test, GasReporter {
coreRegistrationSystem.registerSystemHook.selector,
coreRegistrationSystem.unregisterSystemHook.selector,
coreRegistrationSystem.registerSystem.selector,
coreRegistrationSystem.unregisterSystem.selector,
coreRegistrationSystem.registerFunctionSelector.selector,
coreRegistrationSystem.registerRootFunctionSelector.selector,
coreRegistrationSystem.registerDelegation.selector,
Expand Down

0 comments on commit 5881958

Please sign in to comment.