Deployer

Git Source

Title: CREATE3-based deployer with admin control

Author: Malda Protocol

Minimal helper to precompute and deploy contracts via CREATE3 with two-step admin handover.

State Variables

admin

Current admin authorized to deploy and manage ownership

address public admin

pendingAdmin

Pending admin address that can accept control

address public pendingAdmin

Functions

onlyAdmin

Modifier to check if the caller is the admin

modifier onlyAdmin() ;

constructor

Initializes the deployer

constructor(address _admin) ;

Parameters

NameTypeDescription
_adminaddressAddress that will control deployments

receive

Accepts plain ETH transfers

receive() external payable;

setPendingAdmin

Propose a new admin that must later accept

function setPendingAdmin(address newAdmin) external onlyAdmin;

Parameters

NameTypeDescription
newAdminaddressAddress proposed as the next admin

saveEth

Withdraws all ETH to the admin

function saveEth() external onlyAdmin;

setNewAdmin

Directly sets a new admin (without pending/accept)

function setNewAdmin(address _addr) external onlyAdmin;

Parameters

NameTypeDescription
_addraddressNew admin address

create

Deploys a contract using CREATE3

function create(bytes32 salt, bytes calldata code) external payable onlyAdmin returns (address deployed);

Parameters

NameTypeDescription
saltbytes32Deterministic salt used for CREATE3
codebytesCreation bytecode to deploy

Returns

NameTypeDescription
deployedaddressThe deployed contract address

acceptAdmin

Allows the pending admin to accept control

function acceptAdmin() external;

precompute

Precomputes the deployment address for a given salt

function precompute(bytes32 salt) external view returns (address);

Parameters

NameTypeDescription
saltbytes32Deterministic salt used for CREATE3

Returns

NameTypeDescription
<none>addressThe address that would be deployed

Events

AdminSet

Emitted when admin is updated

event AdminSet(address indexed _admin);

Parameters

NameTypeDescription
_adminaddressNew admin address

PendingAdminSet

Emitted when pending admin is set

event PendingAdminSet(address indexed _admin);

Parameters

NameTypeDescription
_adminaddressPending admin address

AdminAccepted

Emitted when pending admin accepts control

event AdminAccepted(address indexed _admin);

Parameters

NameTypeDescription
_adminaddressThe admin address that just accepted

Errors

NotAuthorized

Error thrown when the caller is not the admin

error NotAuthorized(address admin, address sender);