|
| 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 | + function _runAsEOA() internal override { |
| 18 | + vm.startBroadcast(); |
| 19 | + |
| 20 | + // We are upgrading 2 contracts: AllocationManager and DelegationManager |
| 21 | + deployImpl({ |
| 22 | + name: type(AllocationManager).name, |
| 23 | + deployedTo: address( |
| 24 | + new AllocationManager({ |
| 25 | + _delegation: Env.proxy.delegationManager(), |
| 26 | + _pauserRegistry: Env.impl.pauserRegistry(), |
| 27 | + _permissionController: Env.proxy.permissionController(), |
| 28 | + _DEALLOCATION_DELAY: Env.MIN_WITHDRAWAL_DELAY(), |
| 29 | + _ALLOCATION_CONFIGURATION_DELAY: Env.ALLOCATION_CONFIGURATION_DELAY(), |
| 30 | + _version: Env.deployVersion() |
| 31 | + }) |
| 32 | + ) |
| 33 | + }); |
| 34 | + |
| 35 | + deployImpl({ |
| 36 | + name: type(DelegationManager).name, |
| 37 | + deployedTo: address( |
| 38 | + new DelegationManager({ |
| 39 | + _strategyManager: Env.proxy.strategyManager(), |
| 40 | + _eigenPodManager: Env.proxy.eigenPodManager(), |
| 41 | + _allocationManager: Env.proxy.allocationManager(), |
| 42 | + _pauserRegistry: Env.impl.pauserRegistry(), |
| 43 | + _permissionController: Env.proxy.permissionController(), |
| 44 | + _MIN_WITHDRAWAL_DELAY: Env.MIN_WITHDRAWAL_DELAY(), |
| 45 | + _version: Env.deployVersion() |
| 46 | + }) |
| 47 | + ) |
| 48 | + }); |
| 49 | + |
| 50 | + vm.stopBroadcast(); |
| 51 | + } |
| 52 | + |
| 53 | + function testScript() public virtual { |
| 54 | + _runAsEOA(); |
| 55 | + |
| 56 | + _validateNewImplAddresses({areMatching: false}); |
| 57 | + _validateProxyAdmins(); |
| 58 | + _validateImplConstructors(); |
| 59 | + _validateImplsInitialized(); |
| 60 | + _validateVersion(); |
| 61 | + |
| 62 | + // Validate that ALLOCATION_CONFIGURATION_DELAY is set to 30 |
| 63 | + assertEq(Env.ALLOCATION_CONFIGURATION_DELAY(), 30, "ALLOCATION_CONFIGURATION_DELAY should be 30"); |
| 64 | + |
| 65 | + // Validate that MIN_WITHDRAWAL_DELAY is set to 25 |
| 66 | + assertEq(Env.MIN_WITHDRAWAL_DELAY(), 25, "MIN_WITHDRAWAL_DELAY should be 25"); |
| 67 | + } |
| 68 | + |
| 69 | + /// @dev Validate that the `Env.impl` addresses are updated to be distinct from what the proxy |
| 70 | + /// admin reports as the current implementation address. |
| 71 | + /// |
| 72 | + /// Note: The upgrade script can call this with `areMatching == true` to check that these impl |
| 73 | + /// addresses _are_ matches. |
| 74 | + function _validateNewImplAddresses( |
| 75 | + bool areMatching |
| 76 | + ) internal view { |
| 77 | + /// core/ |
| 78 | + |
| 79 | + function (bool, string memory) internal pure assertion = areMatching ? _assertTrue : _assertFalse; |
| 80 | + |
| 81 | + assertion( |
| 82 | + _getProxyImpl(address(Env.proxy.allocationManager())) == address(Env.impl.allocationManager()), |
| 83 | + "allocationManager impl failed" |
| 84 | + ); |
| 85 | + |
| 86 | + assertion( |
| 87 | + _getProxyImpl(address(Env.proxy.delegationManager())) == address(Env.impl.delegationManager()), |
| 88 | + "delegationManager impl failed" |
| 89 | + ); |
| 90 | + } |
| 91 | + |
| 92 | + /// @dev Ensure each deployed TUP/beacon is owned by the proxyAdmin/executorMultisig |
| 93 | + function _validateProxyAdmins() internal view { |
| 94 | + address pa = Env.proxyAdmin(); |
| 95 | + |
| 96 | + assertTrue( |
| 97 | + _getProxyAdmin(address(Env.proxy.allocationManager())) == pa, "allocationManager proxyAdmin incorrect" |
| 98 | + ); |
| 99 | + |
| 100 | + assertTrue( |
| 101 | + _getProxyAdmin(address(Env.proxy.delegationManager())) == pa, "delegationManager proxyAdmin incorrect" |
| 102 | + ); |
| 103 | + } |
| 104 | + |
| 105 | + /// @dev Validate the immutables set in the new implementation constructors |
| 106 | + function _validateImplConstructors() internal view { |
| 107 | + AllocationManager allocationManager = Env.impl.allocationManager(); |
| 108 | + assertTrue(allocationManager.delegation() == Env.proxy.delegationManager(), "am.dm invalid"); |
| 109 | + assertTrue(allocationManager.pauserRegistry() == Env.impl.pauserRegistry(), "am.pr invalid"); |
| 110 | + assertTrue(allocationManager.permissionController() == Env.proxy.permissionController(), "am.pc invalid"); |
| 111 | + assertTrue(allocationManager.DEALLOCATION_DELAY() == Env.MIN_WITHDRAWAL_DELAY(), "am.deallocDelay invalid"); |
| 112 | + assertTrue( |
| 113 | + allocationManager.ALLOCATION_CONFIGURATION_DELAY() == Env.ALLOCATION_CONFIGURATION_DELAY(), |
| 114 | + "am.configDelay invalid" |
| 115 | + ); |
| 116 | + |
| 117 | + DelegationManager delegation = Env.impl.delegationManager(); |
| 118 | + assertTrue(delegation.strategyManager() == Env.proxy.strategyManager(), "dm.sm invalid"); |
| 119 | + assertTrue(delegation.eigenPodManager() == Env.proxy.eigenPodManager(), "dm.epm invalid"); |
| 120 | + assertTrue(delegation.allocationManager() == Env.proxy.allocationManager(), "dm.alm invalid"); |
| 121 | + assertTrue(delegation.pauserRegistry() == Env.impl.pauserRegistry(), "dm.pR invalid"); |
| 122 | + assertTrue(delegation.permissionController() == Env.proxy.permissionController(), "dm.pc invalid"); |
| 123 | + assertTrue(delegation.minWithdrawalDelayBlocks() == Env.MIN_WITHDRAWAL_DELAY(), "dm.withdrawalDelay invalid"); |
| 124 | + } |
| 125 | + |
| 126 | + /// @dev Call initialize on all deployed implementations to ensure initializers are disabled |
| 127 | + function _validateImplsInitialized() internal { |
| 128 | + bytes memory errInit = "Initializable: contract is already initialized"; |
| 129 | + |
| 130 | + AllocationManager allocationManager = Env.impl.allocationManager(); |
| 131 | + vm.expectRevert(errInit); |
| 132 | + allocationManager.initialize(address(0), 0); |
| 133 | + |
| 134 | + DelegationManager delegation = Env.impl.delegationManager(); |
| 135 | + vm.expectRevert(errInit); |
| 136 | + delegation.initialize(address(0), 0); |
| 137 | + } |
| 138 | + |
| 139 | + function _validateVersion() internal view { |
| 140 | + // On future upgrades, just tick the major/minor/patch to validate |
| 141 | + string memory expected = Env.deployVersion(); |
| 142 | + |
| 143 | + assertEq(Env.impl.allocationManager().version(), expected, "allocationManager version mismatch"); |
| 144 | + assertEq(Env.impl.delegationManager().version(), expected, "delegationManager version mismatch"); |
| 145 | + } |
| 146 | + |
| 147 | + /// @dev Query and return `proxyAdmin.getProxyImplementation(proxy)` |
| 148 | + function _getProxyImpl( |
| 149 | + address proxy |
| 150 | + ) internal view returns (address) { |
| 151 | + return ProxyAdmin(Env.proxyAdmin()).getProxyImplementation(ITransparentUpgradeableProxy(proxy)); |
| 152 | + } |
| 153 | + |
| 154 | + /// @dev Query and return `proxyAdmin.getProxyAdmin(proxy)` |
| 155 | + function _getProxyAdmin( |
| 156 | + address proxy |
| 157 | + ) internal view returns (address) { |
| 158 | + return ProxyAdmin(Env.proxyAdmin()).getProxyAdmin(ITransparentUpgradeableProxy(proxy)); |
| 159 | + } |
| 160 | + |
| 161 | + function _assertTrue(bool b, string memory err) private pure { |
| 162 | + assertTrue(b, err); |
| 163 | + } |
| 164 | + |
| 165 | + function _assertFalse(bool b, string memory err) private pure { |
| 166 | + assertFalse(b, err); |
| 167 | + } |
| 168 | +} |
0 commit comments