@@ -11,6 +11,8 @@ import { ProxyAdmin } from "@openzeppelin/contracts/proxy/transparent/ProxyAdmin
1111
1212import { Hyperlane7683 } from "../src/Hyperlane7683.sol " ;
1313
14+ import { ICreateX } from "./utils/ICreateX.sol " ;
15+
1416contract OwnableProxyAdmin is ProxyAdmin {
1517 constructor (address _owner ) {
1618 _transferOwnership (_owner);
@@ -22,26 +24,16 @@ contract DeployHyperlane7683 is Script {
2224 function run () public {
2325 uint256 deployerPrivateKey = vm.envUint ("DEPLOYER_PK " );
2426
25- string memory ROUTER_SALT = vm.envString ("HYPERLANE7683_SALT " );
26- address mailbox = vm.envAddress ("MAILBOX " );
27- address permit2 = vm.envAddress ("PERMIT2 " );
28- address proxyAdminOwner = vm.envOr ("PROXY_ADMIN_OWNER " , address (0 ));
29- address owner = vm.envAddress ("ROUTER_OWNER " );
3027 uint256 [] memory domains = vm.envUint ("DOMAINS " , ", " );
3128 uint32 [] memory _domains = new uint32 [](domains.length );
3229 bytes32 [] memory routers = new bytes32 [](domains.length );
3330 GasRouter.GasRouterConfig[] memory gasConfigs = new GasRouter.GasRouterConfig [](domains.length );
3431
3532 vm.startBroadcast (deployerPrivateKey);
3633
37- ProxyAdmin proxyAdmin = new OwnableProxyAdmin {salt: keccak256 (abi.encode (ROUTER_SALT))}(proxyAdminOwner);
38-
39- address routerImpl = address (new Hyperlane7683 {salt: keccak256 (abi.encode (ROUTER_SALT))}(mailbox, permit2));
40- TransparentUpgradeableProxy proxy = new TransparentUpgradeableProxy {salt: keccak256 (abi.encode (ROUTER_SALT))}(
41- routerImpl,
42- address (proxyAdmin),
43- abi.encodeWithSelector (Hyperlane7683.initialize.selector , address (0 ), address (0 ), owner)
44- );
34+ ProxyAdmin proxyAdmin = deployProxyAdmin ();
35+ address routerImpl = deployImplementation ();
36+ TransparentUpgradeableProxy proxy = deployProxy (routerImpl, address (proxyAdmin));
4537
4638 for (uint i = 0 ; i < domains.length ; i++ ) {
4739 routers[i] = TypeCasts.addressToBytes32 (address (proxy));
@@ -61,4 +53,44 @@ contract DeployHyperlane7683 is Script {
6153 console2.log ("Implementation: " , routerImpl);
6254 console2.log ("ProxyAdmin: " , address (proxyAdmin));
6355 }
56+
57+ function deployProxyAdmin () internal returns (ProxyAdmin proxyAdmin ) {
58+ string memory ROUTER_SALT = vm.envString ("HYPERLANE7683_SALT " );
59+ address proxyAdminOwner = vm.envOr ("PROXY_ADMIN_OWNER " , address (0 ));
60+ proxyAdmin = new OwnableProxyAdmin {salt: keccak256 (abi.encode (ROUTER_SALT))}(proxyAdminOwner);
61+ }
62+
63+ function deployImplementation () internal returns (address routerImpl ) {
64+ uint256 deployerPrivateKey = vm.envUint ("DEPLOYER_PK " );
65+ address createX = vm.envAddress ("CREATEX_ADDRESS " );
66+ string memory ROUTER_SALT = vm.envString ("HYPERLANE7683_SALT " );
67+ address mailbox = vm.envAddress ("MAILBOX " );
68+ address permit2 = vm.envAddress ("PERMIT2 " );
69+ bytes32 salt = keccak256 (abi.encodePacked ("impl " ,ROUTER_SALT, vm.addr (deployerPrivateKey)));
70+
71+ bytes memory routerCreation = type (Hyperlane7683).creationCode;
72+ bytes memory routerBytecode = abi.encodePacked (routerCreation, abi.encode (mailbox, permit2));
73+
74+ routerImpl = ICreateX (createX).deployCreate3 (salt, routerBytecode);
75+ }
76+
77+ function deployProxy (address routerImpl , address proxyAdmin ) internal returns (TransparentUpgradeableProxy proxy ) {
78+ uint256 deployerPrivateKey = vm.envUint ("DEPLOYER_PK " );
79+ address createX = vm.envAddress ("CREATEX_ADDRESS " );
80+ string memory ROUTER_SALT = vm.envString ("HYPERLANE7683_SALT " );
81+ address owner = vm.envAddress ("ROUTER_OWNER " );
82+
83+ bytes32 salt = keccak256 (abi.encodePacked ("proxy " , ROUTER_SALT, vm.addr (deployerPrivateKey)));
84+
85+ bytes memory proxyCreation = type (TransparentUpgradeableProxy).creationCode;
86+ bytes memory proxyBytecode = abi.encodePacked (proxyCreation, abi.encode (
87+ routerImpl,
88+ proxyAdmin,
89+ abi.encodeWithSelector (Hyperlane7683.initialize.selector , address (0 ), address (0 ), owner)
90+ ));
91+
92+ proxy = TransparentUpgradeableProxy (
93+ payable (ICreateX (createX).deployCreate3 (salt, proxyBytecode))
94+ );
95+ }
6496}
0 commit comments