Architecture

circle-info

Overall architecture

Mainnet:

Basic architecture: Multiple whitelisted-nodes independently fetching price data from multiple data sources to guard against potential node failure. Then the medianizer contract aggregates and picks the median data reported from whitelisted nodes.

There are two ways for nodes to perform price aggregation: median method and weighted-average method.

  • Median: When there are enough price origins, taking the median value can improve security more effectively.

  • Weighted-average: Based-on trading volume, liquidity depth, exchange reputation, etc., price will be fetch from different exchanges for different fungible tokens, applied with different weights.

Flow/USD price feed

It has 8 origins currently and is applied with the median method based on https://www.coingecko.com/en/coins/flow#marketsarrow-up-right:

USDT/USD price feed

It has 3 origins and is applied with the weighted-average method base on https://www.coingecko.com/en/coins/tether#marketsarrow-up-right:

* There're concerns and rumors about Bitfinex & Tether manipulation / non-transparency. So although Bitfinex's USDT/USD volume is on par with Coinbase's, it only has a weight of 15%.

Stablecoins' price feed

Other fungible tokens' price feed:

Testnet:

Basic architecture: A single node fetching from multiple data sources. (Very much close to the mainnet's arch, but to save our resources and costs.)

Emulator:

Basic architecture: A single node SimpleOracle fetching from a single data source (Coingecko api) is used on emulator for local bootstrapping and testing.

Price data is periodically fetched, and it gets updated whichever below conditions happen first:

  • windowSize: e.g. 1200 - every 1,200 seconds

  • deviation: e.g. 0.01 - once ฮ” { fetchedData, lastData } > 0.01 * lastData

Contract architecture

For each different type of price feed, a separate PriceOracle contract is deployed to support it.

The PriceOracle contract defines two whitelists and two resources: PriceReader and PriceFeeder. PriceReader resource holder has the ability to access reported data as long as it's also in the reader whitelist. PriceFeeder resource holder has the ability to post price data and influence the medianized onchain price data as long as it's also in the feeder whitelist.

  • For developers to use the on-chain price data in your Cadence contracts there's no barrier to apply for the reader whitelist - we've made it free and public through the PublicPriceOracle contract with some Chainlink-like APIs. Please read Using Price Feeds for more details.

  • For institutions and partners interest in joining node runners & feeder whitelist to provide more decentralized price feeds on flow, welcome to contact us.

Last updated