Skip to content

Commit

Permalink
contracts-bedrock: Add deployERC1967ProxyWithOwner and transferProxyT…
Browse files Browse the repository at this point in the history
…oProxyAdmin (ethereum-optimism#9107)

This new method provides the option of setting the owner to a temporary deployer address.
  • Loading branch information
maurelian authored Jan 19, 2024
1 parent c6eb757 commit 77a5c85
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions packages/contracts-bedrock/scripts/Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,17 @@ contract Deploy is Deployer {
}
}

/// @notice Transfer ownership of a Proxy to the ProxyAdmin contract
/// This is expected to be used in conjusting with deployERC1967ProxyWithOwner after setup actions
/// have been performed on the proxy.
/// @param _name The name of the proxy to transfer ownership of.
function transferProxyToProxyAdmin(string memory _name) public broadcast {
Proxy proxy = Proxy(mustGetAddress(_name));
address proxyAdmin = mustGetAddress("ProxyAdmin");
proxy.changeAdmin(proxyAdmin);
console.log("Proxy %s ownership transferred to ProxyAdmin at: %s", _name, proxyAdmin);
}

////////////////////////////////////////////////////////////////
// SetUp and Run //
////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -432,12 +443,22 @@ contract Deploy is Deployer {
addr_ = address(proxy);
}

/// @notice Deploys an ERC1967Proxy contract with the ProxyAdmin as the owner.
/// @param _name The name of the proxy contract to be deployed.
/// @return addr_ The address of the deployed proxy contract.
function deployERC1967Proxy(string memory _name) public broadcast returns (address addr_) {
console.log(string.concat("Deploying ERC1967 proxy for", _name, ""));
address proxyAdmin = mustGetAddress("ProxyAdmin");
Proxy proxy = new Proxy({ _admin: proxyAdmin });
addr_ = deployERC1967ProxyWithOwner(_name, mustGetAddress("ProxyAdmin"));
}

require(EIP1967Helper.getAdmin(address(proxy)) == proxyAdmin);
/// @notice Deploys an ERC1967Proxy contract with a specified owner.
/// @param _name The name of the proxy contract to be deployed.
/// @param _proxyOwner The address of the owner of the proxy contract.
/// @return addr_ The address of the deployed proxy contract.
function deployERC1967ProxyWithOwner(string memory _name, address _proxyOwner) public returns (address addr_) {
console.log(string.concat("Deploying ERC1967 proxy for ", _name));
Proxy proxy = new Proxy({ _admin: _proxyOwner });

require(EIP1967Helper.getAdmin(address(proxy)) == _proxyOwner);

save(_name, address(proxy));
console.log(" at %s", address(proxy));
Expand Down

0 comments on commit 77a5c85

Please sign in to comment.