1+ // SPDX-License-Identifier: MIT
2+ pragma solidity ^ 0.8.13 ;
3+
4+ /**
5+ * @title ImmutableCreate2FactoryInterface
6+ * @author 0age
7+ * @notice This contract provides a safeCreate2 function that takes a salt value
8+ * and a block of initialization code as arguments and passes them into
9+ * inline assembly. The contract prevents redeploys by maintaining a
10+ * mapping of all contracts that have already been deployed, and
11+ * prevents frontrunning or other collisions by requiring that the first
12+ * 20 bytes of the salt are equal to the address of the caller (this can
13+ * be bypassed by setting the first 20 bytes to the null address). There
14+ * is also a view function that computes the address of the contract
15+ * that will be created when submitting a given salt or nonce along with
16+ * a given block of initialization code.
17+ */
18+ interface ImmutableCreate2FactoryInterface {
19+ /**
20+ * @dev Create a contract using CREATE2 by submitting a given salt or nonce
21+ * along with the initialization code for the contract. Note that the
22+ * first 20 bytes of the salt must match those of the calling address,
23+ * which prevents contract creation events from being submitted by
24+ * unintended parties.
25+ *
26+ * @param salt The nonce that will be passed into the CREATE2
27+ * call.
28+ * @param initializationCode The initialization code that will be passed
29+ * into the CREATE2 call.
30+ *
31+ * @return deploymentAddress Address of the contract that will be created.
32+ */
33+ function safeCreate2 (
34+ bytes32 salt ,
35+ bytes calldata initializationCode
36+ ) external payable returns (address deploymentAddress );
37+
38+ /**
39+ * @dev Compute the address of the contract that will be created when
40+ * submitting a given salt or nonce to the contract along with the
41+ * contract's initialization code. The CREATE2 address is computed in
42+ * accordance with EIP-1014, and adheres to the formula therein of
43+ * `keccak256( 0xff ++ address ++ salt ++ keccak256(init_code)))[12:]`
44+ * when performing the computation. The computed address is then
45+ * checked for any existing contract code - if so, the null address
46+ * will be returned instead.
47+ *
48+ * @param salt The nonce passed into the CREATE2 address calculation.
49+ * @param initCode The contract initialization code to be used that will be
50+ * passed into the CREATE2 address calculation.
51+ *
52+ * @return deploymentAddress Address of the contract that will be created,
53+ * or the null address if a contract already
54+ * exists at that address.
55+ */
56+ function findCreate2Address (
57+ bytes32 salt ,
58+ bytes calldata initCode
59+ ) external view returns (address deploymentAddress );
60+
61+ /**
62+ * @dev Compute the address of the contract that will be created when
63+ * submitting a given salt or nonce to the contract along with the
64+ * keccak256 hash of the contract's initialization code. The CREATE2
65+ * address is computed in accordance with EIP-1014, and adheres to the
66+ * `keccak256( 0xff ++ address ++ salt ++ keccak256(init_code)))[12:]`
67+ * formula when performing the computation. The computed address is
68+ * then checked for any existing contract code - if so, the null
69+ * address will be returned instead.
70+ *
71+ * @param salt The nonce passed into the CREATE2 address
72+ * calculation.
73+ * @param initCodeHash The keccak256 hash of the initialization code that
74+ * will be passed into the CREATE2 address calculation.
75+ *
76+ * @return deploymentAddress Address of the contract that will be created,
77+ * or the null address if a contract already
78+ * exists at that address.
79+ */
80+ function findCreate2AddressViaHash (
81+ bytes32 salt ,
82+ bytes32 initCodeHash
83+ ) external view returns (address deploymentAddress );
84+
85+ /**
86+ * @dev Determine if a contract has already been deployed by the factory to
87+ * a given address.
88+ *
89+ * @param deploymentAddress The contract address to check.
90+ *
91+ * @return True if the contract has been deployed, false otherwise.
92+ */
93+ function hasBeenDeployed (
94+ address deploymentAddress
95+ ) external view returns (bool );
96+ }
0 commit comments