-
Notifications
You must be signed in to change notification settings - Fork 41
/
STECRVOracle.sol
46 lines (39 loc) · 1.51 KB
/
STECRVOracle.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-only
// Using the same Copyleft License as in the original Repository
pragma solidity 0.6.12;
pragma experimental ABIEncoderV2;
import './interfaces/IOracle.sol';
import '../interfaces/IChainlinkAggregator.sol';
import '../interfaces/ICurvePool.sol';
import {Math} from '../dependencies/openzeppelin/contracts/Math.sol';
/**
* @dev Oracle contract for Curve.fi ETH/stETH (steCRV) LP Token
*/
contract STECRVOracle is IOracle {
ICurvePool public constant STECRV = ICurvePool(0xDC24316b9AE028F1497c275EB9192a3Ea0f67022);
IChainlinkAggregator public constant STETH =
IChainlinkAggregator(0x86392dC19c0b719886221c78AB11eb8Cf5c52812);
/**
* @dev Get LP Token Price
*/
function _get() internal view returns (uint256) {
uint256 stETH_Price = uint256(STETH.latestAnswer());
uint256 minValue = Math.min(stETH_Price, 1e18);
return (STECRV.get_virtual_price() * minValue) / 1e18;
}
// Get the latest exchange rate, if no valid (recent) rate is available, return false
/// @inheritdoc IOracle
function get() public override returns (bool, uint256) {
return (true, _get());
}
// Check the last exchange rate without any state changes
/// @inheritdoc IOracle
function peek() public view override returns (bool, int256) {
return (true, int256(_get()));
}
// Check the current spot exchange rate without any state changes
/// @inheritdoc IOracle
function latestAnswer() external view override returns (int256 rate) {
return int256(_get());
}
}