/
Admin.sol
127 lines (103 loc) · 5.63 KB
/
Admin.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
// SPDX-License-Identifier: MIT
pragma solidity 0.8.20;
import "../interfaces/IAdmin.sol";
import "../libraries/Diamond.sol";
import {L2_TX_MAX_GAS_LIMIT} from "../Config.sol";
import "./Base.sol";
/// @title Admin Contract controls access rights for contract management.
/// @author Matter Labs
/// @custom:security-contact security@matterlabs.dev
contract AdminFacet is Base, IAdmin {
string public constant override getName = "AdminFacet";
/// @notice Starts the transfer of governor rights. Only the current governor can propose a new pending one.
/// @notice New governor can accept governor rights by calling `acceptGovernor` function.
/// @param _newPendingGovernor Address of the new governor
function setPendingGovernor(address _newPendingGovernor) external onlyGovernor {
// Save previous value into the stack to put it into the event later
address oldPendingGovernor = s.pendingGovernor;
// Change pending governor
s.pendingGovernor = _newPendingGovernor;
emit NewPendingGovernor(oldPendingGovernor, _newPendingGovernor);
}
/// @notice Accepts transfer of governor rights. Only pending governor can accept the role.
function acceptGovernor() external {
address pendingGovernor = s.pendingGovernor;
require(msg.sender == pendingGovernor, "n4"); // Only proposed by current governor address can claim the governor rights
address previousGovernor = s.governor;
s.governor = pendingGovernor;
delete s.pendingGovernor;
emit NewPendingGovernor(pendingGovernor, address(0));
emit NewGovernor(previousGovernor, pendingGovernor);
}
/// @notice Starts the transfer of admin rights. Only the current governor or admin can propose a new pending one.
/// @notice New admin can accept admin rights by calling `acceptAdmin` function.
/// @param _newPendingAdmin Address of the new admin
function setPendingAdmin(address _newPendingAdmin) external onlyGovernor {
// Save previous value into the stack to put it into the event later
address oldPendingAdmin = s.pendingAdmin;
// Change pending admin
s.pendingAdmin = _newPendingAdmin;
emit NewPendingAdmin(oldPendingAdmin, _newPendingAdmin);
}
/// @notice Accepts transfer of admin rights. Only pending admin can accept the role.
function acceptAdmin() external {
address pendingAdmin = s.pendingAdmin;
require(msg.sender == pendingAdmin, "n4"); // Only proposed by current admin address can claim the admin rights
address previousAdmin = s.admin;
s.admin = pendingAdmin;
delete s.pendingAdmin;
emit NewPendingAdmin(pendingAdmin, address(0));
emit NewAdmin(previousAdmin, pendingAdmin);
}
/// @notice Change validator status (active or not active)
/// @param _validator Validator address
/// @param _active Active flag
function setValidator(address _validator, bool _active) external onlyGovernorOrAdmin {
s.validators[_validator] = _active;
emit ValidatorStatusUpdate(_validator, _active);
}
/// @notice Change zk porter availability
/// @param _zkPorterIsAvailable The availability of zk porter shard
function setPorterAvailability(bool _zkPorterIsAvailable) external onlyGovernor {
// Change the porter availability
s.zkPorterIsAvailable = _zkPorterIsAvailable;
emit IsPorterAvailableStatusUpdate(_zkPorterIsAvailable);
}
/// @notice Change the max L2 gas limit for L1 -> L2 transactions
/// @param _newPriorityTxMaxGasLimit The maximum number of L2 gas that a user can request for L1 -> L2 transactions
function setPriorityTxMaxGasLimit(uint256 _newPriorityTxMaxGasLimit) external onlyGovernor {
require(_newPriorityTxMaxGasLimit <= L2_TX_MAX_GAS_LIMIT, "n5");
uint256 oldPriorityTxMaxGasLimit = s.priorityTxMaxGasLimit;
s.priorityTxMaxGasLimit = _newPriorityTxMaxGasLimit;
emit NewPriorityTxMaxGasLimit(oldPriorityTxMaxGasLimit, _newPriorityTxMaxGasLimit);
}
/*//////////////////////////////////////////////////////////////
UPGRADE EXECUTION
//////////////////////////////////////////////////////////////*/
/// @notice Executes a proposed governor upgrade
/// @dev Only the current governor can execute the upgrade
/// @param _diamondCut The diamond cut parameters to be executed
function executeUpgrade(Diamond.DiamondCutData calldata _diamondCut) external onlyGovernor {
Diamond.diamondCut(_diamondCut);
emit ExecuteUpgrade(_diamondCut);
}
/*//////////////////////////////////////////////////////////////
CONTRACT FREEZING
//////////////////////////////////////////////////////////////*/
/// @notice Instantly pause the functionality of all freezable facets & their selectors
/// @dev Only the governance mechanism may freeze Diamond Proxy
function freezeDiamond() external onlyGovernor {
Diamond.DiamondStorage storage diamondStorage = Diamond.getDiamondStorage();
require(!diamondStorage.isFrozen, "a9"); // diamond proxy is frozen already
diamondStorage.isFrozen = true;
emit Freeze();
}
/// @notice Unpause the functionality of all freezable facets & their selectors
/// @dev Both the governor and its owner can unfreeze Diamond Proxy
function unfreezeDiamond() external onlyGovernorOrAdmin {
Diamond.DiamondStorage storage diamondStorage = Diamond.getDiamondStorage();
require(diamondStorage.isFrozen, "a7"); // diamond proxy is not frozen
diamondStorage.isFrozen = false;
emit Unfreeze();
}
}