uniswap

package
v0.0.23 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2021 License: Apache-2.0 Imports: 10 Imported by: 1

Documentation

Overview

Package uniswap provdies a Golang client wrapper for UniswapV2

Package uniswap contains the required bindings as well as corresponding wrappers for those bindings for interacting with the uniswap smart contracts.

Index

Constants

This section is empty.

Variables

View Source
var FactoryAddress = common.HexToAddress("0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f")

FactoryAddress points to the uniswap factory.

View Source
var Router02Address = common.HexToAddress("0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D")

Router02Address points to the uniswap v2 02 router.

Functions

func GeneratePairAddress

func GeneratePairAddress(token0, token1 common.Address) common.Address

GeneratePairAddress generates a pair address for the given tokens

func Quote

func Quote(amount, reserve0, reserve1 *big.Int) *big.Int

Quote gets the exchange quote for a given amount of tokens and the respective pairs reserves.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client allows to do operations on uniswap smart contracts.

func NewClient

func NewClient(bc *ethclient.Client) *Client

NewClient returns a new instance of uniswap client.

func (*Client) GetExchangeAmount

func (c *Client) GetExchangeAmount(amount *big.Int, token0, token1 common.Address) (*big.Int, error)

GetExchangeAmount returns the amount of tokens you'd receive when exchanging the given amount of token0 to token1.

func (*Client) GetExchangeAmountForPath

func (c *Client) GetExchangeAmountForPath(amount *big.Int, tokens ...common.Address) (*big.Int, error)

GetExchangeAmountForPath calculates the amount for a given path.

func (*Client) GetReserves

func (c *Client) GetReserves(token0, token1 common.Address) (*Reserve, error)

GetReserves retursn the available reserves in a pair

type Pair

type Pair struct {
	Token0, Token1 common.Address
}

Pair represents a token pair.

func GetPathPairs

func GetPathPairs(tokens []common.Address) []Pair

GetPathPairs takes in the given token path and returns the corresponding pairs.

type Reserve

type Reserve struct {
	Reserve0           *big.Int // Token
	Reserve1           *big.Int // QuoteToken
	BlockTimestampLast uint32
}

Reserve represents a given uniswap pair reserve

Jump to

Keyboard shortcuts

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