DiverSqrtPriceMath
Contains the math that uses liquidity to compute token deltas or square root of price as a Q64.96
Last updated
Contains the math that uses liquidity to compute token deltas or square root of price as a Q64.96
Last updated
Gets the delta amount of Spear or Shield tokens based on the given sqrt ratios and liquidity. Computes for Spear token delta when the sqrtPrice moves from upper to lower; or Shield token delta when the sqrtPrice moves from lower to upper. For the same sqrt ratio range and liquidity, the computed delta amounts of Spear and Shield are equal.
The formula for this is spear or shield delta amount = liquidity * (sqrtRatioBX96 - sqrtRatioAX96) * (1 + 1 /(sqrtRatioAX96 * sqrtRatioBX96))
Params:
Returns:
Helper that gets signed spear or shield token delta
Params:
Returns:
Gets the next sqrt ratio based on the given the Spear token delta and liquidity.
Params:
Returns:
Gets the next sqrt ratio based on the given the Shield token delta and liquidity.
Params:
Returns:
Name
Type
Description
sqrtRatioAX96
uint160
A sqrt ratio
sqrtRatioBX96
uint160
Another sqrt ratio
liquidity
uint128
The change in liquidity for which to compute the Spear or Shield token delta
roundUp
bool
Whether to round the amount up or down
Name
Type
Description
amount
uint256
The amount of Spear or Shield token corresponding to the passed liquidityDelta between the two prices
Name
Type
Description
sqrtRatioAX96
uint160
A sqrt ratio
sqrtRatioBX96
uint160
Another sqrt ratio
liquidity
int128
The change in liquidity for which to compute the Spear or Shield token delta
Name
Type
Description
amount
int256
The amount of Spear or Shield token corresponding to the passed liquidityDelta between the two prices
Name
Type
Description
sqrtPrice
uint160
The starting price, i.e. before accounting for the spear token delta
liquidity
uint128
The amount of usable liquidity
amount
uint256
The amount of Spear token delta to mint for the trade
unit
uint256
The token decimal unit, e.g. a token with 18 decimals has a unit of 10**18
Name
Type
Description
nextSqrtPrice
uint160
The next sqrt ratio after minting the given amount of Spear tokens
Name
Type
Description
sqrtPrice
uint160
The starting price, i.e. before accounting for the Shield token delta
liquidity
uint128
The amount of usable liquidity
amount
uint256
The amount of Shield token delta to mint for the trade
unit
uint256
The token decimal unit, e.g. a token with 18 decimals has a unit of 10**18
Name
Type
Description
nextSqrtPrice
uint160
The next sqrt ratio after minting the given amount of Shield tokens