Skip to content

Instantly share code, notes, and snippets.

@BedrosovaYulia
Created June 6, 2023 11:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save BedrosovaYulia/96088d1ae844318bc8de0294bb7c2cb3 to your computer and use it in GitHub Desktop.
Save BedrosovaYulia/96088d1ae844318bc8de0294bb7c2cb3 to your computer and use it in GitHub Desktop.
// 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