-
Notifications
You must be signed in to change notification settings - Fork 12
/
RETHExchangeRateOracle.sol
46 lines (34 loc) · 1.35 KB
/
RETHExchangeRateOracle.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
// SPDX-License-Identifier: AGPL-3.0
pragma solidity ^0.8.0;
import { IPriceSource } from "./interfaces/IPriceSource.sol";
interface IRocketPoolStakedEth {
function getExchangeRate() external view returns (uint256);
}
/**
* @title RETHExchangeRateOracle
* @dev Provides rETH / USD by multiplying the rETH exchange rate by ETH / USD.
* This provides a "non-market" price. Any depeg event will be ignored.
*/
contract RETHExchangeRateOracle {
/// @notice RocketPool staked eth token contract.
IRocketPoolStakedEth public immutable reth;
/// @notice The price source for ETH / USD.
IPriceSource public immutable ethSource;
constructor(address _reth, address _ethSource) {
// 8 decimals required as AaveOracle assumes this
require(IPriceSource(_ethSource).decimals() == 8, "RETHExchangeRateOracle/invalid-decimals");
reth = IRocketPoolStakedEth(_reth);
ethSource = IPriceSource(_ethSource);
}
function latestAnswer() external view returns (int256) {
int256 ethUsd = ethSource.latestAnswer();
int256 exchangeRate = int256(reth.getExchangeRate());
if (ethUsd <= 0 || exchangeRate <= 0) {
return 0;
}
return exchangeRate * ethUsd / 1e18;
}
function decimals() external pure returns (uint8) {
return 8;
}
}