|
| 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 | +import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol"; |
| 11 | +import "src/contracts/libraries/BeaconChainProofs.sol"; |
| 12 | + |
| 13 | +contract Deploy is EOADeployer { |
| 14 | + using Env for *; |
| 15 | + |
| 16 | + function _runAsEOA() internal override { |
| 17 | + vm.startBroadcast(); |
| 18 | + |
| 19 | + // Deploy EigenPodManager Impl |
| 20 | + deployImpl({ |
| 21 | + name: type(EigenPodManager).name, |
| 22 | + deployedTo: address(new EigenPodManager({ |
| 23 | + _ethPOS: Env.ethPOS(), |
| 24 | + _eigenPodBeacon: Env.beacon.eigenPod(), |
| 25 | + _delegationManager: Env.proxy.delegationManager(), |
| 26 | + _pauserRegistry: Env.impl.pauserRegistry(), |
| 27 | + _version: "v1.2.0" |
| 28 | + })) |
| 29 | + }); |
| 30 | + |
| 31 | + // Deploy EigenPodBeacon Impl |
| 32 | + deployImpl({ |
| 33 | + name: type(EigenPod).name, |
| 34 | + deployedTo: address(new EigenPod({ |
| 35 | + _ethPOS: Env.ethPOS(), |
| 36 | + _eigenPodManager: Env.proxy.eigenPodManager(), |
| 37 | + _GENESIS_TIME: Env.EIGENPOD_GENESIS_TIME(), |
| 38 | + _version: "v1.2.0" |
| 39 | + })) |
| 40 | + }); |
| 41 | + |
| 42 | + vm.stopBroadcast(); |
| 43 | + } |
| 44 | + |
| 45 | + function testDeploy() public virtual { |
| 46 | + _runAsEOA(); |
| 47 | + _validateNewImplAddresses(false); |
| 48 | + _validateProxyAdmins(); |
| 49 | + _validateImplConstructors(); |
| 50 | + _validateImplsInitialized(); |
| 51 | + } |
| 52 | + |
| 53 | + /// @dev Validate that the `Env.impl` addresses are updated to be distinct from what the proxy |
| 54 | + /// admin reports as the current implementation address. |
| 55 | + /// |
| 56 | + /// Note: The upgrade script can call this with `areMatching == true` to check that these impl |
| 57 | + /// addresses _are_ matches. |
| 58 | + function _validateNewImplAddresses(bool areMatching) internal view { |
| 59 | + function(address, address, string memory) |
| 60 | + internal |
| 61 | + pure assertion = areMatching ? _assertMatch : _assertNotMatch; |
| 62 | + |
| 63 | + assertion( |
| 64 | + Env.beacon.eigenPod().implementation(), |
| 65 | + address(Env.impl.eigenPod()), |
| 66 | + "eigenPod impl failed" |
| 67 | + ); |
| 68 | + |
| 69 | + assertion( |
| 70 | + _getProxyImpl(address(Env.proxy.eigenPodManager())), |
| 71 | + address(Env.impl.eigenPodManager()), |
| 72 | + "eigenPodManager impl failed" |
| 73 | + ); |
| 74 | + } |
| 75 | + |
| 76 | + /// @dev Ensure each deployed TUP/beacon is owned by the proxyAdmin/executorMultisig |
| 77 | + function _validateProxyAdmins() internal view { |
| 78 | + assertTrue( |
| 79 | + Env.beacon.eigenPod().owner() == Env.executorMultisig(), |
| 80 | + "eigenPod beacon owner incorrect" |
| 81 | + ); |
| 82 | + |
| 83 | + assertTrue( |
| 84 | + _getProxyAdmin(address(Env.proxy.eigenPodManager())) == Env.proxyAdmin(), |
| 85 | + "eigenPodManager proxyAdmin incorrect" |
| 86 | + ); |
| 87 | + } |
| 88 | + |
| 89 | + /// @dev Validate the immutables set in the new implementation constructors |
| 90 | + function _validateImplConstructors() internal view { |
| 91 | + /// pods/ |
| 92 | + EigenPod eigenPod = Env.impl.eigenPod(); |
| 93 | + assertTrue(eigenPod.ethPOS() == Env.ethPOS(), "ep.ethPOS invalid"); |
| 94 | + assertTrue(eigenPod.eigenPodManager() == Env.proxy.eigenPodManager(), "ep.epm invalid"); |
| 95 | + assertTrue(eigenPod.GENESIS_TIME() == Env.EIGENPOD_GENESIS_TIME(), "ep.genesis invalid"); |
| 96 | + |
| 97 | + /// manager/ |
| 98 | + EigenPodManager eigenPodManager = Env.impl.eigenPodManager(); |
| 99 | + assertTrue(eigenPodManager.ethPOS() == Env.ethPOS(), "epm.ethPOS invalid"); |
| 100 | + assertTrue(eigenPodManager.eigenPodBeacon() == Env.beacon.eigenPod(), "epm.epBeacon invalid"); |
| 101 | + assertTrue(eigenPodManager.delegationManager() == Env.proxy.delegationManager(), "epm.dm invalid"); |
| 102 | + assertTrue(eigenPodManager.pauserRegistry() == Env.impl.pauserRegistry(), "epm.pR invalid"); |
| 103 | + } |
| 104 | + |
| 105 | + function _validateImplsInitialized() internal { |
| 106 | + bytes memory errInit = "Initializable: contract is already initialized"; |
| 107 | + |
| 108 | + EigenPod eigenPod = Env.impl.eigenPod(); |
| 109 | + vm.expectRevert(errInit); |
| 110 | + eigenPod.initialize(address(0)); |
| 111 | + |
| 112 | + EigenPodManager eigenPodManager = Env.impl.eigenPodManager(); |
| 113 | + vm.expectRevert(errInit); |
| 114 | + eigenPodManager.initialize(address(0), 0); |
| 115 | + } |
| 116 | + |
| 117 | + /// @dev Query and return `proxyAdmin.getProxyImplementation(proxy)` |
| 118 | + function _getProxyImpl(address proxy) internal view returns (address) { |
| 119 | + return |
| 120 | + ProxyAdmin(Env.proxyAdmin()).getProxyImplementation( |
| 121 | + ITransparentUpgradeableProxy(proxy) |
| 122 | + ); |
| 123 | + } |
| 124 | + |
| 125 | + /// @dev Query and return `proxyAdmin.getProxyAdmin(proxy)` |
| 126 | + function _getProxyAdmin(address proxy) internal view returns (address) { |
| 127 | + return |
| 128 | + ProxyAdmin(Env.proxyAdmin()).getProxyAdmin( |
| 129 | + ITransparentUpgradeableProxy(proxy) |
| 130 | + ); |
| 131 | + } |
| 132 | + |
| 133 | + function _assertMatch( |
| 134 | + address a, |
| 135 | + address b, |
| 136 | + string memory err |
| 137 | + ) private pure { |
| 138 | + assertEq(a, b, err); |
| 139 | + } |
| 140 | + |
| 141 | + function _assertNotMatch( |
| 142 | + address a, |
| 143 | + address b, |
| 144 | + string memory err |
| 145 | + ) private pure { |
| 146 | + assertNotEq(a, b, err); |
| 147 | + } |
| 148 | +} |
0 commit comments