๐Ÿ’ฑGetting a different currency pair

eOracle feeds are provided in <SYMBOL>/USD by default. If you need a different currency pair, you can calculate it using two existing data feeds. For instance, to get the BTC/ETH price, you can use the BTC/USD feed and the ETH/USD feed and calculate BTC/ETH by dividing the two.

Here is an example:

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

interface IEOFeedManager {
    struct PriceFeed {
        uint256 value;
        uint256 timestamp;
    }
    function getLatestPriceFeed(uint16 symbol) external view returns (PriceFeed memory);
    function getLatestPriceFeeds(uint16[] calldata symbols) external view returns (PriceFeed[] memory);
}

/**
 * Network: Holesky
 * FeedManager: 0x723BD409703EF60d6fB9F8d986eb90099A170fd0
 */


contract PairConverter {
    uint256 constant PRECISION = 1e18; 
    function getConvertedPrice(
        address _feedManager,
    ) public view returns (int256) {
        uint256 btcRate  =  _feedManager.getLatestPriceFeed(1).rate; 
        uint256 ethRate =  _feedManager.getLatestPriceFeed(2).rate; 
        return ((btcRate * PRECISION) / ethRate);
    }


}

Last updated