-
Notifications
You must be signed in to change notification settings - Fork 1
/
Greenlistable.sol
111 lines (98 loc) · 2.89 KB
/
Greenlistable.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
// SPDX-License-Identifier: MIT
pragma solidity 0.8.9;
import "./WithMidasAccessControl.sol";
/**
* @title Greenlistable
* @notice Base contract that implements basic functions and modifiers
* to work with greenlistable
* @author RedDuck Software
*/
abstract contract Greenlistable is WithMidasAccessControl {
/**
* @notice actor that can change green list enable
*/
bytes32 public constant GREENLIST_TOGGLER_ROLE =
keccak256("GREENLIST_TOGGLER_ROLE");
/**
* @notice is greenlist enabled
*/
bool public greenlistEnabled;
event SetGreenlistEnable(address indexed sender, bool enable);
/**
* @dev checks that a given `account`
* have `greenlistedRole()`
*/
modifier onlyGreenlisted(address account) {
if (greenlistEnabled) _onlyGreenlisted(account);
_;
}
/**
* @dev checks that a given `account`
* have `greenlistedRole()`
* do the check even if greenlist check is off
*/
modifier onlyAlwaysGreenlisted(address account) {
_onlyGreenlisted(account);
_;
}
/**
* @dev upgradeable pattern contract`s initializer
* @param _accessControl MidasAccessControl contract address
*/
// solhint-disable func-name-mixedcase
function __Greenlistable_init(address _accessControl)
internal
onlyInitializing
{
__WithMidasAccessControl_init(_accessControl);
__Greenlistable_init_unchained();
}
/**
* @dev upgradeable pattern contract`s initializer unchained
*/
// solhint-disable func-name-mixedcase
function __Greenlistable_init_unchained() internal onlyInitializing {}
/**
* @notice enable or disable greenlist.
* can be called only from permissioned actor.
* @param enable enable
*/
function setGreenlistEnable(bool enable) external {
_onlyGreenlistToggler(msg.sender);
require(greenlistEnabled != enable, "GL: same enable status");
greenlistEnabled = enable;
emit SetGreenlistEnable(msg.sender, enable);
}
/**
* @notice AC role of a greenlist
* @return role bytes32 role
*/
function greenlistedRole() public view virtual returns (bytes32) {
return GREENLISTED_ROLE;
}
/**
* @notice AC role of a greenlist
* @return role bytes32 role
*/
function greenlistTogglerRole() public view virtual returns (bytes32) {
return GREENLIST_TOGGLER_ROLE;
}
/**
* @dev checks that a given `account`
* have a `greenlistedRole()`
*/
function _onlyGreenlisted(address account)
private
view
onlyRole(greenlistedRole(), account)
{}
/**
* @dev checks that a given `account`
* have a `greenlistTogglerRole()`
*/
function _onlyGreenlistToggler(address account)
internal
view
onlyRole(greenlistTogglerRole(), account)
{}
}