-
Notifications
You must be signed in to change notification settings - Fork 0
/
PriceConsumerV3.sol
43 lines (38 loc) · 1.12 KB
/
PriceConsumerV3.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;
import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
contract PriceConsumerV3 {
AggregatorV3Interface internal priceFeed;
address public priceProvider;
/**
* Network: Sepolia
* Aggregator: ETH/USD
* Address: 0x1b44F3514812d835EB1BDB0acB33d3fA3351Ee43
*/
constructor(address _priceProvider) {
priceProvider = _priceProvider;
priceFeed = AggregatorV3Interface(
_priceProvider
);
}
function setPriceProvider(address _priceProvider) public {
priceProvider = _priceProvider;
priceFeed = AggregatorV3Interface(
_priceProvider
);
}
/**
* Returns the latest price.
*/
function getLatestPrice() public view returns (int) {
// prettier-ignore
(
/* uint80 roundID */,
int price,
/*uint startedAt*/,
/*uint timeStamp*/,
/*uint80 answeredInRound*/
) = priceFeed.latestRoundData();
return price;
}
}