PriceHelper
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
id
uint24
The id
binStep
uint16
The bin step
Returns
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
price
uint256
The price as a 128.128-binary fixed-point number
binStep
uint16
The bin step
Returns
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
binStep
uint16
The bin step
Returns
<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
id
uint24
The id
Returns
<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
price
uint256
The price with 18 decimals
Returns
<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
price128x128
uint256
The 128.128-binary fixed-point number
Returns
<none>
uint256
price The price with 18 decimals
Last updated