EVM

This section contains all the neccesary information such as functions and interfaces required for utilizing data feeds in the solidity smart contracts .

DataFeedV1 Interface

For interacting with the data feed contract for retrieving data feeds into your contract , use the below given interface in your solidity contract .

interface IDataFeedV1 {
    function requestPrices(
        bytes32[] calldata _assets,
        function(uint8[] memory, uint256[] memory) external _callback
    ) external payable;

    function feePerAsset() external view returns (uint256);
}

Functions in IDataFeedV1 interface

Name
Description

requestPrices

function for requesting data feeds from the data feed contract .

feesPerAsset

function for querying the fees Per Data Feed for the respective chain .

requestPrice

For requesting the data feeds from the data feed contract

Parameter
Description

bytes32[] _assets

array of keccak256 hash of the data feeds to be requested

_callback

a callback function for recieving the response data from the data feed contract

_callback

callback function defined in the contract requesting the data feeds , this function recieves the response and processes the response data as specified by the user according to their use case .

Parameter
Description

uint8[] decimals

number of decimals to be adjusted in the price retrieved

uint256[] prices

price of the requested asset multiplied by the decimals .

Example Usage

contract DataFeedInteractor  {
    address public constant PRICE_FEED_PROXY = 0x30B3731d5fE29E768Ab282dBF2c79D9A70776Ad0; // Data Feed Address on Arbitrum Sepolia
    IDataFeed public priceFeed;

    uint8[] public lastDecimals;
    uint256[] public lastPrices;

    event PricesReceived(uint8[] decimals, uint256[] prices);

    constructor() {
        priceFeed = IDataFeedV1(PRICE_FEED_PROXY);
    }

    function requestPrices(bytes32[] calldata _assets) external payable {
        uint256 totalFee = priceFeed.feePerAsset() * _assets.length;
        require(msg.value >= totalFee, "Insufficient fee");

        priceFeed.requestPrices{value: totalFee}(_assets, this.dataCallback);

        // Refund excess fee
        if (msg.value > totalFee) {
            payable(msg.sender).transfer(msg.value - totalFee);
        }
    }

    // Callback to handle the response
    function dataCallback(uint8[] memory _decimals, uint256[] memory _prices) external {
        require(msg.sender == PRICE_FEED_PROXY, "Unauthorized callback");

        lastDecimals = _decimals;
        lastPrices = _prices;

        emit PricesReceived(_decimals, _prices);
    }

    function getLastPrices() external view returns (uint8[] memory, uint256[] memory) {
        return (lastDecimals, lastPrices);
    }

    // Receive function to handle refunds in case of excess funds
    receive() external payable {}
}

Last updated