Skip to content

Commit

Permalink
feat: call unregister hook if exists on delegatee
Browse files Browse the repository at this point in the history
  • Loading branch information
dhvanipa committed Mar 18, 2024
1 parent ae4b224 commit 9055202
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/world/src/ICustomUnregisterDelegation.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.24;

import { IERC165 } from "./IERC165.sol";

interface ICustomUnregisterDelegation is IERC165 {
function canUnregister() external returns (bool);
}
6 changes: 6 additions & 0 deletions packages/world/src/IWorldErrors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ interface IWorldErrors {
*/
error World_UnlimitedDelegationNotAllowed();

/**
* @notice Raised when unregister delegation is called but a custom unregister delegation blocks it
* e.g. if the delegation agreement wanted to enforce some conditions before allowing the delegation to be removed
*/
error World_CustomUnregisterDelegationNotAllowed();

/**
* @notice Raised when there's an insufficient balance for a particular operation.
* @param balance The current balance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import { NamespaceDelegationControl } from "../../../codegen/tables/NamespaceDel
import { ISystemHook } from "../../../ISystemHook.sol";
import { IWorldErrors } from "../../../IWorldErrors.sol";
import { IDelegationControl } from "../../../IDelegationControl.sol";
import { ICustomUnregisterDelegation } from "../../../ICustomUnregisterDelegation.sol";
import { ERC165Checker } from "../../../ERC165Checker.sol";

import { SystemHooks } from "../../../codegen/tables/SystemHooks.sol";
import { SystemRegistry } from "../../../codegen/tables/SystemRegistry.sol";
Expand Down Expand Up @@ -293,6 +295,15 @@ contract WorldRegistrationSystem is System, IWorldErrors, LimitedCallContext {
* @param delegatee The address of the delegatee
*/
function unregisterDelegation(address delegatee) public onlyDelegatecall {
if (ERC165Checker.supportsInterface(delegatee, type(ICustomUnregisterDelegation).interfaceId)) {
(bool canUnregisterSuccess, bytes memory canUnregisterReturnData) = delegatee.call(
abi.encodeCall(ICustomUnregisterDelegation.canUnregister, ())
);
if (!canUnregisterSuccess) revert World_CustomUnregisterDelegationNotAllowed();
canUnregisterSuccess = abi.decode(canUnregisterReturnData, (bool));
if (!canUnregisterSuccess) revert World_CustomUnregisterDelegationNotAllowed();
}

// Delete the delegation control contract address
UserDelegationControl.deleteRecord({ delegator: _msgSender(), delegatee: delegatee });
}
Expand Down

0 comments on commit 9055202

Please sign in to comment.