Documentation ¶
Index ¶
- Constants
- Variables
- func AddDeltaInPlace(x *Uint128, y *Int128) error
- func CheckToUint160(value *Uint256) error
- func ComputePoolAddress(factoryAddress common.Address, tokenA *entities.Token, tokenB *entities.Token, ...) (common.Address, error)
- func ComputeSwapStep(sqrtRatioCurrentX96, sqrtRatioTargetX96 *Uint160, liquidity *Uint128, ...) error
- func DivRoundingUp(a, denominator, result *uint256.Int)
- func EncodeSqrtRatioX96(amount1 *big.Int, amount0 *big.Int) *big.Int
- func GetAmount0Delta(sqrtRatioAX96, sqrtRatioBX96, liquidity *big.Int, roundUp bool) *big.Int
- func GetAmount0DeltaV2(sqrtRatioAX96, sqrtRatioBX96 *Uint160, liquidity *Uint128, roundUp bool, ...) error
- func GetAmount1Delta(sqrtRatioAX96, sqrtRatioBX96, liquidity *big.Int, roundUp bool) *big.Int
- func GetAmount1DeltaV2(sqrtRatioAX96, sqrtRatioBX96 *Uint160, liquidity *Uint128, roundUp bool, ...) error
- func GetNextSqrtPriceFromInput(sqrtPX96 *Uint160, liquidity *Uint128, amountIn *uint256.Int, zeroForOne bool, ...) error
- func GetNextSqrtPriceFromOutput(sqrtPX96 *Uint160, liquidity *Uint128, amountOut *uint256.Int, zeroForOne bool, ...) error
- func GetSqrtRatioAtTick(tick int) (*big.Int, error)
- func GetSqrtRatioAtTickV2(tick int, result *Uint160) error
- func GetTickAtSqrtRatio(sqrtRatioX96 *big.Int) (int, error)
- func GetTickAtSqrtRatioV2(sqrtRatioX96 *Uint160) (int, error)
- func MaxLiquidityForAmounts(sqrtRatioCurrentX96 *big.Int, sqrtRatioAX96, sqrtRatioBX96 *big.Int, ...) *big.Int
- func MostSignificantBit(x *uint256.Int) (uint, error)
- func MulDiv(a, b, denominator *uint256.Int) (*uint256.Int, error)
- func MulDivRoundingUp(a, b, denominator *uint256.Int) (*uint256.Int, error)
- func MulDivRoundingUpV2(a, b, denominator, result *uint256.Int) error
- func MulDivV2(a, b, denominator, result, remainder *uint256.Int) error
- 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
- func ToInt256(value *Uint256, result *Int256) error
- func ToUInt256(value *Int256, result *Uint256) error
- type Int128
- type Int256
- type MethodParameters
- type Uint128
- type Uint160
- type Uint256
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. )
View Source
const MaxFeeInt = 1000000
Variables ¶
View Source
var ( ErrMulDivOverflow = errors.New("muldiv overflow") One = big.NewInt(1) )
View Source
var ( ErrExceedMaxInt256 = errors.New("exceed max int256") ErrOverflowUint128 = errors.New("overflow uint128") ErrOverflowUint160 = errors.New("overflow uint160") Uint128Max = uint256.MustFromHex("0xffffffffffffffffffffffffffffffff") Uint160Max = uint256.MustFromHex("0xffffffffffffffffffffffffffffffffffffffff") )
View Source
var ( ErrSqrtPriceLessThanZero = errors.New("sqrt price less than zero") ErrLiquidityLessThanZero = errors.New("liquidity less than zero") ErrInvariant = errors.New("invariant violation") ErrAddOverflow = errors.New("add overflow") )
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. Q32U256 = uint256.NewInt(1 << 32) MinSqrtRatioU256 = uint256.NewInt(4295128739) // The sqrt ratio corresponding to the minimum tick that could be used on any pool. MaxSqrtRatioU256 = uint256.MustFromDecimal("1461446703485210103287273052203988822378723970342") // 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")
View Source
var MaxFeeUint256 = uint256.NewInt(MaxFeeInt)
View Source
var MaxUint160 = uint256.MustFromHex("0xffffffffffffffffffffffffffffffffffffffff")
View Source
var (
MaxUint256 = uint256.MustFromHex("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")
)
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 ¶
deprecated
func GetAmount0DeltaV2 ¶
func GetAmount1Delta ¶
deprecated
func GetAmount1DeltaV2 ¶
func GetSqrtRatioAtTickV2 ¶
*
- 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 GetTickAtSqrtRatioV2 ¶
*
- 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 MulDivRoundingUp ¶
Calculates ceil(a×b÷denominator) with full precision
func MulDivRoundingUpV2 ¶
func MulDivV2 ¶
result=floor(a×b÷denominator), remainder=a×b%denominator (pass remainder=nil if not required) (the main usage for `remainder` is to be used in `MulDivRoundingUpV2` to determine if we need to round up, so it won't have to call MulMod again)
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
func ToHex ¶
*
- Converts a big int to a hex string
- @param bigintIsh
- @returns The hex encoded calldata
Types ¶
type MethodParameters ¶
Click to show internal directories.
Click to hide internal directories.