Skip to content
Bette edited this page Oct 23, 2019 · 5 revisions

Introduction

The price oracle implements the PriceOracleInterface, and provides an interface for other contracts to access external data such as price feed for given assets.

Price Oracle Interface

Get Price

The getPrice functions returns price feed for a given asset.

function getPrice(address addr) external view returns (uint)
  • addr: the account of an asset e.g. fToken
  • return: price feed for given asset

Simple Price Oracle Implementation

Our simple price oracle implementation implements the PriceOracleInterface, PriceFeederRole and PriceOracleConfig.

Attack Resistant Get Price

In our getPrice function implementation, we provided extra level of security to resist potential attacks.

The smart contract will find the median price amongst prices provided by all active prices feeder.

The change between two prices are capped by the oracleDeltaLastLimit. The change between this price and the snapshot price which is taken every oracleDeltaSnapshotTime are further capped by the oracleDeltaSnapshotLimit.

Still, any compromised oracle is able to influence the price but to a very limited degree with both median price taking and price capping.

Set Oracle Delta Last Limit

function setOracleDeltaLastLimit(uint limit) public onlyOwner

Set Oracle Delta Snapshot Limit

function setOracleDeltaSnapshotLimit(uint limit) public onlyOwner

Set Oracle Delta Snapshot Time

function setOracleDeltaSnapshotTime(uint time) public onlyOwner

Feed Price

function feedPrice(address key, uint price) external onlyPriceFeeder 

Add Price Feeder

function addPriceFeeder(address account) public onlyOwner

Remove Price Feeder

function removePriceFeeder(address account) public onlyOwner