LFJ Developer Docs
  • Liquidity Book
  • Introduction
  • LB V2.2 Key Changes
  • Guides
    • Swap Tokens
    • Add/Remove Liquidity
    • Tracking Volume
    • Tracking Pool Balances
    • Finding The Best Quote
    • Byte32 Decoding
    • Price From Bin Id
    • Bin Id From Price
    • Finding Liquidity Depth
    • User Balances
  • Concepts
    • Concentrated Liquidity
    • Bin Math
    • Bin Liquidity
    • Swaps
    • Fees
    • Oracle
  • Contracts
    • Interfaces
      • ILBLegacyFactory
      • ILBLegacyToken
      • ILBLegacyPair
      • ILBLegacyRouter
      • ILBFlashLoanCallback
      • IPendingOwnable
      • IJoeFactory
      • IJoePair
      • IJoeRouter01
      • IJoeRouter02
      • IWNATIVE
      • ILBFactory
      • ILBHooks
      • ILBPair
      • ILBRouter
      • ILBToken
    • Libraries
      • Math
        • BitMath
        • Encoded
        • LiquidityConfigurations
        • PackedUint128Math
        • SafeCast
        • SampleMath
        • TreeMath
        • Uint128x128Math
        • Uint256x256Math
      • BinHelper
      • Clone
      • Constants
      • FeeHelper
      • Hooks
      • ImmutableClone
      • JoeLibrary
      • OracleHelper
      • PairParameterHelper
      • PriceHelper
      • ReentrancyGuardUpgradeable
      • TokenHelper
    • LBBaseHooks
    • LBFactory
    • LBPair
    • LBQuoter
    • LBRouter
    • LBToken
  • Deployment Addresses
    • Avalanche C-Chain
    • Fuji Testnet
    • Arbitrum One
    • Binance Smart Chain
    • Binance Smart Chain Testnet
    • Ethereum Mainnet
    • Monad Testnet
  • SDK
    • Introduction
    • Making a Trade
    • Adding Liquidity
    • Removing Liquidity
  • Audits
  • AMM
    • Joe V1 Contracts
    • Joe V1 Audits
  • LFJ DEX API
    • Dex Analytics
    • Pools
    • Rewards
    • User
    • User Lifetime Stats
    • Vaults
    • Models
  • LFJ Aggregator API
    • Default
    • Models
Powered by GitBook
On this page
  • Functions
  • cloneDeterministic
  • initCodeHash
  • predictDeterministicAddress
  • predictDeterministicAddress
  • Errors
  • DeploymentFailed
  • PackedDataTooBig
  1. Contracts
  2. Libraries

ImmutableClone

PreviousHooksNextJoeLibrary

Last updated 8 days ago

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

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.

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.

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.

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

error DeploymentFailed();

PackedDataTooBig

error PackedDataTooBig();
Git Source