all files / facade/ DeployerRegistry.sol

100% Statements 7/7
100% Branches 10/10
100% Functions 3/3
100% Lines 10/10
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                                      18×                                            
// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.17;
 
import "@openzeppelin/contracts/access/Ownable.sol";
import "../interfaces/IDeployerRegistry.sol";
 
/**
 * @title DeployerRegistry
 * @notice A tiny contract for tracking deployments over time, from an EOA.
 * @dev Does not allow overwriting without deregistration
 */
contract DeployerRegistry is IDeployerRegistry, Ownable {
    string public constant ENS = "reserveprotocol.eth";
 
    mapping(string => IDeployer) public deployments;
 
    IDeployer public override latestDeployment;
 
    constructor(address owner_) Ownable() {
        _transferOwnership(owner_);
    }
 
    /// Register a deployer address, keyed by a version.
    /// @dev Does not allow overwriting without deregistration
    /// @param version A semver version string
    /// @param makeLatest True iff this deployment should be promoted to be the latest deployment
    function register(
        string calldata version,
        IDeployer deployer,
        bool makeLatest
    ) external onlyOwner {
        require(address(deployer) != address(0), "deployer is zero addr");
        require(address(deployments[version]) == address(0), "cannot overwrite");
 
        emit DeploymentRegistered(version, deployer);
 
        deployments[version] = deployer;
 
        if (makeLatest) {
            emit LatestChanged(version, deployer);
            latestDeployment = deployer;
        }
    }
 
    /// Unregister by version
    function unregister(string calldata version) external onlyOwner {
        emit DeploymentUnregistered(version, deployments[version]);
        deployments[version] = IDeployer(address(0));
    }
}