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
  • State Variables
  • OFFSET_ID
  • OFFSET_DISTRIBUTION_Y
  • OFFSET_DISTRIBUTION_X
  • PRECISION
  • Functions
  • encodeParams
  • decodeParams
  • getAmountsAndId
  • Errors
  • LiquidityConfigurations__InvalidConfig
  1. Contracts
  2. Libraries
  3. Math

LiquidityConfigurations

PreviousEncodedNextPackedUint128Math

Last updated 8 days ago

This library contains functions to encode and decode the config of a pool and interact with the encoded bytes32.

State Variables

OFFSET_ID

uint256 private constant OFFSET_ID = 0;

OFFSET_DISTRIBUTION_Y

uint256 private constant OFFSET_DISTRIBUTION_Y = 24;

OFFSET_DISTRIBUTION_X

uint256 private constant OFFSET_DISTRIBUTION_X = 88;

PRECISION

uint256 private constant PRECISION = 1e18;

Functions

encodeParams

Encode the distributionX, distributionY and id into a single bytes32

function encodeParams(uint64 distributionX, uint64 distributionY, uint24 id) internal pure returns (bytes32 config);

Parameters

Name
Type
Description

distributionX

uint64

The distribution of the first token

distributionY

uint64

The distribution of the second token

id

uint24

The id of the pool

Returns

Name
Type
Description

config

bytes32

The encoded config as follows: [0 - 24[: id [24 - 88[: distributionY [88 - 152[: distributionX [152 - 256[: empty

decodeParams

Decode the distributionX, distributionY and id from a single bytes32

function decodeParams(bytes32 config) internal pure returns (uint64 distributionX, uint64 distributionY, uint24 id);

Parameters

Name
Type
Description

config

bytes32

The encoded config as follows: [0 - 24[: id [24 - 88[: distributionY [88 - 152[: distributionX [152 - 256[: empty

Returns

Name
Type
Description

distributionX

uint64

The distribution of the first token

distributionY

uint64

The distribution of the second token

id

uint24

The id of the bin to add the liquidity to

getAmountsAndId

Get the amounts and id from a config and amountsIn

function getAmountsAndId(bytes32 config, bytes32 amountsIn) internal pure returns (bytes32, uint24);

Parameters

Name
Type
Description

config

bytes32

The encoded config as follows: [0 - 24[: id [24 - 88[: distributionY [88 - 152[: distributionX [152 - 256[: empty

amountsIn

bytes32

The amounts to distribute as follows: [0 - 128[: x1 [128 - 256[: x2

Returns

Name
Type
Description

<none>

bytes32

amounts The distributed amounts as follows: [0 - 128[: x1 [128 - 256[: x2

<none>

uint24

id The id of the bin to add the liquidity to

Errors

LiquidityConfigurations__InvalidConfig

error LiquidityConfigurations__InvalidConfig();
Git Source