math

package
v0.0.0-...-3786997 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 10, 2023 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddLiquidity

func AddLiquidity(liquidityA, liquidityB sdk.Dec) (finalLiquidity sdk.Dec)

func CalcAmount0Delta

func CalcAmount0Delta(liq, sqrtPriceA, sqrtPriceB sdk.Dec, roundUp bool) sdk.Dec

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

func CalcAmount1Delta(liq, sqrtPriceA, sqrtPriceB sdk.Dec, roundUp bool) sdk.Dec

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

func Liquidity0(amount sdk.Int, sqrtPriceA, sqrtPriceB sdk.Dec) sdk.Dec

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

func Liquidity1(amount sdk.Int, sqrtPriceA, sqrtPriceB sdk.Dec) sdk.Dec

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

func MulRoundUp(a, b sdk.Dec) sdk.Dec

MulRoundUp multiplies a by b and rounds up to the nearest integer at precision end.

func PowTenInternal

func PowTenInternal(exponent sdk.Int) sdk.Dec

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

func PriceToTick(price sdk.Dec, exponentAtPriceOne sdk.Int) (sdk.Int, error)

PriceToTick takes a price and returns the corresponding tick index

func TickToSqrtPrice

func TickToSqrtPrice(tickIndex, exponentAtPriceOne sdk.Int) (price sdk.Dec, err error)

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().

func TicksToSqrtPrice

func TicksToSqrtPrice(lowerTick, upperTick int64, exponentAtPriceOne sdk.Int) (sdk.Dec, sdk.Dec, error)

TicksToSqrtPrice returns the sqrtPrice for the lower and upper ticks. Returns error if fails to calculate price. TODO: spec and tests

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL