-
Notifications
You must be signed in to change notification settings - Fork 969
/
Copy pathCreateCall.sol
44 lines (40 loc) · 1.94 KB
/
CreateCall.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
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity >=0.7.0 <0.9.0;
/**
* @title Create Call - Allows to use the different create opcodes to deploy a contract.
* @author Richard Meissner - @rmeissner
* @notice This contract provides functions for deploying a new contract using the create and create2 opcodes.
*/
contract CreateCall {
/// @notice Emitted when a new contract is created
event ContractCreation(address indexed newContract);
/**
* @notice Deploys a new contract using the create2 opcode.
* @param value The value in wei to be sent with the contract creation.
* @param deploymentData The initialisation code of the contract to be created.
* @param salt The salt value to use for the contract creation.
* @return newContract The address of the newly created contract.
*/
function performCreate2(uint256 value, bytes memory deploymentData, bytes32 salt) public returns (address newContract) {
// solhint-disable-next-line no-inline-assembly
assembly {
newContract := create2(value, add(0x20, deploymentData), mload(deploymentData), salt)
}
require(newContract != address(0), "Could not deploy contract");
emit ContractCreation(newContract);
}
/**
* @notice Deploys a new contract using the create opcode.
* @param value The value in wei to be sent with the contract creation.
* @param deploymentData The initialisation code of the contract to be created.
* @return newContract The address of the newly created contract.
*/
function performCreate(uint256 value, bytes memory deploymentData) public returns (address newContract) {
// solhint-disable-next-line no-inline-assembly
assembly {
newContract := create(value, add(deploymentData, 0x20), mload(deploymentData))
}
require(newContract != address(0), "Could not deploy contract");
emit ContractCreation(newContract);
}
}