Documentation ¶
Index ¶
- Variables
- func AddLiquidityDelta(x *big.Int, y *big.Int) (z *big.Int)
- func ComputeSwapStep(sqrtRatioCurrentX96 *big.Int, sqrtRatioTargetX96 *big.Int, liquidity *big.Int, ...) (sqrtRatioNextX96 *big.Int, amountIn *big.Int, amountOut *big.Int, ...)
- func DivRoundingUp(a *big.Int, b *big.Int) (result *big.Int)
- func DoSwap(zeroForOne bool, amountSpecified *big.Int, sqrtPriceLimitX96 *big.Int, ...) (amount0 *big.Int, amount1 *big.Int, feeTotal *big.Int)
- func GetAmount0Delta(sqrtRatioAX96 *big.Int, sqrtRatioBX96 *big.Int, liquidity *big.Int) (amount0 *big.Int)
- func GetAmount0DeltaRoundingUp(sqrtRatioAX96 *big.Int, sqrtRatioBX96 *big.Int, liquidity *big.Int, ...) (amount0 *big.Int)
- func GetAmount1Delta(sqrtRatioAX96 *big.Int, sqrtRatioBX96 *big.Int, liquidity *big.Int) (amount1 *big.Int)
- func GetAmount1DeltaRoundingUp(sqrtRatioAX96 *big.Int, sqrtRatioBX96 *big.Int, liquidity *big.Int, ...) (amount1 *big.Int)
- func GetMaxValue(bitsCount uint) *big.Int
- func GetNextSqrtPriceFromInput(sqrtPX96 *big.Int, liquidity *big.Int, amountIn *big.Int, zeroForOne bool) (sqrtQX96 *big.Int)
- func GetNextSqrtPriceFromOutput(sqrtPX96 *big.Int, liquidity *big.Int, amountOut *big.Int, zeroForOne bool) (sqrtQX96 *big.Int)
- func GetSqrtRatioAtTick(tick *big.Int) *big.Int
- func GetTickAtSqrtRatio(sqrtPriceX96 *big.Int) *big.Int
- func MulDiv(a *big.Int, b *big.Int, denominator *big.Int) (result *big.Int)
- func MulDivChn(a *big.Int, b *big.Int, denominator *big.Int) (result *big.Int)deprecated
- func MulDivRoundingUp(a *big.Int, b *big.Int, denominator *big.Int) (result *big.Int)
- type BigDecimal
- type BigInt
- type FieldId
- type Pool
- type PoolStateReader
- type Slot0
- type StepComputations
- func (step *StepComputations) ApplyTickLimits()
- func (step *StepComputations) CalcSqrtPriceNextX96()
- func (step *StepComputations) GetSqrtRatioTargetX96(zeroForOne bool, sqrtPriceLimitX96 *big.Int) (sqrtRatioTargetX96 *big.Int)
- func (step *StepComputations) UpdateAmount(zeroForOne bool, sqrtPriceLimitX96 *big.Int, state *SwapState, slot0 *Slot0) (sqrtPriceX96 *big.Int)
- func (step *StepComputations) UpdateSqrtPriceStartX96(state *SwapState)
- func (step *StepComputations) UpdateTickNext(zeroForOne bool, state *SwapState, ticker TickReader)
- type Swap
- type SwapCache
- type SwapState
- type Tick
- type TickReader
- type TickStorage
- type Token
- type Tx
Constants ¶
This section is empty.
Variables ¶
var A [19]*big.Int
var B [19]*big.Int
var C [7]*big.Int
var INIT0 *big.Int
var INIT1 *big.Int
var LOWER_ERR_BOUND *big.Int
var MAX_SQRT_RATIO *big.Int
The maximum value that can be returned from #getSqrtRatioAtTick. Equivalent to getSqrtRatioAtTick(MAX_TICK)
var MAX_TICK *big.Int
The maximum tick that may be passed to #getSqrtRatioAtTick computed from log base 1.0001 of 2**128
var MAX_UINT_160 *big.Int
var MAX_UINT_256 *big.Int
var MIN_SQRT_RATIO *big.Int
The minimum value that can be returned from #getSqrtRatioAtTick. Equivalent to getSqrtRatioAtTick(MIN_TICK)
var MIN_TICK *big.Int
The minimum tick that may be passed to #getSqrtRatioAtTick computed from log base 1.0001 of 2**-128
var ONE_UINT_256 *big.Int
var SQRT_10001 *big.Int
var UPPER_ERR_BOUND *big.Int
var ZERO_UINT_256 *big.Int
Functions ¶
func ComputeSwapStep ¶
func DivRoundingUp ¶
Origin: https://github.com/Uniswap/v3-core/blob/main/contracts/libraries/UnsafeMath.sol
func DoSwap ¶
func DoSwap(zeroForOne bool, amountSpecified *big.Int, sqrtPriceLimitX96 *big.Int, ticker TickReader, slotReader PoolStateReader) (amount0 *big.Int, amount1 *big.Int, feeTotal *big.Int)
Swap token0 for token1, or token1 for token0 zeroForOne bool The direction of the swap, true for token0 to token1, false for token1 to token0 amountSpecified big.Int The amount of the swap, which implicitly configures the swap as exact input (positive), or exact output (negative) sqrtPriceLimitX96 big.Int The Q64.96 sqrt price limit. If zero for one, the price cannot be less than this ticker TickReader tick bitmap object slotReader PoolStateReader Pool's state retriever object amount0 big.Int The delta of the balance of token0 of the pool, exact when negative, minimum when positive amount1 big.Int The delta of the balance of token1 of the pool, exact when negative, minimum when positive
func GetAmount0Delta ¶
func GetAmount0DeltaRoundingUp ¶
func GetAmount0DeltaRoundingUp( sqrtRatioAX96 *big.Int, sqrtRatioBX96 *big.Int, liquidity *big.Int, roundUp bool) (amount0 *big.Int)
Calculates liquidity / sqrt(lower) - liquidity / sqrt(upper), i.e. liquidity * (sqrt(upper) - sqrt(lower)) / (sqrt(upper) * sqrt(lower)) http://atiselsts.github.io/pdfs/uniswap-v3-liquidity-math.pdf
func GetAmount1Delta ¶
func GetAmount1DeltaRoundingUp ¶
func GetAmount1DeltaRoundingUp( sqrtRatioAX96 *big.Int, sqrtRatioBX96 *big.Int, liquidity *big.Int, roundUp bool) (amount1 *big.Int)
Calculates liquidity * (sqrt(upper) - sqrt(lower)) http://atiselsts.github.io/pdfs/uniswap-v3-liquidity-math.pdf
func GetMaxValue ¶
func GetSqrtRatioAtTick ¶
Ported function getSqrtRatioAtTick(int24 tick) internal pure returns (uint160 sqrtPriceX96) Source: https://github.com/Uniswap/v3-core/blob/main/contracts/libraries/TickMath.sol tick int24 return int96 sqrtPriceX96
func GetTickAtSqrtRatio ¶
Ported function getTickAtSqrtRatio(uint160 sqrtPriceX96) internal pure returns (int24 tick) Source: https://github.com/Uniswap/v3-core/blob/main/contracts/libraries/TickMath.sol sqrtPriceX96 int96 return tick int24
Types ¶
type BigDecimal ¶
func (*BigDecimal) UnmarshalJSON ¶
func (bi *BigDecimal) UnmarshalJSON(data []byte) error
type BigInt ¶
func (*BigInt) UnmarshalJSON ¶
type Pool ¶
type Pool struct { Id string CreatedAtTimestamp BigInt CreatedAtBlockNumber BigInt Token0 Token Token1 Token FeeTier BigInt Liquidity BigInt SqrtPrice BigInt FeeGrowthGlobal0X128 BigInt FeeGrowthGlobal1X128 BigInt Token0Price BigDecimal Token1Price BigDecimal Tick BigInt ObservationIndex BigInt VolumeToken0 BigDecimal VolumeToken1 BigDecimal VolumeUSD BigDecimal UntrackedVolumeUSD BigDecimal FeesUSD BigDecimal TxCount BigInt CollectedFeesToken0 BigDecimal CollectedFeesToken1 BigDecimal CollectedFeesUSD BigDecimal TotalValueLockedToken0 BigDecimal TotalValueLockedToken1 BigDecimal TotalValueLockedETH BigDecimal TotalValueLockedUSD BigDecimal TotalValueLockedUSDUntracked BigDecimal LiquidityProviderCount BigInt Swaps []Swap Ticks []Tick }
func (Pool) CurrentState ¶
func (Pool) FeerTierToTickSpacing ¶
type PoolStateReader ¶
type PoolStateReader interface {
CurrentState() *Slot0
}
type Slot0 ¶
type Slot0 struct { TickSpacing *big.Int Fee *big.Int Liquidity *big.Int FeeGrowthGlobal0X128 *big.Int FeeGrowthGlobal1X128 *big.Int // the current price SqrtPriceX96 *big.Int // the current tick TickCurrent *big.Int // the most-recently updated index of the observations array ObservationIndex *big.Int // the current maximum number of observations that are being stored ObservationCardinality *big.Int // the next maximum number of observations to store, triggered in observations.write ObservationCardinalityNext *big.Int // the current protocol fee as a percentage of the swap fee taken on withdrawal // represented as an integer denominator (1/x)% FeeProtocol *big.Int }
type StepComputations ¶
type StepComputations struct {
// contains filtered or unexported fields
}
func NewStepComputations ¶
func NewStepComputations() *StepComputations
func (*StepComputations) ApplyTickLimits ¶
func (step *StepComputations) ApplyTickLimits()
func (*StepComputations) CalcSqrtPriceNextX96 ¶
func (step *StepComputations) CalcSqrtPriceNextX96()
func (*StepComputations) GetSqrtRatioTargetX96 ¶
func (*StepComputations) UpdateAmount ¶
func (*StepComputations) UpdateSqrtPriceStartX96 ¶
func (step *StepComputations) UpdateSqrtPriceStartX96(state *SwapState)
func (*StepComputations) UpdateTickNext ¶
func (step *StepComputations) UpdateTickNext(zeroForOne bool, state *SwapState, ticker TickReader)
type Swap ¶
type Swap struct { Id string Transaction Tx Timestamp BigInt Pool FieldId Token0 Token Token1 Token Sender string Recipient string Origin string Amount0 BigDecimal Amount1 BigDecimal AmountUSD BigDecimal SqrtPriceX96 BigInt Tick BigInt LogIndex BigInt }
type SwapCache ¶
type SwapCache struct {
// contains filtered or unexported fields
}
func NewSwapCache ¶
type SwapState ¶
type SwapState struct {
// contains filtered or unexported fields
}
the top level state of the swap, the results of which are recorded in storage at the end
func NewSwapState ¶
func (*SwapState) UpdateAmount ¶
func (state *SwapState) UpdateAmount(exactInput bool, step *StepComputations)
func (*SwapState) UpdateTickLiquidity ¶
func (state *SwapState) UpdateTickLiquidity(zeroForOne bool, step *StepComputations, ticker TickReader)
type Tick ¶
type Tick struct { Id string PoolAddress string TickIdx BigInt Pool FieldId LiquidityGross BigInt LiquidityNet BigInt Price0 BigDecimal Price1 BigDecimal VolumeToken0 BigDecimal VolumeToken1 BigDecimal VolumeUSD BigDecimal UntrackedVolumeUSD BigDecimal FeesUSD BigDecimal CollectedFeesToken0 BigDecimal CollectedFeesToken1 BigDecimal CollectedFeesUSD BigDecimal CreatedAtTimestamp BigInt CreatedAtBlockNumber BigInt LiquidityProviderCount BigInt FeeGrowthOutside0X128 BigInt FeeGrowthOutside1X128 BigInt }
func (Tick) IsInitialized ¶
type TickReader ¶
type TickStorage ¶
func NewTickStorage ¶
func NewTickStorage(ticks []Tick, tickSpacing *big.Int) *TickStorage
func (TickStorage) GetLiquidityNet ¶
func (t TickStorage) GetLiquidityNet(tick *big.Int) *big.Int
func (TickStorage) IsInitialized ¶
func (t TickStorage) IsInitialized(tickKey *big.Int) bool
func (TickStorage) NextInitializedTick ¶
type Token ¶
type Token struct { Id string Symbol string Name string Decimals BigInt TotalSupply BigInt Volume BigDecimal VolumeUSD BigDecimal UntrackedVolumeUSD BigDecimal FeesUSD BigDecimal TxCount BigInt PoolCount BigInt TotalValueLocked BigDecimal TotalValueLockedUSD BigDecimal TotalValueLockedUSDUntracked BigDecimal DerivedETH BigDecimal }