bclient

package
v0.0.2-rc2 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2021 License: Apache-2.0 Imports: 18 Imported by: 2

Documentation

Overview

Package bclient provides a blockchain client for indexed finance

Index

Constants

This section is empty.

Variables

View Source
var (

	// DEFI5TokenAddress is the address of the DEFI5 token/pool contract
	DEFI5TokenAddress = common.HexToAddress(defi5Addr)
	// DEFI5StakingAddress is the address of the DEFI5 staking contract
	DEFI5StakingAddress = common.HexToAddress(defi5StakeAddr)
	// DEFI5UNILPStakingAddress is the address of the ETH-DEFI5 Uniswap staking contract
	DEFI5UNILPStakingAddress = common.HexToAddress(defi5UNILPStakeAddr)
	// CC10TokenAddress is the address of the CC10 token/pool contract
	CC10TokenAddress = common.HexToAddress(cc10Addr)
	// WETHTokenAddress is the address of the WETH token contract
	WETHTokenAddress = common.HexToAddress("0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2")
	// DAITokenAddress is the address of the MCD (Multi Collateral DAI) contract
	DAITokenAddress = common.HexToAddress("0x6b175474e89094c44da98b954eedeac495271d0f")
	// NDXTokenAddress is the address of the NDX contract
	NDXTokenAddress = common.HexToAddress("0x86772b1409b61c639eaac9ba0acfbb6e238e5f83")
	// InfuraWSURL is the URL for INFURA websockets access
	InfuraWSURL = "wss://mainnet.infura.io/ws/v3/"
	// InfuraHTTPURL is the URL for INFURA HTTP access
	InfuraHTTPURL = "https://mainnet.infura.io/v3/"
	// IndexPools contains all current available idnex pools
	// note that it may not be truly up-to-date
	IndexPools = map[string]common.Address{"defi5": DEFI5TokenAddress, "cc10": CC10TokenAddress}
)

Functions

func BalanceOfDecimal

func BalanceOfDecimal(ip IndexPool, addr common.Address) (decimal.Decimal, error)

BalanceOfDecimal returns the IndexPool balance in decimal (non wei) format

func StakeBalanceOf

StakeBalanceOf returns the balance of staking tokens owned by account

func StakeEarned

StakeEarned returns the amount of staking tokens earned

Types

type Client

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

Client wraps ethclient and provides helper functions for interacting with the indexed finance smart contracts

func NewClient

func NewClient(url string) (*Client, error)

NewClient returns an eth client connected to an RPC

func NewInfuraClient

func NewInfuraClient(token string, websockets bool) (*Client, error)

NewInfuraClient returns an eth client connected to infura

func (*Client) CC10

func (c *Client) CC10() (IndexPool, error)

CC10 returns a CC10 contract binding

func (*Client) Cc10DaiPrice

func (c *Client) Cc10DaiPrice() (float64, error)

Cc10DaiPrice returns the price of CC10 in terms of DAI

func (*Client) Cc10EthPairAddress

func (c *Client) Cc10EthPairAddress() common.Address

Cc10EthPairAddress returns the UniswapV2 pair of CC10-ETH

func (*Client) Close

func (c *Client) Close()

Close terminates the blockchain connection

func (*Client) CurrentBlock

func (c *Client) CurrentBlock() (uint64, error)

CurrentBlock returns the current block known by the ethereum client

func (*Client) DEFI5

func (c *Client) DEFI5() (IndexPool, error)

DEFI5 returns a DEFI5 contract binding

func (*Client) Defi5DaiPrice

func (c *Client) Defi5DaiPrice() (float64, error)

Defi5DaiPrice returns the price of DEFI5 in terms of DAI

func (*Client) Defi5EthPairAddress

func (c *Client) Defi5EthPairAddress() common.Address

Defi5EthPairAddress returns the UniswapV2 pair of DEFI5-ETH

func (*Client) EthDaiPrice

