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

Name
Type
Description

uint8

The decimals (now only USD support) for a specific asset

description()

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

Return values

Name
Type
Description

string

The type of a specific oracle feeder

version()

Return the version of a specific oracle feed contract.

Return values

Name
Type
Description

uint256

The version of a specific oracle feed contract.

getRoundData(_roundId)

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

Parameters

Name
Type
Description

_roundId

uint8

The round ID of desired price information.

Return values

Name
Type
Description

roundId

uint80

The round ID.

answer

int256

The price information for this round.

startedAt

uint256

The timestamp of when the round started.

updatedAt

uint256

The timestamp of when the round was updated.

answeredInRound

uint80

The answers could take multiple rounds to be computed.

latestRoundData()

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

Return values

Name
Type
Description

roundId

uint80

The round ID.

answer

int256

The price information for this round.

startedAt

uint256

The timestamp of when the round started.

updatedAt

uint256

The timestamp of when the round was updated.

answeredInRound

uint80

The answers could take multiple rounds to be computed.

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

Asset/Fiat Type
Contract Address (mainnet/testnet)

ETH/USD

mainnet: 0x0427d2908E45FAfD65F56a6A6E2095461e70A3d6 testnet: 0x786cA38641bD2eE6f4c9397056F9CF9d9C893eEA

USDC/USD

mainnet: 0x2FFc2e7C4c280eb82A13972cCA30719F9365746F testnet: 0x9Fa06A8f3454b902b4ecdaBB6eBC8F56CC536609

BNB/USD

mainnet: 0x1Eda422B45b279c8C280B510cbf4BDFB671985c0 testnet: 0x590A94102B03b10d4aDF8bfc83aCC556dc9745E5

MATIC/USD

mainnet: 0x59C75485126Ac9a90609E7Fe5D6c513396ED503d testnet: 0x534Fa69E2616444B5DFB940f3a893D8183fEDcD7

BIFI/USD

mainnet: 0xc97D3b8d03ec813b760C8A471F3c8393e4F91506 testnet: 0x42acD3003fA8b870999573071427C64A90146991

BFC/USD

mainnet: 0x77397a130c169702Ff007682630eCAa5caB23791 testnet: 0xEF746B668880f83F06245245017B31523e485Df8

USDT/USD

mainnet: 0xd8653315Dc63128AA8428C6Ae12E50b5E77156AC testnet: 0xfdcC92216E7236E6f0A2033B1d63D3505369945b

DAI/USD

mainnet: 0xF2385A5DDa77fF9731F661aA44f6b4398A97A1cd testnet: 0x4842D3a8c29fABfB971AeD8675262c16b71ef2Dd

WBTC/USD

mainnet: 0xc1596ece7e801125D507f0815e7070Aa97D3645e testnet: 0x1aF3595Ba40EAb3481f19245E5a0F09018e85Aa4

BTCB/USD

mainnet: 0x40c8BB8036351EF29b41ea8AFEbA76ac2d8A96bF testnet: 0x0B2C85312E35829e714Fef01efAD6d2718e3c227

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