uniswapv3

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2022 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrPoolNotFound = errors.New("uniswap v3 factory: pool not found")
)
View Source
var (
	ErrWrongToken = errors.New("uniswap v3 pool: PriceOf: token not in pool")
)

Functions

func GetAmountsOut

func GetAmountsOut(price, lpValue, lowerPrice, upperPrice float64) (float64, float64)

Gets the amounts out for the current price and lpValue, given the lower and upper price bounds of the position.

func GetInitializedTickAtPrice

func GetInitializedTickAtPrice(price float64, tickSpace int) int64

Gets the initialized tick at a price given the tickspace. 5bps -> 10, 30bps -> 60, 100bps -> 200

func GetPriceAtTick

func GetPriceAtTick(tick int64) float64

Gets the price at the given tick.

func GetTickAtPrice

func GetTickAtPrice(price float64) int64

Gets the tick at the given price.

Types

type Pool

type Pool struct {
	Name    string
	Address common.Address

	Immutables PoolOpts
	State      PoolState // The last known Pool State
	// contains filtered or unexported fields
}

func Decode

func Decode(poolBytes []byte) (*Pool, error)

func NewPool

func NewPool(client *ethclient.Client, name string, poolAddress common.Address, immutables PoolOpts) (*Pool, error)

func (Pool) Encode

func (p Pool) Encode() ([]byte, error)

func (*Pool) PriceOf

func (p *Pool) PriceOf(token common.Address) (float64, error)

func (*Pool) UpdateState

func (p *Pool) UpdateState(ctx context.Context, client *ethclient.Client) error

UpdateState updates the internal pool state. Should be called every time the state changes on-chain i.e. on a new block. Note that cached pools should have their states refreshed as well. TODO: accept context

type PoolManager

type PoolManager interface {
	GetPool(token0, token1 common.Address, fee int64) (Pool, error)
	GetPoolAddress(token0, token1 common.Address, fee int64) (common.Address, error)
}

type PoolOpts

type PoolOpts struct {
	Token0 token.Token
	Token1 token.Token
	Fee    int64
}

type PoolState

type PoolState struct {
	SqrtPriceX96   *big.Int
	Tick           *big.Int
	Liquidity      *big.Int
	LiquidityGross *big.Int
	LiquidityNet   *big.Int
}

type UniswapV3

type UniswapV3 struct {
	Client *ethclient.Client

	PoolAddressCache db.Cacher // Holds the pool addresses for different assets and fee tiers
	PoolCache        db.Cacher // Holds the actual pools in a chained cache (checks memory first, then leveldb on disk)

	Factory *univ3factory.Univ3factoryCaller

	Opts db.Opts // Holds options
	// contains filtered or unexported fields
}

func New

func New(client *ethclient.Client, tokenManager token.TokenManager, factoryAddress common.Address, opts db.Opts) *UniswapV3

Returns a UniswapV3 instance.

func (*UniswapV3) GetPool

func (v3 *UniswapV3) GetPool(ctx context.Context, token0, token1 common.Address, fee int64) (*Pool, error)

func (*UniswapV3) GetPoolAddress

func (v3 *UniswapV3) GetPoolAddress(ctx context.Context, token0, token1 common.Address, fee int64) (common.Address, error)

func (*UniswapV3) GetPrice

func (v3 *UniswapV3) GetPrice(ctx context.Context, token0, token1 common.Address, fee int64) (float64, error)

func (*UniswapV3) UpdateCachedPoolStates

func (v3 *UniswapV3) UpdateCachedPoolStates(ctx context.Context) error

UpdateCachedPoolStates should get called once the chain state updates, i.e. on a new block. It retrieves all the pools from the cache, updates their states and writes them to cache again.

Jump to

Keyboard shortcuts

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