Documentation ¶
Index ¶
- Constants
- Variables
- func GetAddress(tokenA, tokenB *entities.Token, fee constants.FeeAmount, ...) (common.Address, error)
- func IsAtOrAboveLargest(ticks []Tick, tick int) (bool, error)
- func IsBelowSmallest(ticks []Tick, tick int) (bool, error)
- func NearestUsableTick(tick int, tickSpacing int) int
- func NextInitializedTickIndex(ticks []Tick, tick int, lte bool) (int, bool, error)
- func NextInitializedTickWithinOneWord(ticks []Tick, tick int, lte bool, tickSpacing int) (int, bool, error)
- func Round(x float64) float64
- func ValidateList(ticks []Tick, tickSpacing int) error
- type Pool
- func (p *Pool) ChainID() uint
- func (p *Pool) GetInputAmount(outputAmount *entities.CurrencyAmount, sqrtPriceLimitX96 *big.Int) (*entities.CurrencyAmount, *Pool, error)
- func (p *Pool) GetOutputAmount(inputAmount *entities.CurrencyAmount, sqrtPriceLimitX96 *big.Int) (*entities.CurrencyAmount, *Pool, error)
- func (p *Pool) InvolvesToken(token *entities.Token) bool
- func (p *Pool) PriceOf(token *entities.Token) (*entities.Price, error)
- func (p *Pool) Token0Price() *entities.Price
- func (p *Pool) Token1Price() *entities.Price
- type StepComputations
- type Tick
- type TickDataProvider
- type TickListDataProvider
Constants ¶
const ( ZeroValueTickIndex = 0 ZeroValueTickInitialized = false )
Variables ¶
var ( ErrFeeTooHigh = errors.New("Fee too high") ErrInvalidSqrtRatioX96 = errors.New("Invalid sqrtRatioX96") ErrTokenNotInvolved = errors.New("Token not involved in pool") ErrSqrtPriceLimitX96TooLow = errors.New("SqrtPriceLimitX96 too low") ErrSqrtPriceLimitX96TooHigh = errors.New("SqrtPriceLimitX96 too high") )
var ( ErrZeroTickSpacing = errors.New("tick spacing must be greater than 0") ErrInvalidTickSpacing = errors.New("invalid tick spacing") ErrZeroNet = errors.New("tick net delta must be zero") ErrSorted = errors.New("ticks must be sorted") ErrEmptyTickList = errors.New("empty tick list") ErrBelowSmallest = errors.New("below smallest") ErrAtOrAboveLargest = errors.New("at or above largest") ErrInvalidTickIndex = errors.New("invalid tick index") )
var (
EmptyTick = Tick{}
)
Functions ¶
func GetAddress ¶
func NearestUsableTick ¶
*
- Returns the closest tick that is nearest a given tick and usable for the given tick spacing
- @param tick the target tick
- @param tickSpacing the spacing of the pool
func Round ¶
Round like javascript Math.round Note that this differs from many languages' round() functions, which often round this case to the next integer away from zero, instead giving a different result in the case of negative numbers with a fractional part of exactly 0.5. For example, -1.5 rounds to -2, but -1.5 rounds to -1. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/round#description
func ValidateList ¶
Types ¶
type Pool ¶
type Pool struct { Token0 *entities.Token Token1 *entities.Token Fee constants.FeeAmount SqrtRatioX96 *big.Int Liquidity *big.Int TickCurrent int TickDataProvider TickDataProvider // contains filtered or unexported fields }
Represents a V3 pool
func NewPool ¶
func NewPool(tokenA, tokenB *entities.Token, fee constants.FeeAmount, sqrtRatioX96 *big.Int, liquidity *big.Int, tickCurrent int, ticks TickDataProvider) (*Pool, error)
*
- Construct a pool
- @param tokenA One of the tokens in the pool
- @param tokenB The other token in the pool
- @param fee The fee in hundredths of a bips of the input amount of every swap that is collected by the pool
- @param sqrtRatioX96 The sqrt of the current ratio of amounts of token1 to token0
- @param liquidity The current value of in range liquidity
- @param tickCurrent The current tick of the pool
- @param ticks The current state of the pool ticks or a data provider that can return tick data
func (*Pool) GetInputAmount ¶
func (p *Pool) GetInputAmount(outputAmount *entities.CurrencyAmount, sqrtPriceLimitX96 *big.Int) (*entities.CurrencyAmount, *Pool, error)
*
- Given a desired output amount of a token, return the computed input amount and a pool with state updated after the trade
- @param outputAmount the output amount for which to quote the input amount
- @param sqrtPriceLimitX96 The Q64.96 sqrt price limit. If zero for one, the price cannot be less than this value after the swap. If one for zero, the price cannot be greater than this value after the swap
- @returns The input amount and the pool with updated state
func (*Pool) GetOutputAmount ¶
func (p *Pool) GetOutputAmount(inputAmount *entities.CurrencyAmount, sqrtPriceLimitX96 *big.Int) (*entities.CurrencyAmount, *Pool, error)
*
- Given an input amount of a token, return the computed output amount, and a pool with state updated after the trade
- @param inputAmount The input amount for which to quote the output amount
- @param sqrtPriceLimitX96 The Q64.96 sqrt price limit
- @returns The output amount and the pool with updated state
func (*Pool) InvolvesToken ¶
*
- Returns true if the token is either token0 or token1
- @param token The token to check
- @returns True if token is either token0 or token
func (*Pool) PriceOf ¶
*
- Return the price of the given token in terms of the other token in the pool.
- @param token The token to return price of
- @returns The price of the given token, in terms of the other.
func (*Pool) Token0Price ¶
Token0Price returns the current mid price of the pool in terms of token0, i.e. the ratio of token1 over token0
func (*Pool) Token1Price ¶
Token1Price returns the current mid price of the pool in terms of token1, i.e. the ratio of token0 over token1
type StepComputations ¶
type StepComputations struct {
// contains filtered or unexported fields
}
type TickDataProvider ¶
type TickDataProvider interface { /** * Return information corresponding to a specific tick * @param tick the tick to load */ GetTick(tick int) (Tick, error) /** * Return the next tick that is initialized within a single word * @param tick The current tick * @param lte Whether the next tick should be lte the current tick * @param tickSpacing The tick spacing of the pool */ NextInitializedTickWithinOneWord(tick int, lte bool, tickSpacing int) (int, bool, error) // NextInitializedTickIndex return the next tick that is initialized NextInitializedTickIndex(tick int, lte bool) (int, bool, error) }
Provides information about ticks
type TickListDataProvider ¶
type TickListDataProvider struct {
// contains filtered or unexported fields
}
A data provider for ticks that is backed by an in-memory array of ticks.
func NewTickListDataProvider ¶
func NewTickListDataProvider(ticks []Tick, tickSpacing int) (*TickListDataProvider, error)
func (*TickListDataProvider) GetTick ¶
func (p *TickListDataProvider) GetTick(tick int) (Tick, error)