Documentation
¶
Index ¶
- Constants
- Variables
- func NoRaydiumMetadataForTickerError(ticker string) error
- func SolanaJSONRPCError(err error) error
- type AMMTokenVaultMetadata
- type APIPriceFetcher
- type JSONRPCClient
- type MultiJSONRPCClient
- type SolanaJSONRPCClient
- func NewJSONRPCClient(api config.APIConfig, apiMetrics metrics.APIMetrics) (SolanaJSONRPCClient, error)
- func NewMultiJSONRPCClient(logger *zap.Logger, api config.APIConfig, apiMetrics metrics.APIMetrics, ...) SolanaJSONRPCClient
- func NewMultiJSONRPCClientFromEndpoints(logger *zap.Logger, api config.APIConfig, apiMetrics metrics.APIMetrics) (SolanaJSONRPCClient, error)
- type TickerMetadata
Constants ¶
const ( // Name is the name of the Raydium API. Name = "raydium_api" // NormalizedTokenAmountExponent. NormalizedTokenAmountExponent = 18 )
Variables ¶
var DefaultAPIConfig = config.APIConfig{ Enabled: true, Name: Name, Timeout: 2 * time.Second, Interval: 500 * time.Millisecond, ReconnectTimeout: 2000 * time.Millisecond, MaxQueries: 10, Atomic: false, BatchSize: 25, Endpoints: []config.Endpoint{ { URL: "https://api.mainnet-beta.solana.com", }, }, MaxBlockHeightAge: 30 * time.Second, }
DefaultAPIConfig is the default configuration for the Raydium API price fetcher.
Functions ¶
func NoRaydiumMetadataForTickerError ¶
NoRaydiumMetadataForTickerError is returned when there is no metadata associated with a given ticker.
func SolanaJSONRPCError ¶
SolanaJSONRPCError is returned when there is an error querying the solana JSON-RPC client.
Types ¶
type AMMTokenVaultMetadata ¶
type AMMTokenVaultMetadata struct { // QuoteTokenAddress is the base58 encoded address of the serum token corresponding // to this market's quote address TokenVaultAddress string `json:"token_vault_address"` // TokenDecimals is the number of decimals used for the token, we use this for // normalizing the balance of tokens at the designated vault address TokenDecimals uint64 `json:"token_decimals"` }
AMMTokenVaultMetadata represents the metadata associated with a raydium AMM pool's token vault. Specifically, we require the token vault address and the token decimals for the token that the vault is associated with.
type APIPriceFetcher ¶
type APIPriceFetcher struct {
// contains filtered or unexported fields
}
APIPriceFetcher is responsible for interacting with the solana API and querying information about the price of a given currency pair.
func NewAPIPriceFetcher ¶
func NewAPIPriceFetcher( logger *zap.Logger, api config.APIConfig, apiMetrics metrics.APIMetrics, ) (*APIPriceFetcher, error)
NewAPIPriceFetcher returns a new APIPriceFetcher. This method constructs the default solana JSON-RPC client in accordance with the config's URL param.
func NewAPIPriceFetcherWithClient ¶
func NewAPIPriceFetcherWithClient( logger *zap.Logger, api config.APIConfig, client SolanaJSONRPCClient, ) (*APIPriceFetcher, error)
NewAPIPriceFetcherWithClient returns a new APIPriceFetcher. This method requires that the given market + config are valid, otherwise a nil implementation + an error will be returned.
func (*APIPriceFetcher) Fetch ¶
func (pf *APIPriceFetcher) Fetch( ctx context.Context, tickers []oracletypes.ProviderTicker, ) oracletypes.PriceResponse
Fetch fetches prices from the solana JSON-RPC API for the given currency-pairs. Specifically for each currency-pair,
- Query the raydium API base (coin) / quote (pc) token vault addresses
- Normalize the token balances by 1e18
- Calculate the price as quote / base, and scale by ticker.Decimals
type JSONRPCClient ¶
type JSONRPCClient struct {
// contains filtered or unexported fields
}
JSONRPCClient is an implementation of the Solana JSON RPC client with additional functionality for metrics and logging.
func (*JSONRPCClient) GetMultipleAccountsWithOpts ¶
func (c *JSONRPCClient) GetMultipleAccountsWithOpts( ctx context.Context, accounts []solana.PublicKey, opts *rpc.GetMultipleAccountsOpts, ) (*rpc.GetMultipleAccountsResult, error)
GetMultipleAccountsWithOpts is a wrapper around the solana-go GetMultipleAccountsWithOpts method.
type MultiJSONRPCClient ¶
type MultiJSONRPCClient struct {
// contains filtered or unexported fields
}
MultiJSONRPCClient is an implementation of the SolanaJSONRPCClient interface that delegates requests to multiple underlying clients, and aggregates over all provided responses.
func (*MultiJSONRPCClient) GetMultipleAccountsWithOpts ¶
func (c *MultiJSONRPCClient) GetMultipleAccountsWithOpts( ctx context.Context, accounts []solana.PublicKey, opts *rpc.GetMultipleAccountsOpts, ) (*rpc.GetMultipleAccountsResult, error)
GetMultipleAccountsWithOpts delegates the request to all underlying clients and applies a filter to the responses.
type SolanaJSONRPCClient ¶
type SolanaJSONRPCClient interface { GetMultipleAccountsWithOpts( ctx context.Context, accounts []solana.PublicKey, opts *rpc.GetMultipleAccountsOpts, ) (out *rpc.GetMultipleAccountsResult, err error) }
SolanaJSONRPCClient is the expected interface for a solana JSON-RPC client according to the APIPriceFetcher.
func NewJSONRPCClient ¶
func NewJSONRPCClient( api config.APIConfig, apiMetrics metrics.APIMetrics, ) (SolanaJSONRPCClient, error)
NewJSONRPCClient returns a new JSONRPCClient.
func NewMultiJSONRPCClient ¶
func NewMultiJSONRPCClient( logger *zap.Logger, api config.APIConfig, apiMetrics metrics.APIMetrics, clients []SolanaJSONRPCClient, ) SolanaJSONRPCClient
NewMultiJSONRPCClient returns a new MultiJSONRPCClient.
func NewMultiJSONRPCClientFromEndpoints ¶
func NewMultiJSONRPCClientFromEndpoints( logger *zap.Logger, api config.APIConfig, apiMetrics metrics.APIMetrics, ) (SolanaJSONRPCClient, error)
NewMultiJSONRPCClientFromEndpoints creates a new MultiJSONRPCClient from a list of endpoints.
type TickerMetadata ¶
type TickerMetadata struct { // BaseTokenVault is the metadata associated with the base token's token vault BaseTokenVault AMMTokenVaultMetadata `json:"base_token_vault"` // QuoteTokenVault is the metadata associated with the quote token's token vault QuoteTokenVault AMMTokenVaultMetadata `json:"quote_token_vault"` // AMMInfoAddress is the address of the AMMInfo account for this raydium pool AMMInfoAddress string `json:"amm_info_address"` // OpenOrdersAddress is the address of the open orders account for this raydium pool OpenOrdersAddress string `json:"open_orders_address"` }
TickerMetadata represents the metadata associated with a ticker's corresponding raydium pool.
func (TickerMetadata) ValidateBasic ¶
func (metadata TickerMetadata) ValidateBasic() error
ValidateBasic checks that the solana token vault addresses are valid.