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
  • REAL_ID_SHIFT
  • Functions
  • getPriceFromId
  • getIdFromPrice
  • getBase
  • getExponent
  • convertDecimalPriceTo128x128
  • convert128x128PriceToDecimal
  1. Contracts
  2. Libraries

PriceHelper

PreviousPairParameterHelperNextReentrancyGuardUpgradeable

Last updated 8 days ago

Author: Trader Joe

This library contains functions to calculate prices

State Variables

REAL_ID_SHIFT

int256 private constant REAL_ID_SHIFT = 1 << 23;

Functions

getPriceFromId

Calculates the price from the id and the bin step

function getPriceFromId(uint24 id, uint16 binStep) internal pure returns (uint256 price);

Parameters

Name
Type
Description

id

uint24

The id

binStep

uint16

The bin step

Returns

Name
Type
Description

price

uint256

The price as a 128.128-binary fixed-point number

getIdFromPrice

Calculates the id from the price and the bin step

function getIdFromPrice(uint256 price, uint16 binStep) internal pure returns (uint24 id);

Parameters

Name
Type
Description

price

uint256

The price as a 128.128-binary fixed-point number

binStep

uint16

The bin step

Returns

Name
Type
Description

id

uint24

The id

getBase

Calculates the base from the bin step, which is 1 + binStep / BASIS_POINT_MAX

function getBase(uint16 binStep) internal pure returns (uint256);

Parameters

Name
Type
Description

binStep

uint16

The bin step

Returns

Name
Type
Description

<none>

uint256

base The base

getExponent

Calculates the exponent from the id, which is id - REAL_ID_SHIFT

function getExponent(uint24 id) internal pure returns (int256);

Parameters

Name
Type
Description

id

uint24

The id

Returns

Name
Type
Description

<none>

int256

exponent The exponent

convertDecimalPriceTo128x128

Converts a price with 18 decimals to a 128.128-binary fixed-point number

function convertDecimalPriceTo128x128(uint256 price) internal pure returns (uint256);

Parameters

Name
Type
Description

price

uint256

The price with 18 decimals

Returns

Name
Type
Description

<none>

uint256

price128x128 The 128.128-binary fixed-point number

convert128x128PriceToDecimal

Converts a 128.128-binary fixed-point number to a price with 18 decimals

function convert128x128PriceToDecimal(uint256 price128x128) internal pure returns (uint256);

Parameters

Name
Type
Description

price128x128

uint256

The 128.128-binary fixed-point number

Returns

Name
Type
Description

<none>

uint256

price The price with 18 decimals

Git Source