This repository has been archived by the owner on May 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
WSTETHOracle.sol
90 lines (69 loc) · 3.09 KB
/
WSTETHOracle.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
import {Errors} from "../utils/Errors.sol";
import {IOracle} from "../core/IOracle.sol";
import {FixedPointMathLib} from "solmate/utils/FixedPointMathLib.sol";
import {AggregatorV3Interface} from "../chainlink/AggregatorV3Interface.sol";
/**
@title WSTETH Oracle
@notice Oracle that returns price of wsteth
arbi:0x5979D7b546E38E414F7E9822514be443A4800529
*/
contract WSTETHOracle is IOracle {
using FixedPointMathLib for uint;
/* -------------------------------------------------------------------------- */
/* STATE VARIABLES */
/* -------------------------------------------------------------------------- */
/// @notice WSTETH/STETH chainlink price feed
AggregatorV3Interface immutable WSTETHFeed;
/// @notice STETH/USD chainlink price feed
AggregatorV3Interface immutable STETHFeed;
/// @notice ETH USD Chainlink price feed
AggregatorV3Interface immutable ethUsdPriceFeed;
/* -------------------------------------------------------------------------- */
/* CONSTRUCTOR */
/* -------------------------------------------------------------------------- */
constructor(
AggregatorV3Interface _WSTETHFeed,
AggregatorV3Interface _STETHFeed,
AggregatorV3Interface _ethUsdPriceFeed
)
{
WSTETHFeed = _WSTETHFeed;
STETHFeed = _STETHFeed;
ethUsdPriceFeed = _ethUsdPriceFeed;
}
/// @inheritdoc IOracle
function getPrice(address token) external view returns (uint) {
(, int answer,, uint updatedAt,) =
WSTETHFeed.latestRoundData();
if (block.timestamp - updatedAt >= 86400)
revert Errors.StalePrice(token, address(WSTETHFeed));
if (answer <= 0)
revert Errors.NegativePrice(token, address(WSTETHFeed));
return uint(answer).mulWadDown(getSTETHPrice());
}
/* -------------------------------------------------------------------------- */
/* INTERNAL FUNCTIONS */
/* -------------------------------------------------------------------------- */
function getSTETHPrice() internal view returns (uint) {
(, int answer,, uint updatedAt,) =
STETHFeed.latestRoundData();
if (block.timestamp - updatedAt >= 86400)
revert Errors.StalePrice(address(0), address(WSTETHFeed));
if (answer <= 0)
revert Errors.NegativePrice(address(0), address(WSTETHFeed));
return (
(uint(answer)*1e18)/getEthPrice()
);
}
function getEthPrice() internal view returns (uint) {
(, int answer,, uint updatedAt,) =
ethUsdPriceFeed.latestRoundData();
if (block.timestamp - updatedAt >= 86400)
revert Errors.StalePrice(address(0), address(ethUsdPriceFeed));
if (answer <= 0)
revert Errors.NegativePrice(address(0), address(ethUsdPriceFeed));
return uint(answer);
}
}