origin

package
v0.0.0-...-9e55092 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2024 License: AGPL-3.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const AmpPrecision = 1e3
View Source
const BalancerV2LoggerTag = "BALANCERV2_ORIGIN"
View Source
const ComposableBalancerV2LoggerTag = "COMPOSABLE_BALANCERV2_ORIGIN"
View Source
const CurveLoggerTag = "CURVE_ORIGIN"
View Source
const DSRLoggerTag = "DSR_ORIGIN"
View Source
const ISharesLoggerTag = "ISHARES_ORIGIN"
View Source
const LidoLSTLoggerTag = "LIDO_LST_ORIGIN"
View Source
const RocketPoolLoggerTag = "ROCKETPOOL_ORIGIN"
View Source
const SDAILoggerTag = "SDAI_ORIGIN"
View Source
const SushiswapLoggerTag = "SUSHISWAP_ORIGIN"
View Source
const TickGenericHTTPLoggerTag = "TICK_GENERIC_HTTP_ORIGIN"
View Source
const TickGenericJQLoggerTag = "TICK_GENERIC_JQ_ORIGIN"
View Source
const UniswapV2LoggerTag = "UNISWAPV2_ORIGIN"
View Source
const UniswapV3LoggerTag = "UNISWAPV3_ORIGIN"
View Source
const WeightedBalancerV2LoggerTag = "WEIGHTED_BALANCERV2_ORIGIN"
View Source
const WrappedStakedETHLoggerTag = "WSTETH_ORIGIN"

Variables

View Source
var LN_36_LOWER_BOUND = ONE_18.Sub(_powX(10, 17)) //nolint:revive,gomnd,stylecheck
View Source
var LN_36_UPPER_BOUND = ONE_18.Add(_powX(10, 17)) //nolint:revive,gomnd,stylecheck
View Source
var MAX_EXPONENT_BOUND = _powX(2, 255) //nolint:revive,gomnd,stylecheck
View Source
var MAX_NATURAL_EXPONENT = bn.DecFixedPoint(130, 0).Mul(ONE_18) //nolint:revive,gomnd,stylecheck
View Source
var MILD_EXPONENT_BOUND = _divDown(_powX(2, 254), ONE_20) //nolint:revive,gomnd,stylecheck
View Source
var MIN_NATURAL_EXPONENT = bn.DecFixedPoint(-41, 0).Mul(ONE_18) //nolint:revive,gomnd,stylecheck
View Source
var ONE_18 = _powX(10, balancerV2Precision) //nolint:revive,stylecheck
View Source
var ONE_20 = _powX(10, 20) //nolint:revive,gomnd,stylecheck
View Source
var ONE_36 = _powX(10, 36) //nolint:revive,gomnd,stylecheck
View Source
var PRODUCT_OUT_OF_BOUNDS = fmt.Errorf("PRODUCT_OUT_OF_BOUNDS") //nolint:revive,stylecheck
View Source
var STABLE_GET_BALANCE_DIDNT_CONVERGE = fmt.Errorf("STABLE_GET_BALANCE_DIDNT_CONVERGE") //nolint:revive,stylecheck
View Source
var STABLE_INVARIANT_DIDNT_CONVERGE = fmt.Errorf("STABLE_INVARIANT_DIDNT_CONVERGE") //nolint:revive,stylecheck
View Source
var X_OUT_OF_BOUNDS = fmt.Errorf("X_OUT_OF_BOUNDS") //nolint:revive,stylecheck
View Source
var Y_OUT_OF_BOUNDS = fmt.Errorf("Y_OUT_OF_BOUNDS") //nolint:revive,stylecheck

Functions

This section is empty.

Types

type AmplificationParameter

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

type AssetPair

type AssetPair [maxTokenCount]string

func (AssetPair) IndexOf

func (a AssetPair) IndexOf(token string) int

func (AssetPair) MarshalJSON

func (a AssetPair) MarshalJSON() ([]byte, error)

func (AssetPair) String

func (a AssetPair) String() string

