Created
June 6, 2023 11:17
-
-
Save BedrosovaYulia/96088d1ae844318bc8de0294bb7c2cb3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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: MIT | |
pragma solidity 0.8.0; | |
import "@openzeppelin/contracts/access/Ownable.sol"; | |
contract DeployerOfDeployer is Ownable{ | |
event Deployed(address to); | |
function deploy( | |
uint256 _salt | |
) external onlyOwner { | |
DeployerOfTarget d1 = new DeployerOfTarget{salt: bytes32(_salt)}(); | |
emit Deployed(address(d1)); | |
d1.transferOwnership(owner()); | |
} | |
} | |
contract DeployerOfTarget is Ownable{ | |
event Deployed(address to); | |
function deploy(bytes memory bytecode) external onlyOwner { | |
address addr; | |
assembly{ | |
mstore(0x0, bytecode) | |
addr := create(0, 0xa0, calldatasize()) | |
} | |
require(addr != address(0)); | |
emit Deployed(addr); | |
Ownable c1 = Ownable(addr); | |
c1.transferOwnership(owner()); | |
} | |
function destroy() external onlyOwner { | |
selfdestruct(payable(msg.sender)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment