Pricing
This library implements the functions necessary for computing price movements within a tick range.
WARNING: This library should not be used for computations that span multiple ticks. Instead, the user should use the functions of this library to simplify computations for more complex price calculations.
Functions
proportion
Returns the percentage by which the market price has passed through the lower and upper prices from left to right. Reverts if the market price is not within the range of the lower and upper prices.
function proportion(UD60x18 lower, UD60x18 upper, UD50x28 marketPrice) internal pure returns (UD50x28);
proportion
Returns the percentage by which the market price has passed through the lower and upper prices from left to right. Reverts if the market price is not within the range of the lower and upper prices.
function proportion(Args memory args) internal pure returns (UD50x28);
amountOfTicksBetween
Find the number of ticks of an active tick range. Used to compute the aggregate, bid or ask liquidity either of the pool or the range order.
min_tick_distance = 0.01
lower = 0.01
upper = 0.03
num_ticks = 2
0.01 0.02 0.03
|xxxxxxxxxxxxxxxxxx|xxxxxxxxxxxxxxxxxx|
Then there are two active ticks, 0.01 and 0.02, within the active tick range.
function amountOfTicksBetween(UD60x18 lower, UD60x18 upper) internal pure returns (UD60x18);
amountOfTicksBetween
Returns the number of ticks between args.lower
and args.upper
function amountOfTicksBetween(Args memory args) internal pure returns (UD60x18);
liquidity
Returns the liquidity between args.lower
and args.upper
function liquidity(Args memory args) internal pure returns (UD60x18);
bidLiquidity
Returns the bid-side liquidity between args.lower
and args.upper
function bidLiquidity(Args memory args) internal pure returns (UD60x18);
askLiquidity
Returns the ask-side liquidity between args.lower
and args.upper
function askLiquidity(Args memory args) internal pure returns (UD60x18);
maxTradeSize
Returns the maximum trade size (askLiquidity or bidLiquidity depending on the TradeSide).
function maxTradeSize(Args memory args) internal pure returns (UD60x18);
price
Computes price reached from the current lower/upper tick after buying/selling trade_size
amount of
contracts
function price(Args memory args, UD60x18 tradeSize) internal pure returns (UD50x28);
nextPrice
Gets the next market price within a tick range after buying/selling tradeSize
amount of contracts
function nextPrice(Args memory args, UD60x18 tradeSize) internal pure returns (UD50x28);
Structs
Args
struct Args {
UD50x28 liquidityRate;
UD50x28 marketPrice;
UD60x18 lower;
UD60x18 upper;
bool isBuy;
}