|
| 1 | +// SPDX-License-Identifier: BUSL-1.1 |
| 2 | +pragma solidity ^0.8.12; |
| 3 | + |
| 4 | +import {EOADeployer} from "zeus-templates/templates/EOADeployer.sol"; |
| 5 | +import "../Env.sol"; |
| 6 | + |
| 7 | +import "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; |
| 8 | +import "@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol"; |
| 9 | +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; |
| 10 | + |
| 11 | +/** |
| 12 | + * Purpose: use an EOA to deploy all of the new contracts for this upgrade. |
| 13 | + */ |
| 14 | +contract Deploy is EOADeployer { |
| 15 | + using Env for *; |
| 16 | + |
| 17 | + /// forgefmt: disable-next-item |
| 18 | + function _runAsEOA() internal override { |
| 19 | + vm.startBroadcast(); |
| 20 | + |
| 21 | + |
| 22 | + // We are upgrading 1 contract: EigenPod |
| 23 | + deployImpl({ |
| 24 | + name: type(EigenPod).name, |
| 25 | + deployedTo: address( |
| 26 | + new EigenPod({ |
| 27 | + _ethPOS: Env.ethPOS(), |
| 28 | + _eigenPodManager: Env.proxy.eigenPodManager(), |
| 29 | + _version: Env.deployVersion() |
| 30 | + }) |
| 31 | + ) |
| 32 | + }); |
| 33 | + |
| 34 | + vm.stopBroadcast(); |
| 35 | + } |
| 36 | + |
| 37 | + function testScript() public virtual { |
| 38 | + super.runAsEOA(); |
| 39 | + |
| 40 | + _validateNewImplAddresses({areMatching: false}); |
| 41 | + _validateProxyAdmins(); |
| 42 | + _validateImplConstructors(); |
| 43 | + _validateImplsInitialized(); |
| 44 | + _validateVersion(); |
| 45 | + } |
| 46 | + |
| 47 | + /// @dev Validate that the `Env.impl` addresses are updated to be distinct from what the proxy |
| 48 | + /// admin reports as the current implementation address. |
| 49 | + /// |
| 50 | + /// Note: The upgrade script can call this with `areMatching == true` to check that these impl |
| 51 | + /// addresses _are_ matches. |
| 52 | + function _validateNewImplAddresses( |
| 53 | + bool areMatching |
| 54 | + ) internal view { |
| 55 | + function (bool, string memory) internal pure assertion = areMatching ? _assertTrue : _assertFalse; |
| 56 | + |
| 57 | + assertion(Env.beacon.eigenPod().implementation() == address(Env.impl.eigenPod()), "eigenPod impl failed"); |
| 58 | + } |
| 59 | + |
| 60 | + /// @dev Ensure each deployed TUP/beacon is owned by the proxyAdmin/executorMultisig |
| 61 | + function _validateProxyAdmins() internal view { |
| 62 | + assertTrue(Env.beacon.eigenPod().owner() == Env.executorMultisig(), "eigenPod beacon owner incorrect"); |
| 63 | + } |
| 64 | + |
| 65 | + /// @dev Validate the immutables set in the new implementation constructors |
| 66 | + function _validateImplConstructors() internal view { |
| 67 | + { |
| 68 | + /// EigenPod |
| 69 | + EigenPod eigenPod = Env.impl.eigenPod(); |
| 70 | + assertTrue(eigenPod.ethPOS() == Env.ethPOS(), "ep.ethPOS invalid"); |
| 71 | + assertTrue(eigenPod.eigenPodManager() == Env.proxy.eigenPodManager(), "ep.epm invalid"); |
| 72 | + assertTrue(_strEq(eigenPod.version(), Env.deployVersion()), "ep.version failed"); |
| 73 | + } |
| 74 | + } |
| 75 | + |
| 76 | + /// @dev Call initialize on all deployed implementations to ensure initializers are disabled |
| 77 | + function _validateImplsInitialized() internal { |
| 78 | + bytes memory errInit = "Initializable: contract is already initialized"; |
| 79 | + |
| 80 | + /// EigenPod |
| 81 | + EigenPod eigenPod = Env.impl.eigenPod(); |
| 82 | + vm.expectRevert(errInit); |
| 83 | + eigenPod.initialize(address(0)); |
| 84 | + } |
| 85 | + |
| 86 | + function _validateVersion() internal view { |
| 87 | + // On future upgrades, just tick the major/minor/patch to validate |
| 88 | + string memory expected = Env.deployVersion(); |
| 89 | + |
| 90 | + assertEq(Env.impl.eigenPod().version(), expected, "eigenPod version mismatch"); |
| 91 | + } |
| 92 | + |
| 93 | + /// @dev Query and return `proxyAdmin.getProxyImplementation(proxy)` |
| 94 | + function _getProxyImpl( |
| 95 | + address proxy |
| 96 | + ) internal view returns (address) { |
| 97 | + return ProxyAdmin(Env.proxyAdmin()).getProxyImplementation(ITransparentUpgradeableProxy(proxy)); |
| 98 | + } |
| 99 | + |
| 100 | + /// @dev Query and return `proxyAdmin.getProxyAdmin(proxy)` |
| 101 | + function _getProxyAdmin( |
| 102 | + address proxy |
| 103 | + ) internal view returns (address) { |
| 104 | + return ProxyAdmin(Env.proxyAdmin()).getProxyAdmin(ITransparentUpgradeableProxy(proxy)); |
| 105 | + } |
| 106 | + |
| 107 | + function _assertTrue(bool b, string memory err) private pure { |
| 108 | + assertTrue(b, err); |
| 109 | + } |
| 110 | + |
| 111 | + function _assertFalse(bool b, string memory err) private pure { |
| 112 | + assertFalse(b, err); |
| 113 | + } |
| 114 | + |
| 115 | + function _strEq(string memory a, string memory b) private pure returns (bool) { |
| 116 | + return keccak256(bytes(a)) == keccak256(bytes(b)); |
| 117 | + } |
| 118 | +} |
0 commit comments