Skip to content

Commit 32146d0

Browse files
committed
Merge branch 'main' into decouple-order-3-leyers
2 parents 98de0d5 + a01408f commit 32146d0

File tree

3 files changed

+526
-797
lines changed

3 files changed

+526
-797
lines changed

solidity/script/DeployHyperlane7683.s.sol

Lines changed: 45 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import { ProxyAdmin } from "@openzeppelin/contracts/proxy/transparent/ProxyAdmin
1111

1212
import { Hyperlane7683 } from "../src/Hyperlane7683.sol";
1313

14+
import { ICreateX } from "./utils/ICreateX.sol";
15+
1416
contract 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
}

solidity/script/utils/ICreateX.sol

Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
// SPDX-License-Identifier: AGPL-3.0-only
2+
pragma solidity 0.8.25;
3+
4+
/**
5+
* @title CreateX Factory Interface Definition
6+
* @author pcaversaccio (https://web.archive.org/web/20230921103111/https://pcaversaccio.com/)
7+
* @custom:coauthor Matt Solomon (https://web.archive.org/web/20230921103335/https://mattsolomon.dev/)
8+
*/
9+
interface ICreateX {
10+
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
11+
/* TYPES */
12+
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
13+
14+
struct Values {
15+
uint256 constructorAmount;
16+
uint256 initCallAmount;
17+
}
18+
19+
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
20+
/* EVENTS */
21+
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
22+
23+
event ContractCreation(address indexed newContract, bytes32 indexed salt);
24+
event ContractCreation(address indexed newContract);
25+
event Create3ProxyContractCreation(address indexed newContract, bytes32 indexed salt);
26+
27+
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
28+
/* CUSTOM ERRORS */
29+
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
30+
31+
error FailedContractCreation(address emitter);
32+
error FailedContractInitialisation(address emitter, bytes revertData);
33+
error InvalidSalt(address emitter);
34+
error InvalidNonceValue(address emitter);
35+
error FailedEtherTransfer(address emitter, bytes revertData);
36+
37+
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
38+
/* CREATE */
39+
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
40+
41+
function deployCreate(bytes memory initCode) external payable returns (address newContract);
42+
43+
function deployCreateAndInit(
44+
bytes memory initCode,
45+
bytes memory data,
46+
Values memory values,
47+
address refundAddress
48+
)
49+
external
50+
payable
51+
returns (address newContract);
52+
53+
function deployCreateAndInit(
54+
bytes memory initCode,
55+
bytes memory data,
56+
Values memory values
57+
)
58+
external
59+
payable
60+
returns (address newContract);
61+
62+
function deployCreateClone(address implementation, bytes memory data) external payable returns (address proxy);
63+
64+
function computeCreateAddress(address deployer, uint256 nonce) external view returns (address computedAddress);
65+
66+
function computeCreateAddress(uint256 nonce) external view returns (address computedAddress);
67+
68+
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
69+
/* CREATE2 */
70+
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
71+
72+
function deployCreate2(bytes32 salt, bytes memory initCode) external payable returns (address newContract);
73+
74+
function deployCreate2(bytes memory initCode) external payable returns (address newContract);
75+
76+
function deployCreate2AndInit(
77+
bytes32 salt,
78+
bytes memory initCode,
79+
bytes memory data,
80+
Values memory values,
81+
address refundAddress
82+
)
83+
external
84+
payable
85+
returns (address newContract);
86+
87+
function deployCreate2AndInit(
88+
bytes32 salt,
89+
bytes memory initCode,
90+
bytes memory data,
91+
Values memory values
92+
)
93+
external
94+
payable
95+
returns (address newContract);
96+
97+
function deployCreate2AndInit(
98+
bytes memory initCode,
99+
bytes memory data,
100+
Values memory values,
101+
address refundAddress
102+
)
103+
external
104+
payable
105+
returns (address newContract);
106+
107+
function deployCreate2AndInit(
108+
bytes memory initCode,
109+
bytes memory data,
110+
Values memory values
111+
)
112+
external
113+
payable
114+
returns (address newContract);
115+
116+
function deployCreate2Clone(
117+
bytes32 salt,
118+
address implementation,
119+
bytes memory data
120+
)
121+
external
122+
payable
123+
returns (address proxy);
124+
125+
function deployCreate2Clone(address implementation, bytes memory data) external payable returns (address proxy);
126+
127+
function computeCreate2Address(
128+
bytes32 salt,
129+
bytes32 initCodeHash,
130+
address deployer
131+
)
132+
external
133+
pure
134+
returns (address computedAddress);
135+
136+
function computeCreate2Address(
137+
bytes32 salt,
138+
bytes32 initCodeHash
139+
)
140+
external
141+
view
142+
returns (address computedAddress);
143+
144+
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
145+
/* CREATE3 */
146+
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
147+
148+
function deployCreate3(bytes32 salt, bytes memory initCode) external payable returns (address newContract);
149+
150+
function deployCreate3(bytes memory initCode) external payable returns (address newContract);
151+
152+
function deployCreate3AndInit(
153+
bytes32 salt,
154+
bytes memory initCode,
155+
bytes memory data,
156+
Values memory values,
157+
address refundAddress
158+
)
159+
external
160+
payable
161+
returns (address newContract);
162+
163+
function deployCreate3AndInit(
164+
bytes32 salt,
165+
bytes memory initCode,
166+
bytes memory data,
167+
Values memory values
168+
)
169+
external
170+
payable
171+
returns (address newContract);
172+
173+
function deployCreate3AndInit(
174+
bytes memory initCode,
175+
bytes memory data,
176+
Values memory values,
177+
address refundAddress
178+
)
179+
external
180+
payable
181+
returns (address newContract);
182+
183+
function deployCreate3AndInit(
184+
bytes memory initCode,
185+
bytes memory data,
186+
Values memory values
187+
)
188+
external
189+
payable
190+
returns (address newContract);
191+
192+
function computeCreate3Address(bytes32 salt, address deployer) external pure returns (address computedAddress);
193+
194+
function computeCreate3Address(bytes32 salt) external view returns (address computedAddress);
195+
}

0 commit comments

Comments
 (0)