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+
12+ // Just upgrade StrategyManager
13+ contract Deploy is EOADeployer {
14+ using Env for * ;
15+
16+ function _runAsEOA () internal override {
17+ vm.startBroadcast ();
18+
19+ // Deploy DM
20+ deployImpl ({
21+ name: type (DelegationManager).name,
22+ deployedTo: address (new DelegationManager ({
23+ _strategyManager: Env.proxy.strategyManager (),
24+ _eigenPodManager: Env.proxy.eigenPodManager (),
25+ _allocationManager: Env.proxy.allocationManager (),
26+ _pauserRegistry: Env.impl.pauserRegistry (),
27+ _permissionController: Env.proxy.permissionController (),
28+ _MIN_WITHDRAWAL_DELAY: Env.MIN_WITHDRAWAL_DELAY ()
29+ }))
30+ });
31+
32+ // Deploy AVSD
33+ deployImpl ({
34+ name: type (AVSDirectory).name,
35+ deployedTo: address (new AVSDirectory ({
36+ _delegation: Env.proxy.delegationManager (),
37+ _pauserRegistry: Env.impl.pauserRegistry ()
38+ }))
39+ });
40+
41+ // Deploy SM
42+ deployImpl ({
43+ name: type (StrategyManager).name,
44+ deployedTo: address (new StrategyManager ({
45+ _delegation: Env.proxy.delegationManager (),
46+ _pauserRegistry: Env.impl.pauserRegistry ()
47+ }))
48+ });
49+
50+ // Deploy RC
51+ deployImpl ({
52+ name: type (RewardsCoordinator).name,
53+ deployedTo: address (new RewardsCoordinator ({
54+ _delegationManager: Env.proxy.delegationManager (),
55+ _strategyManager: Env.proxy.strategyManager (),
56+ _allocationManager: Env.proxy.allocationManager (),
57+ _pauserRegistry: Env.impl.pauserRegistry (),
58+ _permissionController: Env.proxy.permissionController (),
59+ _CALCULATION_INTERVAL_SECONDS: Env.CALCULATION_INTERVAL_SECONDS (),
60+ _MAX_REWARDS_DURATION: Env.MAX_REWARDS_DURATION (),
61+ _MAX_RETROACTIVE_LENGTH: Env.MAX_RETROACTIVE_LENGTH (),
62+ _MAX_FUTURE_LENGTH: Env.MAX_FUTURE_LENGTH (),
63+ _GENESIS_REWARDS_TIMESTAMP: Env.GENESIS_REWARDS_TIMESTAMP ()
64+ }))
65+ });
66+
67+ vm.stopBroadcast ();
68+ }
69+
70+ function testDeploy () public virtual {
71+ _runAsEOA ();
72+ _validateDomainSeparatorNonZero ();
73+ _validateNewImplAddresses (false );
74+ _validateImplConstructors ();
75+ _validateImplsInitialized ();
76+ }
77+
78+ function _validateDomainSeparatorNonZero () internal view {
79+ bytes32 zeroDomainSeparator = bytes32 (0 );
80+
81+ assertFalse (Env.impl.avsDirectory ().domainSeparator () == zeroDomainSeparator, "avsD.domainSeparator is zero " );
82+ assertFalse (Env.impl.delegationManager ().domainSeparator () == zeroDomainSeparator, "dm.domainSeparator is zero " );
83+ assertFalse (Env.impl.strategyManager ().domainSeparator () == zeroDomainSeparator, "rc.domainSeparator is zero " );
84+ }
85+
86+
87+ /// @dev Validate that the `Env.impl` addresses are updated to be distinct from what the proxy
88+ /// admin reports as the current implementation address.
89+ ///
90+ /// Note: The upgrade script can call this with `areMatching == true` to check that these impl
91+ /// addresses _are_ matches.
92+ function _validateNewImplAddresses (bool areMatching ) internal view {
93+ function (address , address , string memory ) internal pure assertion =
94+ areMatching ? _assertMatch : _assertNotMatch;
95+
96+
97+ assertion (
98+ _getProxyImpl (address (Env.proxy.strategyManager ())),
99+ address (Env.impl.strategyManager ()),
100+ "strategyManager impl failed "
101+ );
102+
103+ assertion (
104+ _getProxyImpl (address (Env.proxy.delegationManager ())),
105+ address (Env.impl.delegationManager ()),
106+ "delegationManager impl failed "
107+ );
108+
109+ assertion (
110+ _getProxyImpl (address (Env.proxy.avsDirectory ())),
111+ address (Env.impl.avsDirectory ()),
112+ "avsdirectory impl failed "
113+ );
114+
115+ assertion (
116+ _getProxyImpl (address (Env.proxy.rewardsCoordinator ())),
117+ address (Env.impl.rewardsCoordinator ()),
118+ "rewardsCoordinator impl failed "
119+ );
120+ }
121+
122+ /// @dev Validate the immutables set in the new implementation constructors
123+ function _validateImplConstructors () internal view {
124+ AVSDirectory avsDirectory = Env.impl.avsDirectory ();
125+ assertTrue (avsDirectory.delegation () == Env.proxy.delegationManager (), "avsD.dm invalid " );
126+ assertTrue (avsDirectory.pauserRegistry () == Env.impl.pauserRegistry (), "avsD.pR invalid " );
127+
128+ DelegationManager delegation = Env.impl.delegationManager ();
129+ assertTrue (delegation.strategyManager () == Env.proxy.strategyManager (), "dm.sm invalid " );
130+ assertTrue (delegation.eigenPodManager () == Env.proxy.eigenPodManager (), "dm.epm invalid " );
131+ assertTrue (delegation.allocationManager () == Env.proxy.allocationManager (), "dm.alm invalid " );
132+ assertTrue (delegation.pauserRegistry () == Env.impl.pauserRegistry (), "dm.pR invalid " );
133+ assertTrue (delegation.permissionController () == Env.proxy.permissionController (), "dm.pc invalid " );
134+ assertTrue (delegation.minWithdrawalDelayBlocks () == Env.MIN_WITHDRAWAL_DELAY (), "dm.withdrawalDelay invalid " );
135+
136+ RewardsCoordinator rewards = Env.impl.rewardsCoordinator ();
137+ assertTrue (rewards.delegationManager () == Env.proxy.delegationManager (), "rc.dm invalid " );
138+ assertTrue (rewards.strategyManager () == Env.proxy.strategyManager (), "rc.sm invalid " );
139+ assertTrue (rewards.allocationManager () == Env.proxy.allocationManager (), "rc.alm invalid " );
140+ assertTrue (rewards.pauserRegistry () == Env.impl.pauserRegistry (), "rc.pR invalid " );
141+ assertTrue (rewards.permissionController () == Env.proxy.permissionController (), "rc.pc invalid " );
142+ assertTrue (rewards.CALCULATION_INTERVAL_SECONDS () == Env.CALCULATION_INTERVAL_SECONDS (), "rc.calcInterval invalid " );
143+ assertTrue (rewards.MAX_REWARDS_DURATION () == Env.MAX_REWARDS_DURATION (), "rc.rewardsDuration invalid " );
144+ assertTrue (rewards.MAX_RETROACTIVE_LENGTH () == Env.MAX_RETROACTIVE_LENGTH (), "rc.retroLength invalid " );
145+ assertTrue (rewards.MAX_FUTURE_LENGTH () == Env.MAX_FUTURE_LENGTH (), "rc.futureLength invalid " );
146+ assertTrue (rewards.GENESIS_REWARDS_TIMESTAMP () == Env.GENESIS_REWARDS_TIMESTAMP (), "rc.genesis invalid " );
147+
148+ StrategyManager strategyManager = Env.impl.strategyManager ();
149+ assertTrue (strategyManager.delegation () == Env.proxy.delegationManager (), "sm.dm invalid " );
150+ assertTrue (strategyManager.pauserRegistry () == Env.impl.pauserRegistry (), "sm.pR invalid " );
151+ }
152+
153+ /// @dev Call initialize on all deployed implementations to ensure initializers are disabled
154+ function _validateImplsInitialized () internal {
155+ bytes memory errInit = "Initializable: contract is already initialized " ;
156+
157+ AVSDirectory avsDirectory = Env.impl.avsDirectory ();
158+ vm.expectRevert (errInit);
159+ avsDirectory.initialize (address (0 ), 0 );
160+
161+ DelegationManager delegation = Env.impl.delegationManager ();
162+ vm.expectRevert (errInit);
163+ delegation.initialize (address (0 ), 0 );
164+
165+ RewardsCoordinator rewards = Env.impl.rewardsCoordinator ();
166+ vm.expectRevert (errInit);
167+ rewards.initialize (address (0 ), 0 , address (0 ), 0 , 0 );
168+
169+ StrategyManager strategyManager = Env.impl.strategyManager ();
170+ vm.expectRevert (errInit);
171+ strategyManager.initialize (address (0 ), address (0 ), 0 );
172+ }
173+
174+ /// @dev Query and return `proxyAdmin.getProxyImplementation(proxy)`
175+ function _getProxyImpl (address proxy ) internal view returns (address ) {
176+ return ProxyAdmin (Env.proxyAdmin ()).getProxyImplementation (ITransparentUpgradeableProxy (proxy));
177+ }
178+
179+ /// @dev Query and return `proxyAdmin.getProxyAdmin(proxy)`
180+ function _getProxyAdmin (address proxy ) internal view returns (address ) {
181+ return ProxyAdmin (Env.proxyAdmin ()).getProxyAdmin (ITransparentUpgradeableProxy (proxy));
182+ }
183+
184+ function _assertMatch (address a , address b , string memory err ) private pure {
185+ assertEq (a, b, err);
186+ }
187+
188+ function _assertNotMatch (address a , address b , string memory err ) private pure {
189+ assertNotEq (a, b, err);
190+ }
191+ }
0 commit comments