-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCreate2Helper.sol
56 lines (53 loc) · 1.33 KB
/
Create2Helper.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
pragma solidity 0.8.25;
struct Create2Params {
address creator;
bytes creationCode;
bytes constructorParams;
bytes32 salt;
}
function calculateCreate2Address(
address creator,
bytes memory creationCode,
bytes memory constructorParams,
bytes32 salt
) pure returns (address) {
return address(
uint160(
uint256(
keccak256(
abi.encodePacked(
bytes1(0xff),
creator,
salt,
keccak256(
abi.encodePacked(creationCode, constructorParams)
)
)
)
)
)
);
}
function calculateCreate2Address(Create2Params memory params)
pure
returns (address)
{
return address(
uint160(
uint256(
keccak256(
abi.encodePacked(
bytes1(0xff),
params.creator,
params.salt,
keccak256(
abi.encodePacked(
params.creationCode, params.constructorParams
)
)
)
)
)
)
);
}