-
Notifications
You must be signed in to change notification settings - Fork 12
/
WSTETHExchangeRateOracle.sol
46 lines (34 loc) · 1.37 KB
/
WSTETHExchangeRateOracle.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 ILidoStakedEth {
function getPooledEthByShares(uint256 shares) external view returns (uint256);
}
/**
* @title WSTETHExchangeRateOracle
* @dev Provides wstETH / USD by multiplying the wstETH exchange rate by ETH / USD.
* This provides a "non-market" price. Any depeg event will be ignored.
*/
contract WSTETHExchangeRateOracle {
/// @notice Lido staked eth token contract.
ILidoStakedEth public immutable steth;
/// @notice The price source for ETH / USD.
IPriceSource public immutable ethSource;
constructor(address _steth, address _ethSource) {
// 8 decimals required as AaveOracle assumes this
require(IPriceSource(_ethSource).decimals() == 8, "WSTETHExchangeRateOracle/invalid-decimals");
steth = ILidoStakedEth(_steth);
ethSource = IPriceSource(_ethSource);
}
function latestAnswer() external view returns (int256) {
int256 ethUsd = ethSource.latestAnswer();
int256 exchangeRate = int256(steth.getPooledEthByShares(1e18));
if (ethUsd <= 0 || exchangeRate <= 0) {
return 0;
}
return exchangeRate * ethUsd / 1e18;
}
function decimals() external pure returns (uint8) {
return 8;
}
}