uniswap

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2022 License: LGPL-2.1 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FactoryAddrV3 = "0x1F98431c8aD98523631AE4a59f267346ea31F984"
	FactoryAddrV2 = "0x5c69bee701ef814a2b6a3edd4b1652cb9cc5aa6f"
)
View Source
const (
	MultiCallAddr    = "0x5ba1e12693dc8f9c48aad8770482f4739beed696"
	MultiFragmentAbi = `` /* 1297-byte string literal not displayed */
)
View Source
const (
	AddrSize = 20
	FeeSize  = 3
	Offset   = AddrSize + FeeSize
	DataSize = Offset + AddrSize
)

Variables

View Source
var (
	Address, _ = abi.NewType("address", "", nil)
	Uint24, _  = abi.NewType("uint24", "", nil)

	PoolInitCodeV3, _ = hex.DecodeString("e34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b54")
	PoolInitCodeV2, _ = hex.DecodeString("96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f")
)
View Source
var (
	X96 = decimal.NewFromInt(2).Pow(decimal.NewFromInt(96))
)

Functions

func CalculatePoolAddress added in v0.4.0

func CalculatePoolAddress(tokenA, tokenB, factoryAddr common.Address, poolInitCodeStr string) (poolAddr common.Address, err error)

CalculatePoolAddress calculate uniswapV2 like pool address from token and pool address and pool init code

func CalculatePoolAddressV2

func CalculatePoolAddressV2(token0, token1 string) (pairAddress common.Address, err error)

CalculatePoolAddressV2 calculate uniswapV2 pool address offline from pool tokens

func CalculatePoolAddressV3

func CalculatePoolAddressV3(tokenA, tokenB string, fee *big.Int) (poolAddress common.Address, err error)

CalculatePoolAddressV3 calculate uniswapV3 pool address offline from pool tokens and fee

func EncodePath

func EncodePath(path []common.Address, fees []int) (encoded []byte, err error)

EncodePath encode path to bytes

func MultiCall

func MultiCall(client *ethclient.Client, methodName string, opts *bind.CallOpts, multiCallParam []Multicall2Call) (out []interface{}, err error)

func SqrtPriceX96ToPrice

func SqrtPriceX96ToPrice(sqrtPriceX96 *big.Int, zeroForOne bool) (price decimal.Decimal)

SqrtPriceX96ToPrice convert uniswap v3 sqrt price in x96 format to decimal.Decimal zeroForOne true: price = token0/token1 false: price = token1/token0

Types

type Multicall2Call

type Multicall2Call struct {
	Target   common.Address
	CallData []byte
}

type Multicall2Result

type Multicall2Result struct {
	Success    bool
	ReturnData *big.Int
}

Jump to

Keyboard shortcuts

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