entities

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 2, 2024 License: MIT Imports: 7 Imported by: 1

Documentation

Index

Constants

View Source
const (
	ZeroValueTickIndex       = 0
	ZeroValueTickInitialized = false
)

Variables

View Source
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")
)
View Source
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")
)
View Source
var (
	EmptyTick = Tick{}
)

Functions

func GetAddress

func GetAddress(tokenA, tokenB *entities.Token, fee constants.FeeAmount, initCodeHashManualOverride string) (common.Address, error)

func IsAtOrAboveLargest

func IsAtOrAboveLargest(ticks []Tick, tick int) (bool, error)

func IsBelowSmallest

func IsBelowSmallest(ticks []Tick, tick int) (bool, error)

func NearestUsableTick

func NearestUsableTick(tick int, tickSpacing int) int

*

  • 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 NextInitializedTickIndex

func NextInitializedTickIndex(ticks []Tick, tick int, lte bool) (int, bool, error)

func NextInitializedTickWithinOneWord

func NextInitializedTickWithinOneWord(ticks []Tick, tick int, lte bool, tickSpacing int) (int, bool, error)

func Round

func Round(x float64) float64

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

func ValidateList(ticks []Tick, tickSpacing int) error

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 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) ChainID

func (p *Pool) ChainID() uint

ChainId returns the chain ID of the tokens in the pool.

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

func (p *Pool) InvolvesToken(token *entities.Token) bool

*

  • 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

func (p *Pool) PriceOf(token *entities.Token) (*entities.Price, error)

*

  • 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

func (p *Pool) Token0Price() *entities.Price

Token0Price returns the current mid price of the pool in terms of token0, i.e. the ratio of token1 over token0

func (*Pool) Token1Price

func (p *Pool) Token1Price() *entities.Price

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

type Tick struct {
	Index          int
	LiquidityGross *big.Int
	LiquidityNet   *big.Int
}

func GetTick

func GetTick(ticks []Tick, index int) (Tick, error)

func NextInitializedTick

func NextInitializedTick(ticks []Tick, tick int, lte bool) (Tick, error)

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)

func (*TickListDataProvider) NextInitializedTickIndex

func (p *TickListDataProvider) NextInitializedTickIndex(tick int, lte bool) (int, bool, error)

func (*TickListDataProvider) NextInitializedTickWithinOneWord

func (p *TickListDataProvider) NextInitializedTickWithinOneWord(tick int, lte bool, tickSpacing int) (int, bool, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL