Appearance
ImmutableClone
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
| Name | Type | Description |
|---|---|---|
implementation | address | The address of the implementation |
data | bytes | The encoded immutable arguments |
salt | bytes32 | The 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
| Name | Type | Description |
|---|---|---|
implementation | address | The address of the implementation contract. |
data | bytes | The encoded immutable arguments. |
Returns
| Name | Type | Description |
|---|---|---|
hash | bytes32 | The 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
| Name | Type | Description |
|---|---|---|
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
| Name | Type | Description |
|---|---|---|
predicted | address | The 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
| Name | Type | Description |
|---|---|---|
hash | bytes32 | The initialization code hash. |
salt | bytes32 | The salt used to compute the address. |
deployer | address | The address of the deployer. |
Returns
| Name | Type | Description |
|---|---|---|
predicted | address | The predicted address. |
Errors
DeploymentFailed
solidity
error DeploymentFailed();PackedDataTooBig
solidity
error PackedDataTooBig();