Last active
June 21, 2022 08:46
-
-
Save MerlinEgalite/ab652912ddfdad781e833adc76ddef40 to your computer and use it in GitHub Desktop.
Deployment contract
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: LGPL-3.0-only | |
pragma solidity >=0.7.0 <0.9.0; | |
interface IOwnable { | |
function transferOwnership(address) external; | |
} | |
contract Deployer { | |
event ContractCreation(address newContract); | |
function performCreate2( | |
uint256 value, | |
bytes memory deploymentData, | |
bytes32 salt, | |
address owner | |
) 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"); | |
if (owner != address(0)) IOwnable(newContract).transferOwnership(owner); | |
emit ContractCreation(newContract); | |
} | |
function performCreate(uint256 value, bytes memory deploymentData, address owner) 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); | |
if (owner != address(0)) IOwnable(newContract).transferOwnership(owner); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment