129 lines
5.8 KiB
Solidity
129 lines
5.8 KiB
Solidity
// SPDX-License-Identifier: MIT
|
|
|
|
pragma solidity ^0.8.13;
|
|
|
|
import "../interfaces/IAdmin.sol";
|
|
import "../libraries/Diamond.sol";
|
|
import "../../common/libraries/L2ContractHelper.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 onlyGovernorOrAdmin {
|
|
// Save previous value into the stack to put it into the event later
|
|
address oldPendingAdmin = s.pendingAdmin;
|
|
// Change pending admin
|
|
s.pendingAdmin = _newPendingAdmin;
|
|
emit NewPendingGovernor(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();
|
|
}
|
|
}
|