-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#47] Create FunctionHandlerManager.sol and inherit in SafeProtocolMa…
…nager
- Loading branch information
Showing
2 changed files
with
46 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
pragma solidity ^0.8.18; | ||
import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol"; | ||
|
||
/** | ||
* @title This contract manages the function handlers for the Safe Account. The contract stores the | ||
* information about Safe account, Function selectr and the function handler contract address. | ||
*/ | ||
contract FunctionHandlerManager { | ||
// Storage | ||
/** @dev Mapping that stores information about Safe account, function selector, and address of the account. | ||
*/ | ||
mapping(address => mapping(bytes4 => address)) public functionHandlers; | ||
|
||
// Events | ||
event FunctionHandlerChanged(address indexed safe, bytes4 indexed selector, address indexed functionHandler); | ||
|
||
// Errors | ||
error AddressDoesNotImplementFunctionHandlerInterface(address functionHandler); | ||
|
||
/** | ||
* @notice Returns the function handler for a Safe account and function selector. | ||
* @param safe Address of the Safe account | ||
* @param selector bytes4 function selector | ||
* @return functionHandler Address of the contract to be set as a function handler | ||
*/ | ||
function getFunctionHandler(address safe, bytes4 selector) external view returns (address functionHandler) { | ||
functionHandler = functionHandlers[safe][selector]; | ||
} | ||
|
||
/** | ||
* @notice Sets the function handler for a Safe account and function selector. The msg.sender must be the account. | ||
* @param selector bytes4 function selector | ||
* @param functionHandler Address of the contract to be set as a function handler | ||
*/ | ||
function setFunctionHandler(bytes4 selector, address functionHandler) external { | ||
if (functionHandler != address(0) && !IERC165(functionHandler).supportsInterface(0x00000000)) { | ||
revert AddressDoesNotImplementFunctionHandlerInterface(functionHandler); | ||
} | ||
|
||
functionHandlers[msg.sender][selector] = functionHandler; | ||
emit FunctionHandlerChanged(msg.sender, selector, functionHandler); | ||
} | ||
} |