Documentation ¶
Index ¶
- Constants
- Variables
- func AddDelta(x, y *big.Int) *big.Int
- func ComputePoolAddress(factoryAddress common.Address, tokenA *entities.Token, tokenB *entities.Token, ...) (common.Address, error)
- func ComputeSwapStep(sqrtRatioCurrentX96, sqrtRatioTargetX96, liquidity, amountRemaining *big.Int, ...) (sqrtRatioNextX96, amountIn, amountOut, feeAmount *big.Int, err error)
- func EncodeSqrtRatioX96(amount1 *big.Int, amount0 *big.Int) *big.Int
- func GetAmount0Delta(sqrtRatioAX96, sqrtRatioBX96, liquidity *big.Int, roundUp bool) *big.Int
- func GetAmount1Delta(sqrtRatioAX96, sqrtRatioBX96, liquidity *big.Int, roundUp bool) *big.Int
- func GetNextSqrtPriceFromInput(sqrtPX96, liquidity, amountIn *big.Int, zeroForOne bool) (*big.Int, error)
- func GetNextSqrtPriceFromOutput(sqrtPX96, liquidity, amountOut *big.Int, zeroForOne bool) (*big.Int, error)
- func GetSqrtRatioAtTick(tick int) (*big.Int, error)
- func GetTickAtSqrtRatio(sqrtRatioX96 *big.Int) (int, error)
- func MaxLiquidityForAmounts(sqrtRatioCurrentX96 *big.Int, sqrtRatioAX96, sqrtRatioBX96 *big.Int, ...) *big.Int
- func MostSignificantBit(x *big.Int) (int64, error)
- func MulDivRoundingUp(a, b, denominator *big.Int) *big.Int
- func PriceToClosestTick(price *entities.Price, baseToken, quoteToken *entities.Token) (int, error)
- func TickToPrice(baseToken *entities.Token, quoteToken *entities.Token, tick int) (*entities.Price, error)
- func ToHex(i *big.Int) string
- type MethodParameters
Constants ¶
View Source
const ( MinTick = -887272 // The minimum tick that can be used on any pool. MaxTick = -MinTick // The maximum tick that can be used on any pool. )
Variables ¶
View Source
var ( ErrSqrtPriceLessThanZero = errors.New("sqrt price less than zero") ErrLiquidityLessThanZero = errors.New("liquidity less than zero") ErrInvariant = errors.New("invariant violation") )
View Source
var ( Q32 = big.NewInt(1 << 32) MinSqrtRatio = big.NewInt(4295128739) // The sqrt ratio corresponding to the minimum tick that could be used on any pool. MaxSqrtRatio, _ = new(big.Int).SetString("1461446703485210103287273052203988822378723970342", 10) // The sqrt ratio corresponding to the maximum tick that could be used on any pool. )
View Source
var ( ErrInvalidTick = errors.New("invalid tick") ErrInvalidSqrtRatio = errors.New("invalid sqrt ratio") )
View Source
var ErrInvalidInput = errors.New("invalid input")
Functions ¶
func ComputePoolAddress ¶
func ComputePoolAddress(factoryAddress common.Address, tokenA *entities.Token, tokenB *entities.Token, fee constants.FeeAmount, initCodeHashManualOverride string) (common.Address, error)
*
- Computes a pool address
- @param factoryAddress The Uniswap V3 factory address
- @param tokenA The first token of the pair, irrespective of sort order
- @param tokenB The second token of the pair, irrespective of sort order
- @param fee The fee tier of the pool
- @returns The pool address
func ComputeSwapStep ¶
func EncodeSqrtRatioX96 ¶
*
- Returns the sqrt ratio as a Q64.96 corresponding to a given ratio of amount1 and amount0
- @param amount1 The numerator amount i.e., the amount of token1
- @param amount0 The denominator amount i.e., the amount of token0
- @returns The sqrt ratio
func GetAmount0Delta ¶
func GetAmount1Delta ¶
func GetSqrtRatioAtTick ¶
*
- Returns the sqrt ratio as a Q64.96 for the given tick. The sqrt ratio is computed as sqrt(1.0001)^tick
- @param tick the tick for which to compute the sqrt ratio
func GetTickAtSqrtRatio ¶
*
- Returns the tick corresponding to a given sqrt ratio, s.t. #getSqrtRatioAtTick(tick) <= sqrtRatioX96
- and #getSqrtRatioAtTick(tick + 1) > sqrtRatioX96
- @param sqrtRatioX96 the sqrt ratio as a Q64.96 for which to compute the tick
func MaxLiquidityForAmounts ¶
func MaxLiquidityForAmounts(sqrtRatioCurrentX96 *big.Int, sqrtRatioAX96, sqrtRatioBX96 *big.Int, amount0, amount1 *big.Int, useFullPrecision bool) *big.Int
*
- Computes the maximum amount of liquidity received for a given amount of token0, token1,
- and the prices at the tick boundaries.
- @param sqrtRatioCurrentX96 the current price
- @param sqrtRatioAX96 price at lower boundary
- @param sqrtRatioBX96 price at upper boundary
- @param amount0 token0 amount
- @param amount1 token1 amount
- @param useFullPrecision if false, liquidity will be maximized according to what the router can calculate,
- not what core can theoretically support
func PriceToClosestTick ¶
*
- Returns the first tick for which the given price is greater than or equal to the tick price
- @param price for which to return the closest tick that represents a price less than or equal to the input price,
- i.e. the price of the returned tick is less than or equal to the input price
func TickToPrice ¶
func TickToPrice(baseToken *entities.Token, quoteToken *entities.Token, tick int) (*entities.Price, error)
*
- Returns a price object corresponding to the input tick and the base/quote token
- Inputs must be tokens because the address order is used to interpret the price represented by the tick
- @param baseToken the base token of the price
- @param quoteToken the quote token of the price
- @param tick the tick for which to return the price
Types ¶
type MethodParameters ¶
Click to show internal directories.
Click to hide internal directories.