github.com/ethereum-optimism/optimism@v1.7.2/packages/contracts-bedrock/src/L1/SuperchainConfig.sol (about) 1 // SPDX-License-Identifier: MIT 2 pragma solidity 0.8.15; 3 4 import { Initializable } from "@openzeppelin/contracts/proxy/utils/Initializable.sol"; 5 import { ISemver } from "src/universal/ISemver.sol"; 6 import { Storage } from "src/libraries/Storage.sol"; 7 8 /// @custom:audit none This contracts is not yet audited. 9 /// @title SuperchainConfig 10 /// @notice The SuperchainConfig contract is used to manage configuration of global superchain values. 11 contract SuperchainConfig is Initializable, ISemver { 12 /// @notice Enum representing different types of updates. 13 /// @custom:value GUARDIAN Represents an update to the guardian. 14 enum UpdateType { 15 GUARDIAN 16 } 17 18 /// @notice Whether or not the Superchain is paused. 19 bytes32 public constant PAUSED_SLOT = bytes32(uint256(keccak256("superchainConfig.paused")) - 1); 20 21 /// @notice The address of the guardian, which can pause withdrawals from the System. 22 /// It can only be modified by an upgrade. 23 bytes32 public constant GUARDIAN_SLOT = bytes32(uint256(keccak256("superchainConfig.guardian")) - 1); 24 25 /// @notice Emitted when the pause is triggered. 26 /// @param identifier A string helping to identify provenance of the pause transaction. 27 event Paused(string identifier); 28 29 /// @notice Emitted when the pause is lifted. 30 event Unpaused(); 31 32 /// @notice Emitted when configuration is updated. 33 /// @param updateType Type of update. 34 /// @param data Encoded update data. 35 event ConfigUpdate(UpdateType indexed updateType, bytes data); 36 37 /// @notice Semantic version. 38 /// @custom:semver 1.1.0 39 string public constant version = "1.1.0"; 40 41 /// @notice Constructs the SuperchainConfig contract. 42 constructor() { 43 initialize({ _guardian: address(0), _paused: false }); 44 } 45 46 /// @notice Initializer. 47 /// @param _guardian Address of the guardian, can pause the OptimismPortal. 48 /// @param _paused Initial paused status. 49 function initialize(address _guardian, bool _paused) public initializer { 50 _setGuardian(_guardian); 51 if (_paused) { 52 _pause("Initializer paused"); 53 } 54 } 55 56 /// @notice Getter for the guardian address. 57 function guardian() public view returns (address guardian_) { 58 guardian_ = Storage.getAddress(GUARDIAN_SLOT); 59 } 60 61 /// @notice Getter for the current paused status. 62 function paused() public view returns (bool paused_) { 63 paused_ = Storage.getBool(PAUSED_SLOT); 64 } 65 66 /// @notice Pauses withdrawals. 67 /// @param _identifier (Optional) A string to identify provenance of the pause transaction. 68 function pause(string memory _identifier) external { 69 require(msg.sender == guardian(), "SuperchainConfig: only guardian can pause"); 70 _pause(_identifier); 71 } 72 73 /// @notice Pauses withdrawals. 74 /// @param _identifier (Optional) A string to identify provenance of the pause transaction. 75 function _pause(string memory _identifier) internal { 76 Storage.setBool(PAUSED_SLOT, true); 77 emit Paused(_identifier); 78 } 79 80 /// @notice Unpauses withdrawals. 81 function unpause() external { 82 require(msg.sender == guardian(), "SuperchainConfig: only guardian can unpause"); 83 Storage.setBool(PAUSED_SLOT, false); 84 emit Unpaused(); 85 } 86 87 /// @notice Sets the guardian address. This is only callable during initialization, so an upgrade 88 /// will be required to change the guardian. 89 /// @param _guardian The new guardian address. 90 function _setGuardian(address _guardian) internal { 91 Storage.setAddress(GUARDIAN_SLOT, _guardian); 92 emit ConfigUpdate(UpdateType.GUARDIAN, abi.encode(_guardian)); 93 } 94 }