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 RegisterTickDataProviderImpl(provider TickDataProvider)
- func Round(x float64) float64
- func ValidateList(ticks []Tick, tickSpacing int) error
- type GetInputAmountResult
- type GetOutputAmountResult
- type Pool
- func (p *Pool) ChainID() uint
- func (z *Pool) DecodeMsg(dc *msgp.Reader) (err error)
- func (z *Pool) EncodeMsg(en *msgp.Writer) (err error)
- func (p *Pool) GetInputAmount(outputAmount *entities.CurrencyAmount, sqrtPriceLimitX96 *big.Int) (*GetInputAmountResult, error)
- func (p *Pool) GetOutputAmount(inputAmount *entities.CurrencyAmount, sqrtPriceLimitX96 *big.Int) (*GetOutputAmountResult, error)
- func (p *Pool) InvolvesToken(token *entities.Token) bool
- func (z *Pool) MarshalMsg(b []byte) (o []byte, err error)
- func (z *Pool) Msgsize() (s int)
- func (p *Pool) PriceOf(token *entities.Token) (*entities.Price, error)
- func (p *Pool) Token0Price() *entities.Price
- func (p *Pool) Token1Price() *entities.Price
- func (z *Pool) UnmarshalMsg(bts []byte) (o []byte, err error)
- type StepComputations
- type SwapResult
- type Tick
- type TickDataProvider
- type TickDataProviderWrapper
- func (p *TickDataProviderWrapper) DecodeMsg(dc *msgp.Reader) (err error)
- func (p *TickDataProviderWrapper) EncodeMsg(en *msgp.Writer) (err error)
- func (p *TickDataProviderWrapper) Get() TickDataProvider
- func (p *TickDataProviderWrapper) MarshalMsg(b []byte) (o []byte, err error)
- func (p *TickDataProviderWrapper) Msgsize() int
- func (p *TickDataProviderWrapper) UnmarshalMsg(bts []byte) (o []byte, err error)
- type TickListDataProvider
- func (z *TickListDataProvider) DecodeMsg(dc *msgp.Reader) (err error)
- func (z *TickListDataProvider) EncodeMsg(en *msgp.Writer) (err error)
- func (p *TickListDataProvider) GetTick(tick int) (Tick, error)
- func (z *TickListDataProvider) MarshalMsg(b []byte) (o []byte, err error)
- func (z *TickListDataProvider) Msgsize() (s int)
- func (p *TickListDataProvider) NextInitializedTickIndex(tick int, lte bool) (int, bool, error)
- func (p *TickListDataProvider) NextInitializedTickWithinOneWord(tick int, lte bool, tickSpacing int) (int, bool, error)
- func (z *TickListDataProvider) UnmarshalMsg(bts []byte) (o []byte, err error)
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 RegisterTickDataProviderImpl ¶ added in v0.2.1
func RegisterTickDataProviderImpl(provider TickDataProvider)
RegisterTickDataProviderImpl registers the concrete types of an TickDataProvider. This function is not thread-safe and should be only call in init().
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 GetInputAmountResult ¶ added in v0.2.0
type GetInputAmountResult struct { ReturnedAmount *entities.CurrencyAmount RemainingAmountOut *entities.CurrencyAmount NewPoolState *Pool CrossInitTickLoops int }
type GetOutputAmountResult ¶ added in v0.2.0
type GetOutputAmountResult struct { ReturnedAmount *entities.CurrencyAmount RemainingAmountIn *entities.CurrencyAmount NewPoolState *Pool CrossInitTickLoops int }
type Pool ¶
type Pool struct { Token0 *entities.Token Token1 *entities.Token Fee constants.FeeAmount SqrtRatioX96 *big.Int Liquidity *big.Int TickCurrent int TickDataProvider *TickDataProviderWrapper // 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) (*GetInputAmountResult, 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) (*GetOutputAmountResult, 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) MarshalMsg ¶ added in v0.2.1
MarshalMsg implements msgp.Marshaler
func (*Pool) Msgsize ¶ added in v0.2.1
Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message
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 SwapResult ¶ added in v0.2.0
type SwapResult struct {
// contains filtered or unexported fields
}
type Tick ¶
func (*Tick) MarshalMsg ¶ added in v0.2.1
MarshalMsg implements msgp.Marshaler
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 TickDataProviderWrapper ¶ added in v0.2.1
type TickDataProviderWrapper struct {
TickDataProvider
}
TickDataProviderWrapper is a wrapper of TickDataProvider and is implemented msgp.Encodable, msgp.Decodable, msgp.Marshaler, msgp.Unmarshaler, and msgp.Sizer
func NewTickDataProviderWrapper ¶ added in v0.2.1
func NewTickDataProviderWrapper(provider TickDataProvider) *TickDataProviderWrapper
func (*TickDataProviderWrapper) DecodeMsg ¶ added in v0.2.1
func (p *TickDataProviderWrapper) DecodeMsg(dc *msgp.Reader) (err error)
DecodeMsg implements msgp.Decodable
func (*TickDataProviderWrapper) EncodeMsg ¶ added in v0.2.1
func (p *TickDataProviderWrapper) EncodeMsg(en *msgp.Writer) (err error)
EncodeMsg implements msgp.Encodable
func (*TickDataProviderWrapper) Get ¶ added in v0.2.1
func (p *TickDataProviderWrapper) Get() TickDataProvider
Get the inner TickDataProvider, return nil if TickDataProviderWrapper is nil
func (*TickDataProviderWrapper) MarshalMsg ¶ added in v0.2.1
func (p *TickDataProviderWrapper) MarshalMsg(b []byte) (o []byte, err error)
MarshalMsg implements msgp.Marshaler
func (*TickDataProviderWrapper) Msgsize ¶ added in v0.2.1
func (p *TickDataProviderWrapper) Msgsize() int
Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message
func (*TickDataProviderWrapper) UnmarshalMsg ¶ added in v0.2.1
func (p *TickDataProviderWrapper) UnmarshalMsg(bts []byte) (o []byte, err error)
UnmarshalMsg implements msgp.Unmarshaler
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) DecodeMsg ¶ added in v0.2.1
func (z *TickListDataProvider) DecodeMsg(dc *msgp.Reader) (err error)
DecodeMsg implements msgp.Decodable
func (*TickListDataProvider) EncodeMsg ¶ added in v0.2.1
func (z *TickListDataProvider) EncodeMsg(en *msgp.Writer) (err error)
EncodeMsg implements msgp.Encodable
func (*TickListDataProvider) GetTick ¶
func (p *TickListDataProvider) GetTick(tick int) (Tick, error)
func (*TickListDataProvider) MarshalMsg ¶ added in v0.2.1
func (z *TickListDataProvider) MarshalMsg(b []byte) (o []byte, err error)
MarshalMsg implements msgp.Marshaler
func (*TickListDataProvider) Msgsize ¶ added in v0.2.1
func (z *TickListDataProvider) Msgsize() (s int)
Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message
func (*TickListDataProvider) NextInitializedTickIndex ¶
func (*TickListDataProvider) NextInitializedTickWithinOneWord ¶
func (*TickListDataProvider) UnmarshalMsg ¶ added in v0.2.1
func (z *TickListDataProvider) UnmarshalMsg(bts []byte) (o []byte, err error)
UnmarshalMsg implements msgp.Unmarshaler