Documentation
¶
Index ¶
- type IndexPriceAggregator
- func (m *IndexPriceAggregator) AggregatePrices()
- func (m *IndexPriceAggregator) CalculateAdjustedPrice(cfg mmtypes.ProviderConfig) (*big.Float, error)
- func (m *IndexPriceAggregator) CalculateConvertedPrices(market mmtypes.Market) []*big.Float
- func (m *IndexPriceAggregator) GetIndexPrice(cp pkgtypes.CurrencyPair) (*big.Float, error)
- func (m *IndexPriceAggregator) GetIndexPrices() types.Prices
- func (m *IndexPriceAggregator) GetMarketMap() *mmtypes.MarketMap
- func (m *IndexPriceAggregator) GetPrices() types.Prices
- func (m *IndexPriceAggregator) GetProviderPrice(cfg mmtypes.ProviderConfig) (*big.Float, error)
- func (m *IndexPriceAggregator) Reset()
- func (m *IndexPriceAggregator) SetIndexPrices(prices types.Prices)
- func (m *IndexPriceAggregator) SetProviderPrices(provider string, data types.Prices)
- func (m *IndexPriceAggregator) UpdateMarketMap(marketMap mmtypes.MarketMap)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type IndexPriceAggregator ¶
type IndexPriceAggregator struct {
// contains filtered or unexported fields
}
IndexPriceAggregator is an aggregator that calculates the median price for each ticker, resolved from a predefined set of conversion markets. A conversion market is a set of markets that can be used to convert the prices of a set of tickers to a common ticker. These are defined in the market map configuration.
func NewIndexPriceAggregator ¶
func NewIndexPriceAggregator( logger *zap.Logger, cfg mmtypes.MarketMap, metrics oraclemetrics.Metrics, ) (*IndexPriceAggregator, error)
NewIndexPriceAggregator returns a new Index Price Aggregator.
func (*IndexPriceAggregator) AggregatePrices ¶
func (m *IndexPriceAggregator) AggregatePrices()
AggregatePrices implements the aggregate function for the median price calculation. Specifically, this aggregation function aggregates the prices seen by each provider by first converting each price to a common ticker and then calculating the median of the converted prices. Prices are converted either
- Directly from the base ticker to the target ticker. i.e. I have BTC/USD and I want BTC/USD.
- Using the index price of an asset. i.e. I have BTC/USDT and I want BTC/USD. I can convert BTC/USDT to BTC/USD using the index price of USDT/USD.
The index price cache contains the previously calculated median prices.
func (*IndexPriceAggregator) CalculateAdjustedPrice ¶
func (m *IndexPriceAggregator) CalculateAdjustedPrice( cfg mmtypes.ProviderConfig, ) (*big.Float, error)
CalculateAdjustedPrice calculates an adjusted price for a given set of operations (if applicable). In particular, this assumes that every operation is either:
- A direct conversion from the base ticker to the target ticker i.e. we want BTC/USD and we have BTC/USD from a provider (e.g. Coinbase).
- We need to convert the price of a given asset against the index price of an asset.
In the first case, we can simply return the price of the provider. In the second case, we need to adjust the price by the index price of the asset. If the index price is not available, we return an error.
func (*IndexPriceAggregator) CalculateConvertedPrices ¶
func (m *IndexPriceAggregator) CalculateConvertedPrices( market mmtypes.Market, ) []*big.Float
CalculateConvertedPrices calculates the converted prices for a given set of paths and target ticker. The prices utilized are the prices most recently seen by the providers. Each price is within a MaxPriceAge window so is safe to use.
func (*IndexPriceAggregator) GetIndexPrice ¶
func (m *IndexPriceAggregator) GetIndexPrice( cp pkgtypes.CurrencyPair, ) (*big.Float, error)
GetIndexPrice returns the relevant index price. Note that the aggregator's index price cache stores prices in the form of ticker -> price.
func (*IndexPriceAggregator) GetIndexPrices ¶
func (m *IndexPriceAggregator) GetIndexPrices() types.Prices
GetIndexPrices returns the index prices the aggregator has.
func (*IndexPriceAggregator) GetMarketMap ¶
func (m *IndexPriceAggregator) GetMarketMap() *mmtypes.MarketMap
GetMarketMap returns the market map for the oracle.
func (*IndexPriceAggregator) GetPrices ¶
func (m *IndexPriceAggregator) GetPrices() types.Prices
GetPrices returns the aggregated data the aggregator has. Specifically, the prices returned are the scaled prices - where each price is scaled by the respective ticker's decimals.
func (*IndexPriceAggregator) GetProviderPrice ¶
func (m *IndexPriceAggregator) GetProviderPrice( cfg mmtypes.ProviderConfig, ) (*big.Float, error)
GetProviderPrice returns the relevant provider price. Note that the aggregator's provider data cache stores prices in the form of providerName -> offChainTicker -> price.
func (*IndexPriceAggregator) Reset ¶
func (m *IndexPriceAggregator) Reset()
Reset resets the data aggregator for all providers.
func (*IndexPriceAggregator) SetIndexPrices ¶
func (m *IndexPriceAggregator) SetIndexPrices( prices types.Prices, )
SetIndexPrice sets the index price for the given currency pair.
func (*IndexPriceAggregator) SetProviderPrices ¶
func (m *IndexPriceAggregator) SetProviderPrices(provider string, data types.Prices)
SetProviderPrices updates the data aggregator with the given provider and data.
func (*IndexPriceAggregator) UpdateMarketMap ¶
func (m *IndexPriceAggregator) UpdateMarketMap(marketMap mmtypes.MarketMap)
UpdateMarketMap updates the market map for the oracle.