-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathAccessControl.sol
138 lines (116 loc) · 4.03 KB
/
AccessControl.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;
import { IPausable } from "../interfaces/IPausable.sol";
import { IContractAddressManager } from "../interfaces/IContractAddressManager.sol";
import { Pausable } from "@openzeppelin/contracts/utils/Pausable.sol";
import { AccessControlEnumerable } from "@openzeppelin/contracts/access/extensions/AccessControlEnumerable.sol";
import { SignatureControl } from "./SignatureControl.sol";
import { ETHOS_INTERACTION_CONTROL } from "./Constants.sol";
/**
* @dev Contract module that allows children to restrict access to run functions
* by service account only.
*/
abstract contract AccessControl is IPausable, Pausable, AccessControlEnumerable, SignatureControl {
bytes32 public constant OWNER_ROLE = keccak256("OWNER_ROLE");
bytes32 public constant ADMIN_ROLE = keccak256("ADMIN_ROLE");
IContractAddressManager public contractAddressManager;
/**
* @dev Constructor.
* @param owner Owner address.
* @param admin Admin address.
* @param expectedSigner Signer address used for signing methods that should be approved by Ethos.
* @param signatureVerifier SignatureVerifier contract address.
* @param contractAddressManagerAddr ContractAddressManager contract address.
*/
// solhint-disable-next-line func-name-mixedcase
function __accessControl_init(
address owner,
address admin,
address expectedSigner,
address signatureVerifier,
address contractAddressManagerAddr
) internal onlyInitializing {
if (owner == address(0) || admin == address(0) || contractAddressManagerAddr == address(0)) {
revert ZeroAddress();
}
__signatureControl_init(expectedSigner, signatureVerifier);
contractAddressManager = IContractAddressManager(contractAddressManagerAddr);
_grantRole(OWNER_ROLE, owner);
_grantRole(ADMIN_ROLE, admin);
// allowlistEnabled = false;
}
modifier onlyOwner() {
_checkRole(OWNER_ROLE);
_;
}
modifier onlyAdmin() {
_checkRole(ADMIN_ROLE);
_;
}
modifier onlyInteractionControl() {
address interactionsControlAddr = contractAddressManager.getContractAddressForName(
ETHOS_INTERACTION_CONTROL
);
if (interactionsControlAddr != msg.sender) {
revert AccessControlUnauthorizedAccount(msg.sender, keccak256("ETHOS_INTERACTION_CONTROL"));
}
_;
}
/**
* @dev Updates ContractAddressManager address.
* @param contractAddressesAddr ContractAddresses address.
*/
function updateContractAddressManager(address contractAddressesAddr) external onlyAdmin {
contractAddressManager = IContractAddressManager(contractAddressesAddr);
}
// Owner
/**
* @dev Updates owner address.
* @param owner Owner address to be used instead of current.
*/
function updateOwner(address owner) external onlyOwner {
_revokeRole(OWNER_ROLE, getRoleMember(OWNER_ROLE, 0));
_grantRole(OWNER_ROLE, owner);
}
// Admin
/**
* @dev Adds admin address.
* @param admin Admin address to be added.
*/
function addAdmin(address admin) external onlyOwner {
_grantRole(ADMIN_ROLE, admin);
}
/**
* @dev Removes admin address.
* @param admin Admin address to be removed.
*/
function removeAdmin(address admin) external onlyOwner {
_revokeRole(ADMIN_ROLE, admin);
}
// Signature verification
/**
* @dev Updates expected signer of signatures.
* @param signer Signer address.
*/
function updateExpectedSigner(address signer) external onlyAdmin {
_updateExpectedSigner(signer);
}
/**
* @dev Updates signature verifier contract address.
* @param sinatureVerifier SignatureVerifier contract address.
*/
function updateSignatureVerifier(address sinatureVerifier) external onlyAdmin {
_updateSignatureVerifier(sinatureVerifier);
}
// Pausable
function pause() external onlyInteractionControl {
super._pause();
}
function unpause() external onlyInteractionControl {
super._unpause();
}
// IPausable
function paused() public view override(IPausable, Pausable) returns (bool) {
return super.paused();
}
}