[Release] On-chain Oracle price feeds

What are Oracles?

An oracle is an external data source that provides an answer to a specific question. For example; “what was the temperature in NYC over the past 24 hours”.

A subset of Oracle’s are price feeds. “what is the price in ETH for wBTC”.

Why do we need Oracles?

Not all data can be provided on-chain. And if it can be provided on-chain, not all data should be trusted. Two examples;

Bob and Alice make a wager on the outcome of a coin flip. Bob says heads, Alice says tails. They both lock in their ETH. Bob is the oracle source, and Bob inputs “heads” into the contract. Bob wins. Would Alice trust this outcome? It is important to have external, secure oracles.

Bob agrees to sell Alice 1 ETH. Bob creates a smart contract that takes DAI from Alice and gives her 1 ETH based on the price of ETH-DAI on Uniswap. The current price is 400 DAI = 1 ETH. When Alice calls the contract, it takes 4000 DAI from Alice. Bob added a flash loan into the contract to make ETH more expensive. It is important to have tamperproof oracles.

What are Uniquote Oracles?

Different end results require different products. If you are working with highly available assets (such as ETH, BTC, …) and require optimum security, you should use Chainlink Oracles

These come with a few restrictions;

  • Asset availability
  • ETH price freshness vs exchange freshness
  • Cost

For products like yearn.finance’s Uniswap LP impermanent loss hedge, or yearn.finance’s Uniswap loans, we needed a solution that had the following qualities;

  • Accepts any asset tradeable on Uniswap
  • Security vs data freshness

For full documentation you can read more here and for available feeds you can view here

To get up to date prices, you can simply call;

Uniquote.current(WETH, 1e18, WBTC);

While the above call has high data freshness, it has low security, an exploiter simply needs to manipulate 2 data points to be able to impact the feed. For higher security you can instead use;

Uniquote.consult(WETH, 1e18, WBTC, granularity);

granularity being the amount of readings, so granularity = 48 would be an average price over the last 24 hours. More secure, but the data freshness is 24 hours.

Read more

Documentation

Feeds

Github

medium

6 Likes