func (*AssetPair) UnmarshalText

func (a *AssetPair) UnmarshalText(text []byte) error

type BalancerV2

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

func NewBalancerV2

func NewBalancerV2(config BalancerV2Config) (*BalancerV2, error)

func (*BalancerV2) FetchDataPoints

func (b *BalancerV2) FetchDataPoints(ctx context.Context, query []any) (map[any]datapoint.Point, error)

type BalancerV2Config

type BalancerV2Config struct {
	Client             rpc.RPC
	ContractAddresses  ContractAddresses
	ReferenceAddresses ContractAddresses
	Logger             log.Logger
	Blocks             []int64
}

type ComposableBalancerV2

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

func NewComposableBalancerV2

func NewComposableBalancerV2(config ComposableBalancerV2Config) (*ComposableBalancerV2, error)

NewComposableBalancerV2 create instance for ComposableStableBalancer `ComposableStableBalancer` is just a notable name, it is balancer v2 origin specialized for ComposableStablePool implementation https://docs.balancer.fi/concepts/pools/composable-stable.html WeightedPool or MetaStablePool was implemented in BalancerV2

func (*ComposableBalancerV2) FetchDataPoints

func (b *ComposableBalancerV2) FetchDataPoints(ctx context.Context, query []any) (map[any]datapoint.Point, error)

type ComposableBalancerV2Config

type ComposableBalancerV2Config struct {
	Client            rpc.RPC
	ContractAddresses ContractAddresses
	Logger            log.Logger
	Blocks            []int64
}

type ComposableStablePool

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

func (*ComposableStablePool) CalcAmountOut

func (p *ComposableStablePool) CalcAmountOut(tokenIn, tokenOut types.Address, amountIn *bn.DecFixedPointNumber) (
	*bn.DecFixedPointNumber,
	*bn.DecFixedPointNumber,
	error,
)

type ComposableStablePoolConfig

type ComposableStablePoolConfig struct {
	Pair    value.Pair
	Address types.Address
}

type ComposableStablePools

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

func NewComposableStablePools

func NewComposableStablePools(configs []ComposableStablePoolConfig, client rpc.RPC) (*ComposableStablePools, error)

func (*ComposableStablePools) FindPoolByPair

func (c *ComposableStablePools) FindPoolByPair(pair value.Pair) *ComposableStablePool

func (*ComposableStablePools) InitializePools

func (c *ComposableStablePools) InitializePools(ctx context.Context, blockNumber types.BlockNumber) error

type ContractAddresses

type ContractAddresses map[AssetPair]types.Address

func (ContractAddresses) ByPair

func (c ContractAddresses) ByPair(p value.Pair) (types.Address, int, int, error)

ByPair returns the contract address and the indexes of tokens, where the contract contains the given pair If not found base and quote token, return zero address and -1 for indexes For example, if we have a pool address of USDT/WBTC/WETH, and we are looking for USDT/WETH, then ByPair return the pool address and the indexes of 0, 2 (index is based on zero)

func (ContractAddresses) MarshalHCL

func (c ContractAddresses) MarshalHCL() (cty.Value, error)

func (ContractAddresses) MarshalJSON

func (c ContractAddresses) MarshalJSON() ([]byte, error)

type Curve

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

func NewCurve

func NewCurve(config CurveConfig) (*Curve, error)

func (*Curve) FetchDataPoints

func (c *Curve) FetchDataPoints(ctx context.Context, query []any) (map[any]datapoint.Point, error)

type CurveConfig

type CurveConfig struct {
	Client                      rpc.RPC
	StableSwapContractAddresses ContractAddresses
	CryptoSwapContractAddresses ContractAddresses
	Logger                      log.Logger
	Blocks                      []int64
}

type DSR

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

func NewDSR

func NewDSR(config DSRConfig) (*DSR, error)

func (*DSR) FetchDataPoints

func (d *DSR) FetchDataPoints(ctx context.Context, query []any) (map[any]datapoint.Point, error)

type DSRConfig

