Price Oracle
Pricing Procedure
1. Principle
A digital asset can be traded on different exchanges and its price may be quoted differently. An exchange with a better price generally has lower liquidity, which is insufficient for portfolio allocation. As a result, the actual buying and selling transactions usually take place on serveral exchanges, thus getting different pricing. To set a reference price for downstream quantitative calculations, we use the median price from different price feeds as shown below. This is a standard approach used in asset management since the median price is less volatile than the raw price from a single source, and is, or is close to, the arbitrage-free price. When a price feed fails to fetch an asset price, the prices from the other available sources will be used to calculate the median price.
Off-chain price sources
CoinMarketCap
CoinGecko
Binance
On-chain price sources
PancakeSwap
WaultSwap
Alpaca
Belt.Fi
Terra Mantle
Mirror
Extraterrestial
The method of median pricing is also used by many price oracles on DeFi to mitigate technical risks, such as a price source being attacked, an exchange being temporarily or permanently closed, a price being manipulated or highly deviated, etc. Hence, referencing prices from different data sources allows the fund protocol to do further calculations in the event of some price feeds experiencing the aforementioned problems.
2. Impact and Warning for Investors
The reference price defined using the median price has direct consequences on the investors. For example, asset prices, the fund token price, the net asset value (NAV), and those conditioned on the reference price, that are shown to the investors prior to the execution might differ from the prices shown in actual transactions. Depending on market arbitrage, the slippages, or the difference between the reference prices and execution prices, can either positively or negatively affect the investors. Practically, slippages are minimal for digital assets with high market capitalization.
Price Feed
The diagram below shows the flow of data from price sources to data storage during aggregation, and from the storage to data consumers during request handling.
1. Data Aggregation
The price feeder is a core component of the price oracle. It is responsible for collecting raw price data from various sources both on-chain and off-chain providers, establishing reference prices, and storing recently and historically aggregated prices in a database. Because the reference prices are extensively used throughout the protocol, it is vital to assure the reliability of all the price data. The price report component exists to help administrators regularly monitor the integrity of the price data via visualization and key metrics. The entire process is triggered by a feed task scheduler, which initially sets off every 15 minutes and is administrated by our smart contract engineers. The reference prices, including the raw price data, now become available through the pricing APIs.
2. Data Consumption
Resolvers are smart contracts that passively make on-chain request transactions. Once issued, those requests will be observed by chain-specific event listeners, called watchers, that actively look for and relay the requests. X-Bridge serves as a cross-chain flow controller that redirect requests and responses between the watchers and the pricing APIs. To improve request handling efficiency and survive possible attacks on the price feeds, X-Bridge works with the indexer for logging the requests and responses in order to detect duplicates and negate malicious effects.
Last updated
Was this helpful?