Price Oracle Contract API

Description

One of the key advantages of the Bifrost Network is its native price oracle, which offers a wide range of digital asset prices sourced from centralized exchanges (CEXs) and decentralized exchanges (DEXs) on other networks. We have made the price oracle for CCCP-supported assets publicly available to all developers on the Bifrost Network. We hope many DApp developers will enjoy these benefits through our network.

To minimize the learning curve, our oracle service includes an abstraction layer that provides an interface compatible with Chainlink's. This design choice not only reduces the time needed for developers to adapt but also enables seamless integration for those already familiar with Chainlink's environment.

In the following sections, we will explain how to utilize Bifrost's price oracle.

Price Feed Methods

decimals()

Returns USD price decimals for a specific asset (e.g., the USD price of ETH).

Return values

description()

Return the type of a specific oracle feeder (e.g., ETH/USD)

Return values

version()

Return the version of a specific oracle feed contract.

Return values

getRoundData(_roundId)

Return the price information from the previous round along with the timestamp of that update.

Parameters

Return values

latestRoundData()

Return the latest price information along with the timestamp of the most recent update.

Return values

Price Feed Contract Interface

interface IAccessControlledOffchainAggregator {
  function decimals() external view returns (uint8);
  function description() external view returns (string memory);
  function version() external pure returns (uint256);
  function getRoundData(uint80 _roundId) external view
  returns (
    uint80 roundId,
    int256 answer,
    uint256 startedAt,
    uint256 updatedAt,
    uint80 answeredInRound
  );
  function latestRoundData() external view
  returns (
    uint80 roundId,
    int256 answer,
    uint256 startedAt,
    uint256 updatedAt,
    uint80 answeredInRound
  );
}

Price Feed Contract Address

Example: ETH/USD price oracle (testnet)

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

interface IAccessControlledOffchainAggregator {
  function decimals() external view returns (uint8);
  function description() external view returns (string memory);
  function version() external pure returns (uint256);
  function getRoundData(uint80 _roundId) external view
  returns (
    uint80 roundId,
    int256 answer,
    uint256 startedAt,
    uint256 updatedAt,
    uint80 answeredInRound
  );
  function latestRoundData() external view
  returns (
    uint80 roundId,
    int256 answer,
    uint256 startedAt,
    uint256 updatedAt,
    uint80 answeredInRound
  );
}

contract ChainlinkPriceOracle {
    IAccessControlledOffchainAggregator internal priceFeed;

    constructor() {
        // ETH / USD price oracle address (testnet)
        priceFeed = IAccessControlledOffchainAggregator(0x786cA38641bD2eE6f4c9397056F9CF9d9C893eEA);
    }

    function getLatestPrice() public view returns (int) {
        (
            uint80 roundID,
            int price,
            uint startedAt,
            uint timeStamp,
            uint80 answeredInRound
        ) = priceFeed.latestRoundData();
        // for ETH / USD price is scaled up by 10 ** 8
        return price / 1e8;
    }
}

Last updated