-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGoverned.sol
68 lines (54 loc) · 1.96 KB
/
Governed.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: GPL-2.0-or-later
pragma solidity ^0.7.6;
/**
* @title Graph Governance contract
* @dev All contracts that will be owned by a Governor entity should extend this contract.
*/
contract Governed {
// -- State --
address public governor;
address public pendingGovernor;
// -- Events --
event NewPendingOwnership(address indexed from, address indexed to);
event NewOwnership(address indexed from, address indexed to);
/**
* @dev Check if the caller is the governor.
*/
modifier onlyGovernor() {
require(msg.sender == governor, "Only Governor can call");
_;
}
/**
* @dev Initialize the governor to the contract caller.
*/
function _initialize(address _initGovernor) internal {
governor = _initGovernor;
}
/**
* @dev Admin function to begin change of governor. The `_newGovernor` must call
* `acceptOwnership` to finalize the transfer.
* @param _newGovernor Address of new `governor`
*/
function transferOwnership(address _newGovernor) external onlyGovernor {
require(_newGovernor != address(0), "Governor must be set");
address oldPendingGovernor = pendingGovernor;
pendingGovernor = _newGovernor;
emit NewPendingOwnership(oldPendingGovernor, pendingGovernor);
}
/**
* @dev Admin function for pending governor to accept role and update governor.
* This function must called by the pending governor.
*/
function acceptOwnership() external {
require(
pendingGovernor != address(0) && msg.sender == pendingGovernor,
"Caller must be pending governor"
);
address oldGovernor = governor;
address oldPendingGovernor = pendingGovernor;
governor = pendingGovernor;
pendingGovernor = address(0);
emit NewOwnership(oldGovernor, governor);
emit NewPendingOwnership(oldPendingGovernor, pendingGovernor);
}
}