Create2Deployer
Can be used to deploy contracts with CREATE2 Factory.
State Variables
CREATE2_FACTORY
_Used by default when deploying with create2, https://github.com/Arachnid/deterministic-deployment-proxy._
address public constant _CREATE2_FACTORY = 0x4e59b44847b379578588920cA78FbF26c0B4956C;
Functions
deployWithCreate2
Deploys a contract using the _CREATE2_FACTORY.
The call data is encoded as abi.encodePacked(salt, initCode)
.
The return data is abi.encodePacked(addr)
.
function deployWithCreate2(uint256 salt, bytes memory initCode) internal returns (address addr);
Parameters
Name | Type | Description |
---|---|---|
salt | uint256 | The salt to use for the deployment. |
initCode | bytes | The init code of the contract to deploy. |
Returns
Name | Type | Description |
---|---|---|
addr | address | The address of the deployed contract. |
deployWithCreate2IfNecessary
Deploys a contract using the _CREATE2_FACTORY if it hasn't been deployed yet.
function deployWithCreate2IfNecessary(uint256 salt, bytes memory initCode) internal returns (address addr);
getCreate2Address
Returns the deterministic address of a contract for the given salt and init code.
Assumes that the contract will be deployed using deployWithCreate2
.
function getCreate2Address(uint256 salt, bytes memory initCode) internal pure returns (address);
Parameters
Name | Type | Description |
---|---|---|
salt | uint256 | The salt to use for the deployment. |
initCode | bytes | The init code of the contract to deploy. |
Returns
Name | Type | Description |
---|---|---|
<none> | address | addr The address of the deployed contract. |
getCreate2Address
Returns the deterministic address of a contract for the given salt and init code.
Assumes that the contract will be deployed using deployWithCreate2
.
function getCreate2Address(uint256 salt, bytes32 initCodeHash) internal pure returns (address);
Parameters
Name | Type | Description |
---|---|---|
salt | uint256 | The salt to use for the deployment. |
initCodeHash | bytes32 | The init codehash of the contract to deploy. |
Returns
Name | Type | Description |
---|---|---|
<none> | address | addr The address of the deployed contract. |
deployProxyWithCreate2
Deploys a ERC1967 Proxy for the already deployed implementation contract.
function deployProxyWithCreate2(address implementation, uint256 salt) internal returns (address);
Parameters
Name | Type | Description |
---|---|---|
implementation | address | The implementation contract address. |
salt | uint256 | The salt that will be used for the deployment of the proxy. |
Returns
Name | Type | Description |
---|---|---|
<none> | address | instance The determinitic address of the deployed proxy contract. |
deployProxyWithCreate2IfNecessary
Deploys a ERC1967 Proxy for the already deployed implementation contract if it hasn't been deployed yet.
function deployProxyWithCreate2IfNecessary(address implementation, uint256 salt) internal returns (address);
getCreate2ProxyAddress
Returns the deterministic address of a ERC1967 proxy for the given implementation and salt.
Assumes that the proxy is deployed using deployProxyWithCreate2
.
function getCreate2ProxyAddress(address implementation, uint256 salt) internal pure returns (address);
Parameters
Name | Type | Description |
---|---|---|
implementation | address | The implementation contract address. |
salt | uint256 | The salt that will be used for the deployment of the proxy. |
Returns
Name | Type | Description |
---|---|---|
<none> | address | instance The address of the deployed proxy contract. |