/ test / ChainlinkPriceFeed.sol
ChainlinkPriceFeed.sol
 1  // SPDX-License-Identifier: MIT
 2  pragma solidity ^0.8.0;
 3  
 4  interface AggregatorV3Interface {
 5    function decimals() external view returns (uint8);
 6  
 7    function latestRoundData()
 8      external
 9      view
10      returns (
11        uint80 roundId,
12        int256 answer,
13        uint256 startedAt,
14        uint256 updatedAt,
15        uint80 answeredInRound
16      );
17  }
18  
19  contract ChainlinkPriceFeed {
20    AggregatorV3Interface constant ethPriceFeed = AggregatorV3Interface(0xAB594600376Ec9fD91F8e885dADF0CE036862dE0);//0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419);
21  
22    function getEthPriceInUsd() external view returns (uint256 ethPrice) {
23      ethPrice = chainlinkPrice(ethPriceFeed) / 10**6;
24    }
25  
26    function chainlinkPrice(AggregatorV3Interface priceFeed) internal view returns (uint256) {
27      (
28          /* uint80 roundID */,
29          int price,
30          /*uint startedAt*/,
31          /*uint timeStamp*/,
32          /*uint80 answeredInRound*/
33      ) = priceFeed.latestRoundData();
34      return uint256(price);
35    }
36  }