chains

package
v0.0.0-...-bd92ab4 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Hooks = figure.Hooks{
		"tokenmanager.NetworkType": figure.BaseHooks["int32"],
		"chains.SwapContractVersion": func(value interface{}) (reflect.Value, error) {
			supported := []string{
				string(SwapContractVersionTraderJoe),
				string(SwapContractVersionQuickSwap),
				string(SwapContractVersionPancakeSwap),
				string(SwapContractVersionUniswapV3),
			}

			result, err := cast.ToStringE(value)
			if err != nil {
				return reflect.Value{}, errors.Wrap(err, "failed to parse string")
			}

			if !slices.Contains(supported, result) {
				return reflect.Value{}, fmt.Errorf("supported values are: %v", supported)
			}

			return reflect.ValueOf(SwapContractVersion(result)), nil
		},
		"chains.Kind": func(value interface{}) (reflect.Value, error) {
			supported := []string{
				string(KindTestnet),
				string(KindMainnet),
			}

			result, err := cast.ToStringE(value)
			if err != nil {
				return reflect.Value{}, errors.Wrap(err, "failed to parse string")
			}

			if !slices.Contains(supported, result) {
				return reflect.Value{}, fmt.Errorf("supported values are: %v", supported)
			}

			return reflect.ValueOf(Kind(result)), nil
		},
		"chains.TokensInfo": func(value interface{}) (reflect.Value, error) {
			cfgMap, err := cast.ToStringMapE(value)
			if err != nil {
				return reflect.Value{}, errors.Wrap(err, "failed to parse map[string]interface{}")
			}

			var cfg TokensInfo
			err = figure.
				Out(&cfg).
				With(figure.BaseHooks, tokenHooks).
				From(cfgMap).
				Please()
			if err != nil {
				return reflect.Value{}, errors.Wrap(err, "failed to figure out chain tokens")
			}

			return reflect.ValueOf(cfg), nil
		},
	}
)

Functions

This section is empty.

Types

type Chain

type Chain struct {
	ID                             int64                    `fig:"id,required"`
	Name                           string                   `fig:"name,required"`
	RPCUrl                         *url.URL                 `fig:"rpc_url,required"`        // use this for actual rpc calls
	RPCUrlClient                   *url.URL                 `fig:"rpc_url_client,required"` // use this url for rendering responses etc
	NativeSymbol                   string                   `fig:"native_symbol,required"`
	ExplorerURL                    string                   `fig:"explorer_url,required"`
	Type                           tokenmanager.NetworkType `fig:"type,required"`
	Kind                           Kind                     `fig:"kind,required"`
	IconURL                        string                   `fig:"icon_url,required"`
	SwapContractAddr               common.Address           `fig:"swap_contract_address,required"`
	SwapContractVersion            SwapContractVersion      `fig:"swap_contract_version,required"`
	MultiBalanceGetterContractAddr common.Address           `fig:"balance_multigetter_addr,required"`
	TokensInfo                     TokensInfo               `fig:"tokens_info"`

	BalanceProvider EthMultiAmounter `fig:"-"`
}

type Config

type Config struct {
	Chains []Chain `fig:"list,required"`
}

func (Config) Find

func (c Config) Find(id int64) *Chain

func (Config) FindByName

func (c Config) FindByName(name string) *Chain

type EthMultiAmounter

type EthMultiAmounter interface {
	GetMultipleBalances(opts *bind.CallOpts, tokens []common.Address, account common.Address) (*big.Int, []*big.Int, error)
}

type Kind

type Kind string
const (
	KindTestnet Kind = "testnet"
	KindMainnet Kind = "mainnet"
	KindOther   Kind = "other"
)

type SwapContractVersion

type SwapContractVersion string
const (
	SwapContractVersionTraderJoe   SwapContractVersion = "TraderJoe"
	SwapContractVersionQuickSwap   SwapContractVersion = "QuickSwap"
	SwapContractVersionPancakeSwap SwapContractVersion = "PancakeSwap"
	SwapContractVersionUniswapV3   SwapContractVersion = "UniswapV3"
)

type TokenInfo

type TokenInfo struct {
	Name     string `json:"name" fig:"name"`
	Symbol   string `json:"symbol" fig:"symbol"`
	Address  string `json:"address" fig:"address"`
	Decimals int64  `json:"decimals" fig:"decimals"`
	LogoURI  string `json:"logoURI" fig:"logo_uri"`
	Native   bool   `json:"native" fig:"native"`
}

type TokensInfo

type TokensInfo struct {
	ListURL []url.URL   `fig:"list_urls"`
	Tokens  []TokenInfo `fig:"tokens"`
}

Jump to

Keyboard shortcuts

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