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
  • MASK_UINT1
  • MASK_UINT8
  • MASK_UINT12
  • MASK_UINT14
  • MASK_UINT16
  • MASK_UINT20
  • MASK_UINT24
  • MASK_UINT40
  • MASK_UINT64
  • MASK_UINT128
  • Functions
  • set
  • setBool
  • decode
  • decodeBool
  • decodeUint8
  • decodeUint12
  • decodeUint14
  • decodeUint16
  • decodeUint20
  • decodeUint24
  • decodeUint40
  • decodeUint64
  • decodeUint128
  1. Contracts
  2. Libraries
  3. Math

Encoded

PreviousBitMathNextLiquidityConfigurations

Last updated 8 days ago

Helper contract used for decoding bytes32 sample

State Variables

MASK_UINT1

uint256 internal constant MASK_UINT1 = 0x1;

MASK_UINT8

uint256 internal constant MASK_UINT8 = 0xff;

MASK_UINT12

uint256 internal constant MASK_UINT12 = 0xfff;

MASK_UINT14

uint256 internal constant MASK_UINT14 = 0x3fff;

MASK_UINT16

uint256 internal constant MASK_UINT16 = 0xffff;

MASK_UINT20

uint256 internal constant MASK_UINT20 = 0xfffff;

MASK_UINT24

uint256 internal constant MASK_UINT24 = 0xffffff;

MASK_UINT40

uint256 internal constant MASK_UINT40 = 0xffffffffff;

MASK_UINT64

uint256 internal constant MASK_UINT64 = 0xffffffffffffffff;

MASK_UINT128

uint256 internal constant MASK_UINT128 = 0xffffffffffffffffffffffffffffffff;

Functions

set

Internal function to set a value in an encoded bytes32 using a mask and offset

This function can overflow

function set(bytes32 encoded, uint256 value, uint256 mask, uint256 offset) internal pure returns (bytes32 newEncoded);

Parameters

Name
Type
Description

encoded

bytes32

The previous encoded value

value

uint256

The value to encode

mask

uint256

The mask

offset

uint256

The offset

Returns

Name
Type
Description

newEncoded

bytes32

The new encoded value

setBool

Internal function to set a bool in an encoded bytes32 using an offset

This function can overflow

function setBool(bytes32 encoded, bool boolean, uint256 offset) internal pure returns (bytes32 newEncoded);

Parameters

Name
Type
Description

encoded

bytes32

The previous encoded value

boolean

bool

The bool to encode

offset

uint256

The offset

Returns

Name
Type
Description

newEncoded

bytes32

The new encoded value

decode

Internal function to decode a bytes32 sample using a mask and offset

This function can overflow

function decode(bytes32 encoded, uint256 mask, uint256 offset) internal pure returns (uint256 value);

Parameters

Name
Type
Description

encoded

bytes32

The encoded value

mask

uint256

The mask

offset

uint256

The offset

Returns

Name
Type
Description

value

uint256

The decoded value

decodeBool

Internal function to decode a bytes32 sample into a bool using an offset

This function can overflow

function decodeBool(bytes32 encoded, uint256 offset) internal pure returns (bool boolean);

Parameters

Name
Type
Description

encoded

bytes32

The encoded value

offset

uint256

The offset

Returns

Name
Type
Description

boolean

bool

The decoded value as a bool

decodeUint8

Internal function to decode a bytes32 sample into a uint8 using an offset

This function can overflow

function decodeUint8(bytes32 encoded, uint256 offset) internal pure returns (uint8 value);

Parameters

Name
Type
Description

encoded

bytes32

The encoded value

offset

uint256

The offset

Returns

Name
Type
Description

value

uint8

The decoded value

decodeUint12

Internal function to decode a bytes32 sample into a uint12 using an offset

This function can overflow

function decodeUint12(bytes32 encoded, uint256 offset) internal pure returns (uint16 value);

Parameters

Name
Type
Description

encoded

bytes32

The encoded value

offset

uint256

The offset

Returns

Name
Type
Description

value

uint16

The decoded value as a uint16, since uint12 is not supported

decodeUint14

Internal function to decode a bytes32 sample into a uint14 using an offset

This function can overflow

function decodeUint14(bytes32 encoded, uint256 offset) internal pure returns (uint16 value);

Parameters

Name
Type
Description

encoded

bytes32

The encoded value

offset

uint256

The offset

Returns

Name
Type
Description

value

uint16

The decoded value as a uint16, since uint14 is not supported

decodeUint16

Internal function to decode a bytes32 sample into a uint16 using an offset

This function can overflow

function decodeUint16(bytes32 encoded, uint256 offset) internal pure returns (uint16 value);

Parameters

Name
Type
Description

encoded

bytes32

The encoded value

offset

uint256

The offset

Returns

Name
Type
Description

value

uint16

The decoded value

decodeUint20

Internal function to decode a bytes32 sample into a uint20 using an offset

This function can overflow

function decodeUint20(bytes32 encoded, uint256 offset) internal pure returns (uint24 value);

Parameters

Name
Type
Description

encoded

bytes32

The encoded value

offset

uint256

The offset

Returns

Name
Type
Description

value

uint24

The decoded value as a uint24, since uint20 is not supported

decodeUint24

Internal function to decode a bytes32 sample into a uint24 using an offset

This function can overflow

function decodeUint24(bytes32 encoded, uint256 offset) internal pure returns (uint24 value);

Parameters

Name
Type
Description

encoded

bytes32

The encoded value

offset

uint256

The offset

Returns

Name
Type
Description

value

uint24

The decoded value

decodeUint40

Internal function to decode a bytes32 sample into a uint40 using an offset

This function can overflow

function decodeUint40(bytes32 encoded, uint256 offset) internal pure returns (uint40 value);

Parameters

Name
Type
Description

encoded

bytes32

The encoded value

offset

uint256

The offset

Returns

Name
Type
Description

value

uint40

The decoded value

decodeUint64

Internal function to decode a bytes32 sample into a uint64 using an offset

This function can overflow

function decodeUint64(bytes32 encoded, uint256 offset) internal pure returns (uint64 value);

Parameters

Name
Type
Description

encoded

bytes32

The encoded value

offset

uint256

The offset

Returns

Name
Type
Description

value

uint64

The decoded value

decodeUint128

Internal function to decode a bytes32 sample into a uint128 using an offset

This function can overflow

function decodeUint128(bytes32 encoded, uint256 offset) internal pure returns (uint128 value);

Parameters

Name
Type
Description

encoded

bytes32

The encoded value

offset

uint256

The offset

Returns

Name
Type
Description

value

uint128

The decoded value

Git Source