CloneFactory
0xA104803fc2151BE0BFF18da7bb31938a5fdEd83c · view on evm.now · Ethereum mainnet
Plumbing, deployed once per implementation: the token factory
(0xA104803fc2151BE0BFF18da7bb31938a5fdEd83c) clones Surface (v2)
and the sale factory (0xc474809F9cDB51A01d757aA90fbfC245Ca8A5B66) clones
FixedPriceSale. Each call clones the
implementation as an EIP-1167 proxy, calls it with the caller's encoded
initialize in the same transaction, and records the instance. initData
must call the implementation's initializer (initSelector), which either
initializes the clone or reverts the whole call, so only initialized
instances are recorded.
Every clone is CREATE2 with a salt namespaced by the caller, including
create, which uses the caller's own createNonce. No caller can deploy at
an address another caller predicted, so an owner can safely grant a sale's
predicted address as minter before creating the sale.
Discovery is the Created event plus isInstance; there is no list. The
deployer can pause new instances or deprecate the factory for good, and
neither touches an existing instance. Most callers use the
Launcher; a bespoke project calls a
factory directly.
Write functions
create
function create(bytes initData) external returns (address instance)Access: permissionless (reverts FactoryPaused, FactoryDeprecated or NotInitializer)
Clones the implementation at predictCreate(msg.sender), calls it with
initData (an encoded initialize call), records it, and bumps the caller's
createNonce. The clone's initialize sees this factory as msg.sender.
Emits Created.
createDeterministic
function createDeterministic(bytes32 salt, bytes initData) external returns (address instance)Access: permissionless (reverts FactoryPaused, FactoryDeprecated or NotInitializer)
Same as create, at the CREATE2 address predict(salt, msg.sender) returns.
The salt is namespaced by the caller, so nobody can take another caller's
address. Reusing a salt as the same caller reverts FailedDeployment.
setPaused
function setPaused(bool paused_) externalAccess: deployer-only (NotDeployer)
Halts or resumes new instances. Emits PausedSet.
deprecate
function deprecate(address successor_) externalAccess: deployer-only (NotDeployer); one-way (AlreadyDeprecated)
Halts new instances for good and names where new ones should come from.
Unpausing does not revive it. Emits Deprecated.
Read functions
createNonce
function createNonce(address) external view returns (uint256)How many create calls a caller has made; part of its next create salt.
deployer
function deployer() external view returns (address)The address that deployed the factory: the only one that can pause or deprecate.
deprecated
function deprecated() external view returns (bool)Whether deprecate was called.
implementation
function implementation() external view returns (address)The contract every instance clones.
initSelector
function initSelector() external view returns (bytes4)The implementation's initializer selector: the only call initData may make.
isInstance
function isInstance(address) external view returns (bool)Whether an address was created by this factory.
paused
function paused() external view returns (bool)Whether new instances are halted.
predict
function predict(bytes32 salt, address caller) external view returns (address)The address createDeterministic(salt, ...) returns when called by caller.
predictCreate
function predictCreate(address caller) external view returns (address)The address the next create by caller returns.
successor
function successor() external view returns (address)The successor named by deprecate, or zero.
Events
Created
event Created(address indexed implementation, address indexed instance, address indexed caller)One per instance: the implementation, the new instance, and the caller (the launcher, for a launcher-made collection or sale).
Deprecated
event Deprecated(address indexed successor)The factory was deprecated, naming a successor.
PausedSet
event PausedSet(bool paused)The pause flag changed.
Errors
AddressEmptyCode(address target)
Standard OpenZeppelin Address error, unreachable since a clone always has code.
AlreadyDeprecated()
deprecate was already called.
FactoryDeprecated()
A create after deprecation.
FactoryPaused()
A create while paused.
FailedCall()
Standard OpenZeppelin Address error: the init call reverted with no reason.
FailedDeployment()
Standard OpenZeppelin Clones error: the clone could not be created, for example a reused deterministic salt.
InsufficientBalance(uint256 balance, uint256 needed)
Standard OpenZeppelin error, unreachable since no create sends value.
NotAContract(address account)
The constructor was given an implementation without code.
NotDeployer()
setPaused or deprecate from someone other than the deployer.
NotInitializer(bytes4 selector)
initData does not start with initSelector, or the constructor was given a
zero selector.