-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathHooksManager.sol
40 lines (34 loc) · 1.65 KB
/
HooksManager.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity ^0.8.18;
import {ISafeProtocolHooks} from "../interfaces/Integrations.sol";
contract HooksManager {
mapping(address => address) public enabledHooks;
/// @notice This variable should store the address of the hooks contract whenever
/// checkTransaction(...) is called and use it in checkAfterExecution(...) to avoid
/// any side effects of changed hooks address inbetween transaction.
mapping(address => address) public tempHooksAddress;
// Events
event HooksChanged(address indexed safe, address indexed hooksAddress);
// Errors
error AddressDoesNotImplementHooksInterface(address hooksAddress);
/**
* @notice Returns the address of hooks for a Safe account provided as a fucntion parameter.
* Returns address(0) is no hooks are enabled.
* @param safe Address of a Safe account
* @return hooksAddress Address of hooks enabled for on Safe account
*/
function getEnabledHooks(address safe) external view returns (address hooksAddress) {
hooksAddress = enabledHooks[safe];
}
/**
* @notice Sets hooks on an account. If Zero address is set, manager will not perform pre and post checks for on Safe transaction.
* @param hooks Address of the hooks to be enabled for msg.sender.
*/
function setHooks(address hooks) external {
if (hooks != address(0) && !ISafeProtocolHooks(hooks).supportsInterface(type(ISafeProtocolHooks).interfaceId)) {
revert AddressDoesNotImplementHooksInterface(hooks);
}
enabledHooks[msg.sender] = hooks;
emit HooksChanged(msg.sender, hooks);
}
}