Skip to content

ImmutableClone ​

Git Source

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.

Functions ​

cloneDeterministic ​

Deploys a deterministic clone of implementation using immutable arguments encoded in data, with salt

solidity
function cloneDeterministic(address implementation, bytes memory data, bytes32 salt)
    internal
    returns (address instance);

Parameters

NameTypeDescription
implementationaddressThe address of the implementation
databytesThe encoded immutable arguments
saltbytes32The salt

initCodeHash ​

---------------------------------------------------------------------------------------------------+

CREATION (10 bytes)
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.

solidity
function initCodeHash(address implementation, bytes memory data) internal pure returns (bytes32 hash);

Parameters

NameTypeDescription
implementationaddressThe address of the implementation contract.
databytesThe encoded immutable arguments.

Returns

NameTypeDescription
hashbytes32The initialization code hash.

predictDeterministicAddress ​

Returns the address of the deterministic clone ofimplementation using immutable arguments encoded in data, with salt, by deployer.

solidity
function predictDeterministicAddress(address implementation, bytes memory data, bytes32 salt, address deployer)
    internal
    pure
    returns (address predicted);

Parameters

NameTypeDescription
implementationaddressThe address of the implementation.
databytesThe immutable arguments of the implementation.
saltbytes32The salt used to compute the address.
deployeraddressThe address of the deployer.

Returns

NameTypeDescription
predictedaddressThe predicted address.

predictDeterministicAddress ​

Returns the address when a contract with initialization code hash,hash, is deployed with salt, by deployer.

solidity
function predictDeterministicAddress(bytes32 hash, bytes32 salt, address deployer)
    internal
    pure
    returns (address predicted);

Parameters

NameTypeDescription
hashbytes32The initialization code hash.
saltbytes32The salt used to compute the address.
deployeraddressThe address of the deployer.

Returns

NameTypeDescription
predictedaddressThe predicted address.

Errors ​

DeploymentFailed ​

solidity
error DeploymentFailed();

PackedDataTooBig ​

solidity
error PackedDataTooBig();