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+ deployImpl ({
19+ name: type (StrategyManager).name,
20+ deployedTo: address (new StrategyManager ({
21+ _delegation: Env.proxy.delegationManager (),
22+ _pauserRegistry: Env.impl.pauserRegistry ()
23+ }))
24+ });
25+
26+ vm.stopBroadcast ();
27+ }
28+
29+ function testDeploy () public virtual {
30+ _runAsEOA ();
31+ _validateNewImplAddresses (false );
32+ _validateImplConstructors ();
33+ _validateImplsInitialized ();
34+ }
35+
36+
37+ /// @dev Validate that the `Env.impl` addresses are updated to be distinct from what the proxy
38+ /// admin reports as the current implementation address.
39+ ///
40+ /// Note: The upgrade script can call this with `areMatching == true` to check that these impl
41+ /// addresses _are_ matches.
42+ function _validateNewImplAddresses (bool areMatching ) internal view {
43+ function (address , address , string memory ) internal pure assertion =
44+ areMatching ? _assertMatch : _assertNotMatch;
45+
46+
47+ assertion (
48+ _getProxyImpl (address (Env.proxy.strategyManager ())),
49+ address (Env.impl.strategyManager ()),
50+ "strategyManager impl failed "
51+ );
52+ }
53+
54+ /// @dev Validate the immutables set in the new implementation constructors
55+ function _validateImplConstructors () internal view {
56+ StrategyManager strategyManager = Env.impl.strategyManager ();
57+ assertTrue (strategyManager.delegation () == Env.proxy.delegationManager (), "sm.dm invalid " );
58+ assertTrue (strategyManager.pauserRegistry () == Env.impl.pauserRegistry (), "sm.pR invalid " );
59+ }
60+
61+ /// @dev Call initialize on all deployed implementations to ensure initializers are disabled
62+ function _validateImplsInitialized () internal {
63+ bytes memory errInit = "Initializable: contract is already initialized " ;
64+
65+ StrategyManager strategyManager = Env.impl.strategyManager ();
66+ vm.expectRevert (errInit);
67+ strategyManager.initialize (address (0 ), address (0 ), 0 );
68+ }
69+
70+ /// @dev Query and return `proxyAdmin.getProxyImplementation(proxy)`
71+ function _getProxyImpl (address proxy ) internal view returns (address ) {
72+ return ProxyAdmin (Env.proxyAdmin ()).getProxyImplementation (ITransparentUpgradeableProxy (proxy));
73+ }
74+
75+ /// @dev Query and return `proxyAdmin.getProxyAdmin(proxy)`
76+ function _getProxyAdmin (address proxy ) internal view returns (address ) {
77+ return ProxyAdmin (Env.proxyAdmin ()).getProxyAdmin (ITransparentUpgradeableProxy (proxy));
78+ }
79+
80+ function _assertMatch (address a , address b , string memory err ) private pure {
81+ assertEq (a, b, err);
82+ }
83+
84+ function _assertNotMatch (address a , address b , string memory err ) private pure {
85+ assertNotEq (a, b, err);
86+ }
87+ }
0 commit comments