AggregatorRouter: Simplified Data Feed Access
We’re thrilled to unveil the AggregatorRouter
contract (PR #1049), bringing simplicity to data access. Say goodbye to the hassle of copying aggregator contract addresses for each data feed. Now, you can retrieve the latest data effortlessly by inputting the data feed name into the function. In this article, we will explain how you can read from our new AggregatorRouter
and how it differs from the conventional approach that uses AggregatorProxy
.
If you can’t wait to start buidling with our new AggregatorRouter
, please take a look at our updated example code and experience streamlined data access with AggregatorRouter
. Below, you can find official AggregatorRouter
contracts deployed to Cypress and Baobab.
| Network | Address |
|---------|--------------------------------------------|
| Cypress | 0x16937CFc59A8Cd126Dc70A75A4bd3b78f690C861 |
| Baobab | 0xAF821aaaEdeF65b3bC1668c0b910c5b763dF6354 |
Data Feed Access
Orakl Network Data Feed supports two ways to access data from our feeds: through AggregatorProxy
and newly through AggregatorRouter
.
AggregatorProxy
Every Aggregator
has a single AggregatorProxy
contract associated with it. AggregatorProxy
offers convenient ways to access round data given a round ID, the latest round data, aggregator address, feed decimals, and additional functions tailored for power users.
In the code listing below, you can see that in order to access the latest data from our feed, you need to know address of our AggregatorProxy
contract.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.16;
import {IAggregator} from "@bisonai/orakl-contracts/src/v0.1/interfaces/IAggregator.sol";
contract DataFeedConsumer {
function getLatestData(address aggregatorProxy) public {
(
uint80 roundId_
, int256 answer_
, uint startedAt
, uint updatedAt
, uint80 answeredInRound
) = IAggregator(aggregatorProxy).latestRoundData();
// continue based on received values from oracle
}
}
With our large collection of data feeds, it is challenging to keep track of all AggregatorProxy
contracts. Therefore, we have decided to simplify data access for our users by introducing AggregatorRouter
contract.
AggregatorRouter
AggregatorRouter
simplifies access to any of Orakl Network Data Feeds. Users only need to remember a single AggregatorRouter
address and can fetch data from any of the Orakl Network Data Feeds by their feed names.
Below, we display a similar code snippet as we had for AggregatorProxy
; however, in this case, we only need a single contract address (denoted as aggregatorRouter
) to access all Orakl Network Data Feeds. The data feed is selected by a feed name parameter (denoted as feedName
).
The AggregatorRouter
supports the same interface as AggregatorProxy
, allowing access round data given a round ID, the latest round data, aggregator address, feed decimals, and additional functions tailored for power users. The only difference is that all the functions in AggregatorRouter
routed to the Aggregator
contract accept a feed name parameter that defines the data feed we are requesting.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.16;
import {IAggregatorRouter} from "@bisonai/orakl-contracts/src/v0.1/interfaces/IAggregatorRouter.sol";
contract DataFeedRouterConsumer {
function getLatestData(address aggregatorRouter, string calldata feedName) public {
(
uint80 roundId_
, int256 answer_
, uint startedAt
, uint updatedAt
, uint80 answeredInRound
) = IAggregatorRouter(aggregatorRouter).latestRoundData(feedName);
// continue based on received values from oracle
}
}
The feed names accepted by AggregatorRouter
follow a specific format: BASE-QUOTE
, where BASE
represents the token of interest, and QUOTE
represents the token in which the value of the BASE
token is denominated. The QUOTE
token is usually defined by stablecoins (e.g., USDT, USDC, …). Both BASE
and QUOTE
are connected by a hyphen symbol (-
) and spelled in uppercase letters.
The list of all currently supported feed names in Klaytn Cypress can be found in configuration table under name
column.
New To Orakl Network?
Orakl Network is an easy to use native token oracle that supports Verifiable Random Functions (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
.