Documentation
¶
Index ¶
- func AddLiquidity(liquidityA, liquidityB sdk.Dec) (finalLiquidity sdk.Dec)
- func CalcAmount0Delta(liq, sqrtPriceA, sqrtPriceB sdk.Dec, roundUp bool) sdk.Dec
- func CalcAmount1Delta(liq, sqrtPriceA, sqrtPriceB sdk.Dec, roundUp bool) sdk.Dec
- func CalculatePriceAndTicksPassed(price sdk.Dec, exponentAtPriceOne sdk.Int) (currentPrice sdk.Dec, ticksPassed sdk.Int, ...)
- func GetLiquidityFromAmounts(sqrtPrice, sqrtPriceA, sqrtPriceB sdk.Dec, amount0, amount1 sdk.Int) (liquidity sdk.Dec)
- func GetMinAndMaxTicksFromExponentAtPriceOneInternal(exponentAtPriceOne sdk.Int) (minTick, maxTick int64)
- func GetNextSqrtPriceFromAmount0RoundingUp(sqrtPriceCurrent, liquidity, amountRemaining sdk.Dec) (sqrtPriceNext sdk.Dec)
- func GetNextSqrtPriceFromAmount1RoundingDown(sqrtPriceCurrent, liquidity, amountRemaining sdk.Dec) (sqrtPriceNext sdk.Dec)
- func Liquidity0(amount sdk.Int, sqrtPriceA, sqrtPriceB sdk.Dec) sdk.Dec
- func Liquidity1(amount sdk.Int, sqrtPriceA, sqrtPriceB sdk.Dec) sdk.Dec
- func MulRoundUp(a, b sdk.Dec) sdk.Dec
- func PowTenInternal(exponent sdk.Int) sdk.Dec
- func PriceToTick(price sdk.Dec, exponentAtPriceOne sdk.Int) (sdk.Int, error)
- func TickToSqrtPrice(tickIndex, exponentAtPriceOne sdk.Int) (price sdk.Dec, err error)
- func TicksToSqrtPrice(lowerTick, upperTick int64, exponentAtPriceOne sdk.Int) (sdk.Dec, sdk.Dec, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CalcAmount0Delta ¶
CalcAmount0 takes the asset with the smaller liquidity in the pool as well as the sqrtpCur and the nextPrice and calculates the amount of asset 0 sqrtPriceA is the smaller of sqrtpCur and the nextPrice sqrtPriceB is the larger of sqrtpCur and the nextPrice CalcAmount0Delta = (liquidity * (sqrtPriceB - sqrtPriceA)) / (sqrtPriceB * sqrtPriceA)
func CalcAmount1Delta ¶
CalcAmount1 takes the asset with the smaller liquidity in the pool as well as the sqrtpCur and the nextPrice and calculates the amount of asset 1 sqrtPriceA is the smaller of sqrtpCur and the nextPrice sqrtPriceB is the larger of sqrtpCur and the nextPrice CalcAmount1Delta = liq * (sqrtPriceB - sqrtPriceA)
func CalculatePriceAndTicksPassed ¶
func CalculatePriceAndTicksPassed(price sdk.Dec, exponentAtPriceOne sdk.Int) (currentPrice sdk.Dec, ticksPassed sdk.Int, currentAdditiveIncrementInTicks osmomath.BigDec)
calculatePriceAndTicksPassed takes in a price and an exponentAtPriceOne, and returns the currentPrice, ticksPassed, and currentAdditiveIncrementInTicks. The function uses the geometricExponentIncrementDistanceInTicks formula to determine the number of ticks passed and the current additive increment in ticks. If the price is greater than 1, the function increments the exponentAtCurrentTick until the currentPrice is greater than the input price. If the price is less than 1, the function decrements the exponentAtCurrentTick until the currentPrice is less than the input price.
func GetLiquidityFromAmounts ¶
func GetLiquidityFromAmounts(sqrtPrice, sqrtPriceA, sqrtPriceB sdk.Dec, amount0, amount1 sdk.Int) (liquidity sdk.Dec)
getLiquidityFromAmounts takes the current sqrtPrice and the sqrtPrice for the upper and lower ticks as well as the amounts of asset0 and asset1 in return, liquidity is calculated from these inputs
func GetMinAndMaxTicksFromExponentAtPriceOneInternal ¶
func GetMinAndMaxTicksFromExponentAtPriceOneInternal(exponentAtPriceOne sdk.Int) (minTick, maxTick int64)
getMinAndMaxTicksFromExponentAtPriceOne determines min and max ticks allowed for a given exponentAtPriceOne value This allows for a min spot price of 0.000000000000000001 and a max spot price of 100000000000000000000000000000000000000 for every exponentAtPriceOne value
func GetNextSqrtPriceFromAmount0RoundingUp ¶
func GetNextSqrtPriceFromAmount0RoundingUp(sqrtPriceCurrent, liquidity, amountRemaining sdk.Dec) (sqrtPriceNext sdk.Dec)
getNextSqrtPriceFromAmount0RoundingUp utilizes the current squareRootPrice, liquidity of denom0, and amount of denom0 that still needs to be swapped in order to determine the next squareRootPrice TODO: make an issue to determine if we can remove the less precise formula
func GetNextSqrtPriceFromAmount1RoundingDown ¶
func GetNextSqrtPriceFromAmount1RoundingDown(sqrtPriceCurrent, liquidity, amountRemaining sdk.Dec) (sqrtPriceNext sdk.Dec)
getNextSqrtPriceFromAmount1RoundingDown utilizes the current squareRootPrice, liquidity of denom1, and amount of denom1 that still needs to be swapped in order to determine the next squareRootPrice
func Liquidity0 ¶
liquidity0 takes an amount of asset0 in the pool as well as the sqrtpCur and the nextPrice sqrtPriceA is the smaller of sqrtpCur and the nextPrice sqrtPriceB is the larger of sqrtpCur and the nextPrice Liquidity0 = amount0 * (sqrtPriceA * sqrtPriceB) / (sqrtPriceB - sqrtPriceA)
func Liquidity1 ¶
Liquidity1 takes an amount of asset1 in the pool as well as the sqrtpCur and the nextPrice sqrtPriceA is the smaller of sqrtpCur and the nextPrice sqrtPriceB is the larger of sqrtpCur and the nextPrice Liquidity1 = amount1 / (sqrtPriceB - sqrtPriceA)
func MulRoundUp ¶
MulRoundUp multiplies a by b and rounds up to the nearest integer at precision end.
func PowTenInternal ¶
powTen treats negative exponents as 1/(10**|exponent|) instead of 10**-exponent This is because the sdk.Dec.Power function does not support negative exponents
func PriceToTick ¶
PriceToTick takes a price and returns the corresponding tick index
func TickToSqrtPrice ¶
TickToSqrtPrice returns the sqrtPrice given the following two arguments:
- tickIndex: the tick index to calculate the price for
- exponentAtPriceOne: the value of the exponent (and therefore the precision) at which the starting price of 1 is set
If tickIndex is zero, the function returns sdk.OneDec().
Types ¶
This section is empty.