This repository has been archived by the owner on Jul 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
RolesAdmin.sol
91 lines (67 loc) · 3.35 KB
/
RolesAdmin.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
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity 0.8.15;
import {ROLESv1} from "src/modules/ROLES/ROLES.v1.sol";
import "src/Kernel.sol";
/// @notice The RolesAdmin Policy grants and revokes Roles in the ROLES module.
contract RolesAdmin is Policy {
// ========= EVENTS ========= //
event NewAdminPushed(address indexed newAdmin_);
event NewAdminPulled(address indexed newAdmin_);
// ========= ERRORS ========= //
error Roles_OnlyAdmin();
error Roles_OnlyNewAdmin();
// ========= STATE ========= //
/// @notice Special role that is responsible for assigning policy-defined roles to addresses.
address public admin;
/// @notice Proposed new admin. Address must call `pullRolesAdmin` to become the new roles admin.
address public newAdmin;
ROLESv1 public ROLES;
//============================================================================================//
// POLICY SETUP //
//============================================================================================//
constructor(Kernel _kernel) Policy(_kernel) {
admin = msg.sender;
}
function configureDependencies() external override returns (Keycode[] memory dependencies) {
dependencies = new Keycode[](1);
dependencies[0] = toKeycode("ROLES");
ROLES = ROLESv1(getModuleAddress(dependencies[0]));
(uint8 ROLES_MAJOR, ) = ROLES.VERSION();
// Ensure Modules are using the expected major version.
// Modules should be sorted in alphabetical order.
bytes memory expected = abi.encode([1]);
if (ROLES_MAJOR != 1) revert Policy_WrongModuleVersion(expected);
}
function requestPermissions() external view override returns (Permissions[] memory requests) {
Keycode ROLES_KEYCODE = toKeycode("ROLES");
requests = new Permissions[](2);
requests[0] = Permissions(ROLES_KEYCODE, ROLES.saveRole.selector);
requests[1] = Permissions(ROLES_KEYCODE, ROLES.removeRole.selector);
}
//============================================================================================//
// CORE FUNCTIONS //
//============================================================================================//
modifier onlyAdmin() {
if (msg.sender != admin) revert Roles_OnlyAdmin();
_;
}
function grantRole(bytes32 role_, address wallet_) external onlyAdmin {
ROLES.saveRole(role_, wallet_);
}
function revokeRole(bytes32 role_, address wallet_) external onlyAdmin {
ROLES.removeRole(role_, wallet_);
}
//============================================================================================//
// ADMIN FUNCTIONS //
//============================================================================================//
function pushNewAdmin(address newAdmin_) external onlyAdmin {
newAdmin = newAdmin_;
emit NewAdminPushed(newAdmin_);
}
function pullNewAdmin() external {
if (msg.sender != newAdmin) revert Roles_OnlyNewAdmin();
admin = newAdmin;
newAdmin = address(0);
emit NewAdminPulled(admin);
}
}