-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathGovernable.sol
68 lines (60 loc) · 2.05 KB
/
Governable.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
// SPDX-License-Identifier: AGPL-3.0-or-later
pragma solidity 0.8.17;
/**
* @title Governable
* @author mStable
* @notice Simple contract implementing an Ownable pattern.
* @dev Derives from V2.3.0 @openzeppelin/contracts/ownership/Ownable.sol
* Modified to have custom name and features
* - Removed `renounceOwnership`
* - Changes `_owner` to `_governor`
* VERSION: 1.1
* DATE: 2021-04-15
*/
contract Governable {
event GovernorChanged(address indexed previousGovernor, address indexed newGovernor);
address private _governor;
/**
* @dev Initializes the contract setting the deployer as the initial Governor.
*/
constructor() {
_governor = msg.sender;
emit GovernorChanged(address(0), _governor);
}
/**
* @dev Returns the address of the current Governor.
*/
function governor() public view virtual returns (address) {
return _governor;
}
/**
* @dev Throws if called by any account other than the Governor.
*/
modifier onlyGovernor() {
require(isGovernor(), "GOV: caller is not the Governor");
_;
}
/**
* @dev Returns true if the caller is the current Governor.
*/
function isGovernor() public view returns (bool) {
return msg.sender == _governor;
}
/**
* @dev Transfers Governance of the contract to a new account (`newGovernor`).
* Can only be called by the current Governor.
* @param _newGovernor Address of the new Governor
*/
function changeGovernor(address _newGovernor) external virtual onlyGovernor {
_changeGovernor(_newGovernor);
}
/**
* @dev Change Governance of the contract to a new account (`newGovernor`).
* @param _newGovernor Address of the new Governor
*/
function _changeGovernor(address _newGovernor) internal {
require(_newGovernor != address(0), "GOV: new Governor is address(0)");
emit GovernorChanged(_governor, _newGovernor);
_governor = _newGovernor;
}
}