Documentation
¶
Index ¶
- Constants
- Variables
- func GetActualPriceImpact(trade *uniswap.Trade, dexFee *big.Int) float64
- func GetChainID(url string) (*big.Int, error)
- func ValidateEndpointURL(url string, chainID uint32) bool
- type Client
- func (c *Client) CheckListed(token0, token1 *database.Token, dex *database.Dex, weth string, ...) (*uniswap.Trade, error)
- func (c *Client) GetBalanceOf(address string, contract string) (*big.Int, error)
- func (c *Client) GetBalanceOfToken(address string, token *database.Token) (*big.Int, error)
- func (c *Client) GetBestOrderTrades(token0, token1 *database.Token, buyAmount, sellAmount *big.Int, ...) (*uniswap.Trade, *uniswap.Trade, error)
- func (c *Client) GetBestTradeExactIn(token0, token1 *database.Token, amount *big.Int, dex *database.Dex, ...) (*uniswap.Trade, error)
- func (c *Client) GetBestTradeExactOut(token0, token1 *database.Token, amount *big.Int, dex *database.Dex, ...) (*uniswap.Trade, error)
- func (c *Client) GetPairInfo(contracts ...string) (map[string]*Pair, error)
- func (c *Client) GetTokenInfo(contracts ...string) (map[string]*database.Token, error)
- func (c *Client) GetValidPairTokens(tokens []*database.Token, factory string) ([]string, error)
- func (c *Client) NewRouter(contract string) (*uniswapv2router2.Uniswapv2router2, error)
- func (c *Client) Swap(wallet *database.Wallet, trade *database.Trade, target *database.Target) (*types.Transaction, error)
- func (c *Client) TradeDispatcher(ctx context.Context, cancel context.CancelFunc, wallet *database.Wallet, ...)
- type Pair
- type Price
- func (p *Price) BuyTrade() (*uniswap.Trade, error)
- func (p *Price) GetBuyAmount() *big.Int
- func (p *Price) GetBuyTrade() *uniswap.Trade
- func (p *Price) GetError() error
- func (p *Price) GetHeartbeatRunning() bool
- func (p *Price) GetRunning() bool
- func (p *Price) GetSellAmount() *big.Int
- func (p *Price) GetSellTrade() *uniswap.Trade
- func (p *Price) GetTrades() (*uniswap.Trade, *uniswap.Trade)
- func (p *Price) SellTrade() (*uniswap.Trade, error)
- func (p *Price) SetBuyAmount(amount *big.Int)
- func (p *Price) SetHeartbeat(running bool)
- func (p *Price) SetPriceResult(r PriceResult)
- func (p *Price) SetSellAmount(amount *big.Int)
- func (p *Price) StartFeed(c *Client, token0, token1 *database.Token, dex *database.Dex, ...)
- func (p *Price) Stop()
- type PriceResult
- type TokenPair
Constants ¶
const Zero = "0x0000000000000000000000000000000000000000"
Variables ¶
var ( ErrNoBuyTrade = errors.New("no buy trade found") ErrNoSellTrade = errors.New("no sell trade found") )
var ( ErrNoPathFound = errors.New("no path found") ErrNoPairsFound = errors.New("no pairs found") ErrNoTradeFound = errors.New("no trade found") ErrNoMidPriceFound = errors.New("no mid price found") ErrParsingPrice = errors.New("failed to parse price") )
var ( ErrTxTimeout = errors.New("transaction timed out") ErrCancelNow = errors.New("canceling now") )
var ErrExecutionReverted = errors.New("error no contracts")
var ErrNoContracts = errors.New("error no contracts")
Functions ¶
func GetActualPriceImpact ¶
GetActualPriceImpact returns the price impact of the given trade. The dex fee gets subtracted from the impact for every trade in the route.
func GetChainID ¶
GetChainID returns the chain id of the given node url.
func ValidateEndpointURL ¶
ValidateEndpointURL validates the given node url by trying to fetch the chain id.
Types ¶
type Client ¶
func (*Client) CheckListed ¶
func (c *Client) CheckListed(token0, token1 *database.Token, dex *database.Dex, weth string, tokens []*database.Token) (*uniswap.Trade, error)
CheckListed checks if there is an available trading route for two given tokens. If there is no route, chain.ErrNoTradeFound is returned so you should check against that specific error when calling this functions, other errors can be retured too.
func (*Client) GetBalanceOf ¶
GetBalanceOf returns the balance of a given address in the given token or native currency if an empty string is passed.
func (*Client) GetBalanceOfToken ¶
func (*Client) GetBestOrderTrades ¶
func (*Client) GetBestTradeExactIn ¶
func (*Client) GetBestTradeExactOut ¶
func (*Client) GetPairInfo ¶
GetPairInfo returns a map of liquidity tokens with their pair info as values.
func (*Client) GetTokenInfo ¶
GetTokenSymbols returns a map of token addresses with their symbols as values.
func (*Client) GetValidPairTokens ¶
GetPairTokens returns a slice of liquidity tokens.
func (*Client) NewRouter ¶
func (c *Client) NewRouter(contract string) (*uniswapv2router2.Uniswapv2router2, error)
NewRouter initializes the uniswapv2 router.
func (*Client) Swap ¶
func (c *Client) Swap(wallet *database.Wallet, trade *database.Trade, target *database.Target) (*types.Transaction, error)
Swap triggers a swap of a target.
func (*Client) TradeDispatcher ¶
func (c *Client) TradeDispatcher(ctx context.Context, cancel context.CancelFunc, wallet *database.Wallet, trade *database.Trade, price *Price, logStream chan<- string)
TradeDispatcher is a loop that checks if the price matches a target (considering the slippage) and executes the trade This function is blocking and should be run in a goroutine.
type Pair ¶
type Pair struct {
// contains filtered or unexported fields
}
type Price ¶
type Price struct { Heartbeat chan struct{} // contains filtered or unexported fields }
func NewPriceWithContext ¶
func NewPriceWithContext(ctx context.Context, cancel context.CancelFunc) *Price
func (*Price) GetBuyAmount ¶
func (*Price) GetBuyTrade ¶
func (*Price) GetHeartbeatRunning ¶
func (*Price) GetRunning ¶
func (*Price) GetSellAmount ¶
func (*Price) GetSellTrade ¶
func (*Price) SetBuyAmount ¶
func (*Price) SetHeartbeat ¶
func (*Price) SetPriceResult ¶
func (p *Price) SetPriceResult(r PriceResult)
func (*Price) SetSellAmount ¶
type PriceResult ¶
type PriceResult struct {
// contains filtered or unexported fields
}