type DSRConfig struct {
	Client            rpc.RPC
	ContractAddresses ContractAddresses
	Logger            log.Logger
	Blocks            []int64
}

type ERC20

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

func NewERC20

func NewERC20(client rpc.RPC) (*ERC20, error)

func (*ERC20) GetSymbolAndDecimals

func (e *ERC20) GetSymbolAndDecimals(ctx context.Context, addresses []types.Address) (map[string]ERC20Details, error)

type ERC20Details

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

type Extra

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

type HTTPCallback

type HTTPCallback func(ctx context.Context, pairs []value.Pair, data io.Reader) (map[any]datapoint.Point, error)

type IShares

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

func NewIShares

func NewIShares(config ISharesConfig) (*IShares, error)

func (*IShares) FetchDataPoints

func (g *IShares) FetchDataPoints(ctx context.Context, query []any) (map[any]datapoint.Point, error)

FetchDataPoints implements the Origin interface.

type ISharesConfig

type ISharesConfig struct {
	URL     string
	Headers http.Header
	Client  *http.Client
	Logger  log.Logger
}

type LidoLST

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

func NewLidoLST

func NewLidoLST(config LidoLSTConfig) (*LidoLST, error)

func (*LidoLST) FetchDataPoints

func (r *LidoLST) FetchDataPoints(ctx context.Context, query []any) (map[any]datapoint.Point, error)

type LidoLSTConfig

type LidoLSTConfig struct {
	Client            rpc.RPC
	ContractAddresses ContractAddresses
	Logger            log.Logger
	Blocks            []int64
}

type Origin

type Origin interface {
	// FetchDataPoints fetches data points for the given list of queries.
	//
	// A query is an any type that can be used to query the origin for a data
	// point. For example, a query could be a pair of assets.
	//
	// Note that this method does not guarantee that data points will be
	// returned for all pairs nor in the same order as the pairs. The caller
	// must verify returned data.
	FetchDataPoints(ctx context.Context, query []any) (map[any]datapoint.Point, error)
}

Origin provides dataPoint prices for a given set of pairs from an external source.

type RocketPool

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

func NewRocketPool

func NewRocketPool(config RocketPoolConfig) (*RocketPool, error)

func (*RocketPool) FetchDataPoints

func (r *RocketPool) FetchDataPoints(ctx context.Context, query []any) (map[any]datapoint.Point, error)

type RocketPoolConfig

type RocketPoolConfig struct {
	Client            rpc.RPC
	ContractAddresses ContractAddresses
	Logger            log.Logger
	Blocks            []int64
}

type SDAI

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

func NewSDAI

func NewSDAI(config SDAIConfig) (*SDAI, error)

func (*SDAI) FetchDataPoints

func (s *SDAI) FetchDataPoints(ctx context.Context, query []any) (map[any]datapoint.Point, error)

type SDAIConfig

type SDAIConfig struct {
	Client            rpc.RPC
	ContractAddresses ContractAddresses
	Logger            log.Logger
	Blocks            []int64
}

type Static

type Static struct{}

Static is an origin that returns the same value for all queries.

func NewStatic

func NewStatic() *Static

NewStatic creates a new static origin.

func (*Static) FetchDataPoints

func (s *Static) FetchDataPoints(_ context.Context, query []any) (map[any]datapoint.Point, error)

FetchDataPoints implements the data.Type interface.

type Sushiswap

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

func NewSushiswap

func NewSushiswap(config SushiswapConfig) (*Sushiswap, error)

func (*Sushiswap) FetchDataPoints

func (s *Sushiswap) FetchDataPoints(ctx context.Context, query []any) (map[any]datapoint.Point, error)

type SushiswapConfig

type SushiswapConfig struct {
	Client            rpc.RPC
	ContractAddresses ContractAddresses
	Logger            log.Logger
	Blocks            []int64
}

type TickGenericHTTP

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

TickGenericHTTP is a generic http price provider that can fetch prices from an HTTP endpoint. The callback function is used to parse the response body.

func NewTickGenericHTTP

