DeployerWhitelist.sol 3.63 KB
Newer Older
1
// SPDX-License-Identifier: MIT
2
pragma solidity 0.8.15;
3

4
// Interfaces
5
import { ISemver } from "interfaces/universal/ISemver.sol";
6

7 8
/// @custom:legacy true
/// @custom:proxied true
9 10 11 12 13 14 15
/// @custom:predeployed 0x4200000000000000000000000000000000000002
/// @title DeployerWhitelist
/// @notice DeployerWhitelist is a legacy contract that was originally used to act as a whitelist of
///         addresses allowed to the Optimism network. The DeployerWhitelist has since been
///         disabled, but the code is kept in state for the sake of full backwards compatibility.
///         As of the Bedrock upgrade, the DeployerWhitelist is completely unused by the Optimism
///         system and could, in theory, be removed entirely.
16
contract DeployerWhitelist is ISemver {
17 18
    /// @notice Address of the owner of this contract. Note that when this address is set to
    ///         address(0), the whitelist is disabled.
19 20
    address public owner;

21
    /// @notice Mapping of deployer addresses to boolean whitelist status.
22 23
    mapping(address => bool) public whitelist;

24 25 26
    /// @notice Emitted when the owner of this contract changes.
    /// @param oldOwner Address of the previous owner.
    /// @param newOwner Address of the new owner.
27
    event OwnerChanged(address oldOwner, address newOwner);
28

29 30 31
    /// @notice Emitted when the whitelist status of a deployer changes.
    /// @param deployer    Address of the deployer.
    /// @param whitelisted Boolean indicating whether the deployer is whitelisted.
32 33
    event WhitelistStatusChanged(address deployer, bool whitelisted);

34 35
    /// @notice Emitted when the whitelist is disabled.
    /// @param oldOwner Address of the final owner of the whitelist.
36
    event WhitelistDisabled(address oldOwner);
37

38
    /// @notice Blocks functions to anyone except the contract owner.
39
    modifier onlyOwner() {
40
        require(msg.sender == owner, "DeployerWhitelist: function can only be called by the owner of this contract");
41 42 43
        _;
    }

44
    /// @notice Semantic version.
45 46
    /// @custom:semver 1.1.1-beta.3
    string public constant version = "1.1.1-beta.3";
47

48 49 50
    /// @notice Adds or removes an address from the deployment whitelist.
    /// @param _deployer      Address to update permissions for.
    /// @param _isWhitelisted Whether or not the address is whitelisted.
51 52 53 54 55
    function setWhitelistedDeployer(address _deployer, bool _isWhitelisted) external onlyOwner {
        whitelist[_deployer] = _isWhitelisted;
        emit WhitelistStatusChanged(_deployer, _isWhitelisted);
    }

56 57
    /// @notice Updates the owner of this contract.
    /// @param _owner Address of the new owner.
58
    function setOwner(address _owner) external onlyOwner {
59 60 61
        // Prevent users from setting the whitelist owner to address(0) except via
        // enableArbitraryContractDeployment. If you want to burn the whitelist owner, send it to
        // any other address that doesn't have a corresponding knowable private key.
62
        require(_owner != address(0), "DeployerWhitelist: can only be disabled via enableArbitraryContractDeployment");
63 64 65 66 67

        emit OwnerChanged(owner, _owner);
        owner = _owner;
    }

68
    /// @notice Permanently enables arbitrary contract deployment and deletes the owner.
69 70 71 72 73
    function enableArbitraryContractDeployment() external onlyOwner {
        emit WhitelistDisabled(owner);
        owner = address(0);
    }

74 75 76
    /// @notice Checks whether an address is allowed to deploy contracts.
    /// @param _deployer Address to check.
    /// @return Whether or not the address can deploy contracts.
77 78 79 80
    function isDeployerAllowed(address _deployer) external view returns (bool) {
        return (owner == address(0) || whitelist[_deployer]);
    }
}