Skip to content

Price Feed Berachain

Git Source

The PriceFeed contract is a smart contract that provides the latest price data for a given currency pair. It is similar to Chainlink's AggregatorV3Interface in that it retrieves price data from an external source, in this case, the Oracle module. The PriceFeed contract imports the AggregatorV3Interface and the Oracle module, and it implements the required functions to fetch the latest price data for a specified currency pair.

The PriceFeed contract uses the Oracle module to interact with the precompiled contract at a specific address, which stores the price data for various currency pairs. It initializes the contract with a currency pair and retrieves the precision (number of decimals) for that pair. The contract provides functions to get the latest price data, including the round ID, price, timestamp, and other metadata.

By leveraging the Oracle module, the PriceFeed contract ensures that the price data is reliable and secure, similar to how Chainlink's decentralized oracle network provides high-quality price data.

Note: Link to existing contract ABI's can be found on Github here.

Inherits:AggregatorV3Interface

This contract provides the latest price data for a given currency pair.

This contract implements Chainlink's AggregatorV3Interface.

State Variables

oracleModule

solidity
IOracleModule internal immutable oracleModule = IOracleModule(0x9202Af6Ce925b26AE6B25aDfff0B2705147e195F);
IOracleModule internal immutable oracleModule = IOracleModule(0x9202Af6Ce925b26AE6B25aDfff0B2705147e195F);

pair

solidity
string internal pair;
string internal pair;

versionNumber

solidity
uint256 internal immutable versionNumber;
uint256 internal immutable versionNumber;

precision

solidity
uint8 internal immutable precision;
uint8 internal immutable precision;

Functions

constructor

Only the Oracle Module can create a new PriceFeed instance.

Constructs a new PriceFeed instance.

solidity
constructor(string memory currencyPair);
constructor(string memory currencyPair);

Parameters

NameTypeDescription
currencyPairstringThe currency pair for which to provide the latest price data.

decimals

Returns the number of decimal places used in the price data.

solidity
function decimals() external view returns (uint8);
function decimals() external view returns (uint8);

description

Returns a description of the currency pair for which the contract provides price data.

solidity
function description() external view returns (string memory);
function description() external view returns (string memory);

version

Returns the version number for the PriceFeed contract.

solidity
function version() external view returns (uint256);
function version() external view returns (uint256);

getRoundData

NOT CURRENTLY SUPPORTED.

Returns the latest price data for the specified round.

solidity
function getRoundData(uint80 _roundId)
    external
    view
    returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound);
function getRoundData(uint80 _roundId)
    external
    view
    returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound);

Parameters

NameTypeDescription
_roundIduint80The round for which to return the price data.

latestRoundData

answeredInRound is deprecated.

updatedAt is not supported.

roundId is always equal to block height.

Returns the latest price data for the specified currency pair.

solidity
function latestRoundData()
    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);