func NewTickGenericHTTP(config TickGenericHTTPConfig) (*TickGenericHTTP, error)

NewTickGenericHTTP creates a new TickGenericHTTP instance.

func (*TickGenericHTTP) FetchDataPoints

func (g *TickGenericHTTP) FetchDataPoints(ctx context.Context, query []any) (map[any]datapoint.Point, error)

FetchDataPoints implements the Origin interface.

type TickGenericHTTPConfig

type TickGenericHTTPConfig struct {
	// URL is an TickGenericHTTP endpoint that returns JSON data. It may contain
	// the following variables:
	//   - ${lcbase} - lower case base asset
	//   - ${ucbase} - upper case base asset
	//   - ${lcquote} - lower case quote asset
	//   - ${ucquote} - upper case quote asset
	//   - ${lcbases} - lower case base assets joined by commas
	//   - ${ucbases} - upper case base assets joined by commas
	//   - ${lcquotes} - lower case quote assets joined by commas
	//   - ${ucquotes} - upper case quote assets joined by commas
	URL string

	// Headers is a set of TickGenericHTTP headers that are sent with each request.
	Headers http.Header

	// Callback is a function that is used to parse the response body.
	Callback HTTPCallback

	// Client is an TickGenericHTTP client that is used to fetch data from the
	// TickGenericHTTP endpoint. If nil, http.DefaultClient is used.
	Client *http.Client

	// Logger is an TickGenericHTTP logger that is used to log errors. If nil,
	// null logger is used.
	Logger log.Logger
}

type TickGenericJQ

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

TickGenericJQ is a generic origin implementation that uses JQ to parse JSON data from an TickGenericHTTP endpoint.

func NewTickGenericJQ

func NewTickGenericJQ(config TickGenericJQConfig) (*TickGenericJQ, error)

NewTickGenericJQ creates a new TickGenericJQ instance.

The client argument is an TickGenericHTTP client that is used to fetch data from the TickGenericHTTP endpoint.

The url argument is an TickGenericHTTP endpoint that returns JSON data. It may contain the following variables:

  • ${lcbase} - lower case base asset
  • ${ucbase} - upper case base asset
  • ${lcquote} - lower case quote asset
  • ${ucquote} - upper case quote asset
  • ${lcbases} - lower case base assets joined by commas
  • ${ucbases} - upper case base assets joined by commas
  • ${lcquotes} - lower case quote assets joined by commas
  • ${ucquotes} - upper case quote assets joined by commas

The jq argument is a JQ query that is used to parse JSON data. It must return a single value that will be used as a price or an object with the following fields:

  • price - a price
  • time - a timestamp (optional)
  • volume - a 24h volume (optional)

The JQ query may contain the following variables:

  • $lcbase - lower case base asset
  • $ucbase - upper case base asset
  • $lcquote - lower case quote asset
  • $ucquote - upper case quote asset

Price and volume must be a string that can be parsed as a number or a number.

Time must be a string that can be parsed as time or a number that represents a UNIX timestamp.

If JQ query returns multiple values, the dataPoint will be invalid.

func (*TickGenericJQ) FetchDataPoints

func (g *TickGenericJQ) FetchDataPoints(ctx context.Context, query []any) (map[any]datapoint.Point, error)

FetchDataPoints implements the Origin interface.

type TickGenericJQConfig

