Data Feed
Continuous stream of off-chain data to your smart contract
A detailed example of how to use Orakl Network Data Feed can be found at example repository data-feed-consumer
.
What is Data Feed?
The Orakl Network Data Feed is a secure, reliable, and decentralized source of off-chain data accessible to smart contracts on-chain. The data feed is updated at predefined time intervals, as well as if the data value deviates more than a predefined threshold, to ensure that the data remains accurate and up-to-date. Data feeds can be used in many different on-chain protocols:
Lending and borrowing
Mirrored assets
Stablecoins
Asset management
Options and futures
and many more!
The Orakl Data Feed includes various data feeds that can be used free of charge. The currently supported data feeds can be found in tables below.
Contract Addresses
Reference following link to check deployed addresses
Architecture
The on-chain implementation of Data Feed is composed of two smart contracts: Feed
and FeedProxy
. At first,Feed
and FeedProxy
are deployed together in pair, representing a single data feed (e.g. temperature in Seoul or price of BTC/USD). Feed
is being updated at regular intervals by off-chain oracles, and FeedProxy
is used to access the submitted data to Feed
. Deployed FeedProxy
contract represents a consistent API to read data from the feed, and Feed
contract can be replaced with a newer version.
In the rest of the page, we will focus on how to read from data feed and explain relation between Feed
and FeedProxy
.
How to read from data feed?
In this section, we will explain how to integrate Orakl Network data feed to your smart contract to be able to read from any data feed. We will also point out potential issues you might encounter and how to solve them.
The section is split into following topics:
Initialization
The access to data feed is provided through the FeedProxy
address corresponding to a data feed of your choice, and IFeedProxy
from @bisonai/orakl-contracts
.
Read Data
Data can be queried from feed using following functions: latestRoundData()
and getRoundData(roundId)
.
The latestRoundData
function returns metadata about the latest submission.
Submissions are divided into rounds and indexed by an id
. Node operators are expected to report submission in every round, and aggregate is computed from all submissions in the same round. Submissions from previous rounds can be queried through getRoundData
function which requires a single extra parameter roundId
. The output format is same as from latestRoundData
function.
Process Data
The values returned from latestRoundData()
and getRoundData(roundId)
functions do not include only the data feed value (=answer
) at corresponding round id
but also updatedAt
updatedAt
represents the timestamp when the round was updated last time.
We highly recommend you to keep track of all metadata returned by both
latestRoundData()
andgetRoundData(roundId)
. If your application is dependent on frequent updates, you have to make sure in application layer that data returned by any of these functions is not stale.
feedProxy
has several other auxiliary functions that should be utilized in order to avoid any issues from misrepresenting the answer
returned from data feed.
All answer
s are returned with a specific decimal precision that can be queried using decimals()
function.
FeedProxy
is always connected to a single Feed
, but this connection is not fixed and Feed
can be changed. If you want to make sure that you are still using the same Feed
you can ask for the Feed
address through getFeed()
function.
Use Feed Router
Conveniently access data feeds using
FeedRouter
contractAccess all functions in
FeedProxy
by including price pair name as parameter
Initialize FeedRouter that enables access to all supported data feeds.
Read the latest submitted value of given data feed (e.g. "BTC-USDT")
Read value submitted to a given data feed (e.g. "BTC-USDT") for specific roundId.
Get decimals for given data feed (e.g. "BTC-USDT")
Get Feed address associated with given data feed (e.g. "BTC-USDT").
Relation between FeedProxy
and Feed
FeedProxy
and Feed
When deploying anFeedProxy
, Feed
's address has to be specified to create a connection between the contracts. Consumer can then request data through latestRoundData
or getRoundData
functions, and data will be fetched from Feed
that is represented by the feedAddress
.
At times, it might be necessary to update the address of Feed
. If the Feed
address is updated, a queried data feed will come from a different Feed
than before the update. FeedProxy
's update of Feed
is split into two steps: proposal and confirmation. Both steps can be only executed with onlyOwner
privileges.
proposeFeed
stores the proposed address to storage variable and emits event about new address being proposed.
After the new Feed
is proposed, one can query a new data feed through a special functions: latestRoundDataFromProposedFeed
and getRoundDataFromProposedFeed
. These functions are useful for testing a new data feed, before accepting the new proposed Feed
.
The function confirmFeed
is used to finalize the transition to the new proposed Feed
, and can be executed only with account that has onlyOwner
privilege. New feed is finalized through setFeed
(called also inside of constructor
of FeedProxy
). Finally, the new feed is announced through emitted event.
Last updated