func (c *Client) EthDaiPrice() (*big.Int, error)

EthDaiPrice returns the price of ETH in terms of DAI

func (*Client) ExchangeAmount

func (c *Client) ExchangeAmount(amount *big.Int, pair string) (*big.Int, error)

ExchangeAmount returns the exchange amount for a variety of pairs

func (*Client) MCAPControllerAt

func (c *Client) MCAPControllerAt(ip IndexPool) (*mcapscontroller.Mcapscontroller, error)

MCAPControllerAt returns the marketcap square root controller bindings for an IndexPool

func (*Client) NdxDaiPrice

func (c *Client) NdxDaiPrice() (float64, error)

NdxDaiPrice returns the price of NDX in terms of DAI

func (*Client) NdxEthPairAddress

func (c *Client) NdxEthPairAddress() common.Address

NdxEthPairAddress returns the UniswapV2 pair of NDX-ETH

func (*Client) OracleAt

OracleAt returns the uniswapv2 oracle contract binding that the current idnex pool is using

func (*Client) OracleFor

func (c *Client) OracleFor(ip IndexPool) (common.Address, error)

OracleFor returns the uniswap v2 oracle address for tne given index pool

func (*Client) PairDecimals

func (c *Client) PairDecimals(pair string) int

PairDecimals returns the decimals for the corresponding token pair

func (*Client) PoolTokensFor

func (c *Client) PoolTokensFor(ip IndexPool) (map[string]common.Address, error)

PoolTokensFor returns the pools tokens baseketed in the pool, and their ERC20 name

func (*Client) Reserves

func (c *Client) Reserves(pair string) (*uniswap.Reserve, error)

Reserves returns available reserves in the pair

func (*Client) StakingAt

func (c *Client) StakingAt(contractType string) (*stakingbindings.Stakingbindings, error)

StakingAt returns a staking rewards bindings at the given address

func (*Client) Uniswap

func (c *Client) Uniswap() *uniswap.Client

Uniswap returns a uniswap client helper

type DEFI5

type DEFI5 struct {
	*poolbindings.Poolbindings
}

DEFI5 is the DEFI Top 5 IndexPool

type IndexPool

type IndexPool interface {
	IndexPoolRead
}

IndexPool provides helper functions around the IndexPool contract

type IndexPoolRead

type IndexPoolRead interface {
	IsPublicSwap(opts *bind.CallOpts) (bool, error)
	GetController(opts *bind.CallOpts) (common.Address, error)
	GetCurrentTokens(opts *bind.CallOpts) ([]common.Address, error)
	GetNumTokens(opts *bind.CallOpts) (*big.Int, error)
	GetMaxPoolTokens(opts *bind.CallOpts) (*big.Int, error)
	GetSpotPrice(opts *bind.CallOpts, tokenIn common.Address, tokenOut common.Address) (*big.Int, error)
	GetSwapFee(opts *bind.CallOpts) (*big.Int, error)
	GetCurrentDesiredTokens(opts *bind.CallOpts) ([]common.Address, error)
	GetDenormalizedWeight(opts *bind.CallOpts, token common.Address) (*big.Int, error)
	GetTotalDenormalizedWeight(opts *bind.CallOpts) (*big.Int, error)
	GetUsedBalance(opts *bind.CallOpts, token common.Address) (*big.Int, error)
	GetBalance(opts *bind.CallOpts, token common.Address) (*big.Int, error)
	ExtrapolatePoolValueFromToken(opts *bind.CallOpts) (common.Address, *big.Int, error)
	BalanceOf(opts *bind.CallOpts, whom common.Address) (*big.Int, error)
	Decimals(opts *bind.CallOpts) (uint8, error)
}

IndexPoolRead are read-only IndexPool contract calls See https://docs.indexed.finance/indexed-finance-docs/smart-contracts/pool#indexpool for more information

Jump to

Keyboard shortcuts

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