-
Notifications
You must be signed in to change notification settings - Fork 0
/
WhitelistHook.sol
119 lines (97 loc) · 4.82 KB
/
WhitelistHook.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity ^0.8.18;
import {ISafe} from "@safe-global/safe-core-protocol/contracts/interfaces/Accounts.sol";
import {ISafeProtocolManager} from "@safe-global/safe-core-protocol/contracts/interfaces/Manager.sol";
import {SafeTransaction, SafeRootAccess} from "@safe-global/safe-core-protocol/contracts/DataTypes.sol";
import {BaseHookWithStoredMetadata, PluginMetadata} from "./BaseHook.sol";
contract WhitelistHook is BaseHookWithStoredMetadata {
// safe account => account => whitelist status
mapping(address => mapping(address => bool)) public whitelistedAddresses;
mapping(address => bool) public globalWhitelistedAddresses;
event AddressWhitelisted(address indexed safeAccount, address indexed account);
event AddressRemovedFromWhitelist(address indexed safeAccount, address indexed account);
error AddressNotWhiteListed(address account);
constructor(address[] memory accounts) BaseHookWithStoredMetadata(
PluginMetadata({name: "Whitelist Hook", version: "1.0.0", requiresRootAccess: false, iconUrl: "https://zenguard.xyz/static/media/onboard.e89b3a12b73438bee33cf058de1db6d2.svg", appUrl: "", hook: true})
)
{
for (uint i = 0; i < accounts.length; i++) {
globalWhitelistedAddresses[accounts[i]] = true;
emit AddressWhitelisted(address(0), accounts[i]);
}
}
/**
* @notice Adds accounts to whitelist mapping.
* The caller should be a Safe account.
* @param accounts addresses of the accounts to be whitelisted
*/
function addToWhitelist(address[] memory accounts) external {
for (uint i = 0; i < accounts.length; i++) {
whitelistedAddresses[msg.sender][accounts[i]] = true;
emit AddressWhitelisted(msg.sender, accounts[i]);
}
}
/**
* @notice Removes accounts from whitelist mapping.
* The caller should be a Safe account.
* @param accounts addresses of the accountes to be removed from the whitelist
*/
function removeFromWhitelist(address[] memory accounts) external {
for (uint i = 0; i < accounts.length; i++) {
whitelistedAddresses[msg.sender][accounts[i]] = false;
emit AddressRemovedFromWhitelist(msg.sender, accounts[i]);
}
}
/**
* @notice A function that will be called before the execution of a transaction if the hooks are enabled
* @dev Add custom logic in this function to validate the pre-state and contents of transaction for root access.
* @param account Address of the account
* @param tx SafeTransaction
* @param executionType uint256
* @param executionMeta bytes
* @return preCheckData bytes
*/
function preCheck(
ISafe account,
SafeTransaction calldata tx,
uint256 executionType,
bytes calldata executionMeta
) external view returns (bytes memory preCheckData) {
(address to, uint256 value,
bytes memory data,
uint256 safeTxGas,
uint256 baseGas,
uint256 gasPrice,
address gasToken,
address refundReceiver,
bytes memory signatures,
address msgSender ) = abi.decode(executionMeta, (address, uint256, bytes, uint256, uint256, uint256, address, address, bytes, address));
require(whitelistedAddresses[address(account)][to] || globalWhitelistedAddresses[to], "Address not in the whitelist");
}
/**
* @notice A function that will be called before the execution of a transaction if the hooks are enabled and
* transaction requies root access.
* @dev Add custom logic in this function to validate the pre-state and contents of transaction for root access.
* @param account Address of the account
* @param rootAccess DataTypes.SafeRootAccess
* @param executionType uint256
* @param executionMeta bytes
* @return preCheckData bytes
*/
function preCheckRootAccess(
ISafe account,
SafeRootAccess calldata rootAccess,
uint256 executionType,
bytes calldata executionMeta
) external returns (bytes memory preCheckData) {
}
/**
* @notice A function that will be called after the execution of a transaction if the hooks are enabled. Hooks should revert if the post state of after the transaction is not as expected.
* @dev Add custom logic in this function to validate the post-state after the transaction is executed.
* @param account Address of the account
* @param success bool
* @param preCheckData Arbitrary length bytes that was returned by during pre-check of the transaction.
*/
function postCheck(ISafe account, bool success, bytes calldata preCheckData) external {}
function requiresPermissions() external view returns (uint8 permissions) {}
}