Data Feed V2 Migration Guide

Orakl Network
5 min readMay 16, 2024

--

Orakl Network is planning to update its Data Feed service, transitioning from on-chain to off-chain aggregation. This change involves updates to the smart contracts’ ABIs. In this blog post, current users of Orakl Network will be guided on how to migrate from the old to the new version of Data Feed. This update is required for those who are utilizing AggregatorProxy or AggregatorRouter smart contracts.

The launch date of Orakl Network Data Feed V2 will happen early in June, 2024. Once Data Feed V2 is launched, the previous version enters a deprecation period that will last one month. Afterward, the previous Data Feed will no longer be updated.

The new version of the Orakl Network Data Feed has been audited by CertiK.

New Contract Interfaces

Below, you can find affected contracts and functions that could be used for retrieving data from the Feed (previously Aggregator) contract. To read the full version of the contract source code, please refer to the Orakl Network v0.2 repository.

FeedProxy (previously AggregatorProxy)

Oracles submit their answers to the Feed (previously Aggregator) contract, which represents a single asset. The FeedProxy enables us to read the latest and historical data submitted to the Feed contract.

/**
* @notice Get the latest round data of the feed.
* @dev This function internally calls getRoundData with the
* latest round ID. If no rounds have been submitted, this function
* reverts with the NoDataPresent error.
* @return id The round ID.
* @return answer The oracle answer.
* @return updatedAt Timestamp of the last update.
*/
function latestRoundData()
external
view
returns (uint64 id, int256 answer, uint256 updatedAt);

/**
* @notice Get round data given a round ID.
* @dev If the given roundId is higher than the latest round ID or
* feed has not been updated yet, this function reverts with
* NoDataPresent error.
* @param roundId The round ID.
* @return id The round ID.
* @return answer The oracle answer.
* @return updatedAt Timestamp of the last update.
*/
function getRoundData(uint64 roundId)
external
view
returns (uint64 id, int256 answer, uint256 updatedAt);

/**
* @notice Get the time-weighted average price (TWAP) of the feed
* over a given interval.
* @dev If the latest update time is older than the given tolerance,
* this function reverts with the AnswerAboveTolerance error. If the number of
* data points is less than the given minimum count, this function reverts
* with the InsufficientData error.
* @param interval The time interval in seconds.
* @param latestUpdatedAtTolerance The tolerance for the latest update time.
* @param minCount The minimum number of data points.
* @return The TWAP.
*/
function twap(uint256 interval, uint256 latestUpdatedAtTolerance, int256 minCount)
external
view
returns (int256);

FeedRouter (previously AggregatorRouter)

The FeedRouter enables us to read the latest and historical data from any of the Feed contracts simply by specifying a feed name.

/**
* @notice Get the latest round data of the feed given a feed name.
* @param feedName The feed name.
* @return id The round ID.
* @return answer The oracle answer.
* @return updatedAt Timestamp of the last update.
*/
function latestRoundData(string calldata feedName)
external
view
returns (uint64 id, int256 answer, uint256 updatedAt);

/**
* @notice Get the round data given a a feedd name and round ID.
* @param feedName The feed name.
* @param roundId The round ID.
* @return id The round ID.
* @return answer The oracle answer.
* @return updatedAt Timestamp of the last update.
*/
function getRoundData(string calldata feedName, uint64 roundId)
external
view
returns (uint64 id, int256 answer, uint256 updatedAt);

/**
* @notice Get the time-weighted average price (TWAP) of the feed
* over a given interval.
* @param feedName The feed name.
* @param interval The time interval in seconds.
* @param latestUpdatedAtTolerance The tolerance for the latest update time.
* @param minCount The minimum number of data points.
* @return The TWAP.
*/
function twap(string calldata feedName, uint256 interval, uint256 latestUpdatedAtTolerance, int256 minCount)
external
view
returns (int256);

Guide For Data Feed Consumers

