Skip to content

Instantly share code, notes, and snippets.

@MerlinEgalite
Last active June 21, 2022 08:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MerlinEgalite/ab652912ddfdad781e833adc76ddef40 to your computer and use it in GitHub Desktop.
Save MerlinEgalite/ab652912ddfdad781e833adc76ddef40 to your computer and use it in GitHub Desktop.
Deployment contract
// 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