ImmutableClone
Last updated
Last updated
Authors: Trader Joe, Solady (https://github.com/vectorized/solady/blob/main/src/utils/LibClone.sol), Minimal proxy by 0age (https://github.com/0age), Clones with immutable args by wighawag, zefram.eth, Saw-mon & Natalie (https://github.com/Saw-mon-and-Natalie/clones-with-immutable-args)
Minimal immutable proxy library.
Minimal proxy: Although the sw0nt pattern saves 5 gas over the erc-1167 pattern during runtime, it is not supported out-of-the-box on Etherscan. Hence, we choose to use the 0age pattern, which saves 4 gas over the erc-1167 pattern during runtime, and has the smallest bytecode.
Clones with immutable args (CWIA):
The implementation of CWIA here doesn't implements a receive()
as it is not needed for LB.
Deploys a deterministic clone of implementation
using immutable arguments encoded in data
, with salt
Parameters
implementation
address
The address of the implementation
data
bytes
The encoded immutable arguments
salt
bytes32
The salt
---------------------------------------------------------------------------------------------------+
Opcode
---------------------------------------------------------------------------------------------------
61 runSize
3d
81
60 offset
3d
39
f3
---------------------------------------------------------------------------------------------------
RUNTIME (98 bytes + extraLength)
---------------------------------------------------------------------------------------------------
Opcode
---------------------------------------------------------------------------------------------------
::: copy calldata to memory ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
36
3d
3d
37
::: keep some values in stack ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
3d
3d
3d
3d
61 extra
::: copy extra data to memory ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
80
60 0x35
36
39
::: delegate call to the implementation contract :::::::::::::::::::::::::::::::::::::::::::::::::
36
01
3d
73 addr
5a
f4
::: copy return data to memory :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
3d
3d
93
80
3e
60 0x33
57
::: revert :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
fd
::: return :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
5b
f3
---------------------------------------------------------------------------------------------------+
Returns the initialization code hash of the clone of implementation
using immutable arguments encoded in data
.
Used for mining vanity addresses with create2crunch.
Parameters
implementation
address
The address of the implementation contract.
data
bytes
The encoded immutable arguments.
Returns
hash
bytes32
The initialization code hash.
Returns the address of the deterministic clone ofimplementation
using immutable arguments encoded in data
, with salt
, by deployer
.
Parameters
implementation
address
The address of the implementation.
data
bytes
The immutable arguments of the implementation.
salt
bytes32
The salt used to compute the address.
deployer
address
The address of the deployer.
Returns
predicted
address
The predicted address.
Returns the address when a contract with initialization code hash,hash
, is deployed with salt
, by deployer
.
Parameters
hash
bytes32
The initialization code hash.
salt
bytes32
The salt used to compute the address.
deployer
address
The address of the deployer.
Returns
predicted
address
The predicted address.