The FeedProxy and FeedRouter contracts have not been deployed yet. Once they will be deployed, you can find their addresses in this blog post and on the Data Feed page. You can refer to the recommended use of Orakl Network Data Feed at our Bisonai/data-feed-consumer repository.

AggregatorProxyFeedProxy

  1. Update the contract address (use FeedProxy instead of AggregatorProxy contract).
  2. Update the consumer contract code based on the new ABI.

AggregatorProxy (deprecated soon)

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.16;

import {IAggregator} from "@bisonai/orakl-contracts/v0.1/src/interfaces/IAggregator.sol";

contract DataFeedConsumer {
IAggregator internal dataFeed;
int256 public answer;
uint80 public roundId;

constructor(address aggregatorProxy) {
dataFeed = IAggregator(aggregatorProxy);
}

function getLatestData() public {
(
uint80 roundId_,
int256 answer_
, /* uint startedAt */
, /* uint updatedAt */
, /* uint80 answeredInRound */
) = dataFeed.latestRoundData();

answer = answer_;
roundId = roundId_;
}

function decimals() public view returns (uint8) {
return dataFeed.decimals();
}
}

FeedProxy (new recommended version)

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.16;

import {IFeed} from "@bisonai/orakl-contracts/v0.2/src/interfaces/IFeed.sol";

contract DataFeedConsumer {
IFeed internal dataFeed;
int256 public answer;
uint64 public roundId;

constructor(address feedProxy) {
dataFeed = IFeed(feedProxy);
}

function getLatestData() public {
(
uint64 roundId_,
int256 answer_
, /* uint256 updatedAt */
) = dataFeed.latestRoundData();

answer = answer_;
roundId = roundId_;
}

function decimals() public view returns (uint8) {
return dataFeed.decimals();
}
}

AggregatorRouterFeedRouter

  1. Update the contract address (use FeedRouter instead of AggregatorRouter).
  2. Update the consumer contract code based on the updated ABI.

AggregatorRouter (deprecated soon)

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.16;

import {IAggregatorRouter} from "@bisonai/orakl-contracts/v0.1/src/interfaces/IAggregatorRouter.sol";

contract DataFeedRouterConsumer {
IAggregatorRouter internal router;
int256 public answer;
uint80 public roundId;

constructor(address aggregatorRouter) {
router = IAggregatorRouter(aggregatorRouter);
}

function getLatestData(string calldata pair) public {
(
uint80 roundId_,
int256 answer_
, /* uint startedAt */
, /* uint updatedAt */
, /* uint80 answeredInRound */
) = router.latestRoundData(pair);

answer = answer_;
roundId = roundId_;
}

function decimals(string calldata pair) public view returns (uint8) {
return router.decimals(pair);
}
}

FeedRouter (new recommended version)

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.16;

import {IFeedRouter} from "@bisonai/orakl-contracts/v0.2/src/interfaces/IFeedRouter.sol";

contract DataFeedRouterConsumer {
IFeedRouter internal router;
int256 public answer;
uint64 public roundId;

constructor(address feedRouter) {
router = IFeedRouter(feedRouter);
}

function getLatestData(string calldata feedName) public {
(
uint64 roundId_,
int256 answer_
, /* uint updatedAt */
) = router.latestRoundData(feedName);

answer = answer_;
roundId = roundId_;
}

function decimals(string calldata feedName) public view returns (uint8) {
return router.decimals(feedName);
}
}

New to Orakl Network?

Orakl Network is an easy to use native token oracle that supports Verifiable Randomness Function (VRF), Request-Response, Data Feed and Proof of Reserve. You can learn about each of these functionalities at our documentation or dive directly to code with curated hands-on tutorials for each of our services: vrf-consumer, request-response-consumer and data-feed-consumer.

How Do I Find Out More About Orakl Network?

Website | Docs | X | Medium | GitHub

Orakl Network Is Built By Bisonai. Join Us! 🦬

Website | X | Medium | GitHub | Blockchain Software Engineer

--

--

Orakl Network

Orakl Network is a decentralized oracle network that allows smart contracts to securely access off-chain data and other resources.