From a031f155190e5d508c0b7eaf95bf850deaf054c6 Mon Sep 17 00:00:00 2001 From: aviral727 Date: Wed, 26 Oct 2022 23:46:29 +0530 Subject: [PATCH 1/2] feat: added a dynamic smart contract(Price Feed) --- contracts/Oracle/PriceFeed.sol | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 contracts/Oracle/PriceFeed.sol diff --git a/contracts/Oracle/PriceFeed.sol b/contracts/Oracle/PriceFeed.sol new file mode 100644 index 0000000..59c6b22 --- /dev/null +++ b/contracts/Oracle/PriceFeed.sol @@ -0,0 +1,31 @@ +// SPDX-License-Identifier: MIT + +pragma solidity ^0.8; + +contract TestChainlink { + AggregatorV3Interface internal priceFeed; + + constructor() { + priceFeed = AggregatorV3Interface(0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419); + + } + + function getLatestPrice() public view returns(int) { + ( + uint80 roundID, + int price, + uint startedAt, + uint timeStamp, + uint80 answeredInRound + ) = priceFeed.latestRoundData(); + + return price / 1e8; + } +} + +interface AggregatorV3Interface { + function latestRoundData() external view returns (uint80 roundId, int answer, uint startedAt, uint updatedAt, uint80 answeredInRound); +} + + + From 33644fd231a9ffa200e52e7b02c858431ad3ecc3 Mon Sep 17 00:00:00 2001 From: aviral727 Date: Thu, 27 Oct 2022 14:19:56 +0530 Subject: [PATCH 2/2] imported chainlink interface directly due to issues --- contracts/Oracle/PriceFeed.sol | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/contracts/Oracle/PriceFeed.sol b/contracts/Oracle/PriceFeed.sol index 59c6b22..32ee19a 100644 --- a/contracts/Oracle/PriceFeed.sol +++ b/contracts/Oracle/PriceFeed.sol @@ -2,6 +2,8 @@ pragma solidity ^0.8; +import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol"; + contract TestChainlink { AggregatorV3Interface internal priceFeed; @@ -23,9 +25,9 @@ contract TestChainlink { } } -interface AggregatorV3Interface { - function latestRoundData() external view returns (uint80 roundId, int answer, uint startedAt, uint updatedAt, uint80 answeredInRound); -} +// interface AggregatorV3Interface { +// function latestRoundData() external view returns (uint80 roundId, int answer, uint startedAt, uint updatedAt, uint80 answeredInRound); +// }