type TickGenericJQConfig struct {
	// URL is an TickGenericHTTP endpoint that returns JSON data. It may contain
	// the following variables:
	//   - ${lcbase} - lower case base asset
	//   - ${ucbase} - upper case base asset
	//   - ${lcquote} - lower case quote asset
	//   - ${ucquote} - upper case quote asset
	//   - ${lcbases} - lower case base assets joined by commas
	//   - ${ucbases} - upper case base assets joined by commas
	//   - ${lcquotes} - lower case quote assets joined by commas
	//   - ${ucquotes} - upper case quote assets joined by commas
	URL string

	// Query is a JQ query that is used to parse JSON data. It must
	// return a single value that will be used as a price or an object with the
	// following fields:
	//   - price - a price
	//   - time - a timestamp (optional)
	//   - volume - a 24h volume (optional)
	//
	// The JQ query may contain the following variables:
	//   - $lcbase - lower case base asset
	//   - $ucbase - upper case base asset
	//   - $lcquote - lower case quote asset
	//   - $ucquote - upper case quote asset
	//
	// Price and volume must be a number or a string that can be parsed as a number.
	// Time must be a number or a string that can be parsed as a number or a string
	// that can be parsed as a time.
	Query string

	// Headers is a set of TickGenericHTTP headers that are sent with each request.
	Headers http.Header

	// Client is an TickGenericHTTP client that is used to fetch data from the
	// TickGenericHTTP endpoint. If nil, http.DefaultClient is used.
	Client *http.Client

	// Logger is an TickGenericHTTP logger that is used to log errors. If nil,
	// null logger is used.
	Logger log.Logger
}

type UniswapV2

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

func NewUniswapV2

func NewUniswapV2(config UniswapV2Config) (*UniswapV2, error)

func (*UniswapV2) FetchDataPoints

func (u *UniswapV2) FetchDataPoints(ctx context.Context, query []any) (map[any]datapoint.Point, error)

type UniswapV2Config

type UniswapV2Config struct {
	Client            rpc.RPC
	ContractAddresses ContractAddresses
	Logger            log.Logger
	Blocks            []int64
}

type UniswapV3

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

func NewUniswapV3

func NewUniswapV3(config UniswapV3Config) (*UniswapV3, error)

func (*UniswapV3) FetchDataPoints

func (u *UniswapV3) FetchDataPoints(ctx context.Context, query []any) (map[any]datapoint.Point, error)

type UniswapV3Config

type UniswapV3Config struct {
	Client            rpc.RPC
	ContractAddresses ContractAddresses
	Logger            log.Logger
	Blocks            []int64
}

type WeightedBalancerV2

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

func NewWeightedBalancerV2

func NewWeightedBalancerV2(config WeightedBalancerV2Config) (*WeightedBalancerV2, error)

func (*WeightedBalancerV2) FetchDataPoints

func (b *WeightedBalancerV2) FetchDataPoints(ctx context.Context, query []any) (map[any]datapoint.Point, error)

type WeightedBalancerV2Config

type WeightedBalancerV2Config struct {
	Client            rpc.RPC
	ContractAddresses ContractAddresses
	Logger            log.Logger
	Blocks            []int64
}

type WeightedPool

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

func (*WeightedPool) CalcAmountOut

func (p *WeightedPool) CalcAmountOut(tokenIn, tokenOut types.Address, amountIn *bn.DecFixedPointNumber) (
	*bn.DecFixedPointNumber,
	*bn.DecFixedPointNumber,
	error,
)

type WeightedPoolConfig

type WeightedPoolConfig struct {
	Pair    value.Pair
	Address types.Address
}

type WeightedPools

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

func NewWeightedPools

func NewWeightedPools(configs []WeightedPoolConfig, client rpc.RPC) (*WeightedPools, error)

func (*WeightedPools) FindPoolByPair

func (w *WeightedPools) FindPoolByPair(pair value.Pair) *WeightedPool

func (*WeightedPools) InitializePools

func (w *WeightedPools) InitializePools(ctx context.Context, blockNumber types.BlockNumber) error

type WrappedStakedETH

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

func NewWrappedStakedETH

func NewWrappedStakedETH(config WrappedStakedETHConfig) (*WrappedStakedETH, error)

func (*WrappedStakedETH) FetchDataPoints

func (w *WrappedStakedETH) FetchDataPoints(ctx context.Context, query []any) (map[any]datapoint.Point, error)

type WrappedStakedETHConfig

type WrappedStakedETHConfig struct {
	Client            rpc.RPC
	ContractAddresses ContractAddresses
	Logger            log.Logger
	Blocks            []int64
}

Jump to

Keyboard shortcuts

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