-
Notifications
You must be signed in to change notification settings - Fork 0
/
OlympusOracle.sol
63 lines (57 loc) · 2.29 KB
/
OlympusOracle.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
// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;
import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import {AggregatorV3Interface} from "../../interfaces/oracles/chainlink/AggregatorV3Interface.sol";
import {IOracle} from "../../interfaces/IOracle.sol";
import {IOlympus} from "../../interfaces/oracles/IOlympus.sol";
import {ChainlinkBasic} from "./ChainlinkBasic.sol";
import {Errors} from "../../../Errors.sol";
/**
* @dev supports olympus gOhm oracles which are compatible with v2v3 or v3 interfaces
* should only be utilized with eth based oracles, not usd-based oracles
*/
contract OlympusOracle is IOracle, ChainlinkBasic {
address internal constant OHM_ADDR =
0x0ab87046fBb341D058F17CBC4c1133F25a20a52f;
address internal constant GOHM_ADDR =
0x0ab87046fBb341D058F17CBC4c1133F25a20a52f;
uint256 internal constant SOHM_DECIMALS = 9;
address internal constant ETH_OHM_ORACLE_ADDR =
0x9a72298ae3886221820B1c878d12D872087D3a23;
constructor(
address[] memory _tokenAddrs,
address[] memory _oracleAddrs
)
ChainlinkBasic(
_tokenAddrs,
_oracleAddrs,
0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2, // weth address
1e18 // 18 decimals for ETH based oracles
)
{
oracleAddrs[OHM_ADDR] = ETH_OHM_ORACLE_ADDR;
}
function getPrice(
address collToken,
address loanToken
)
external
view
override(ChainlinkBasic, IOracle)
returns (uint256 collTokenPriceInLoanToken)
{
if (collToken != GOHM_ADDR && loanToken != GOHM_ADDR) {
revert Errors.NeitherTokenIsGOHM();
}
uint256 priceOfCollToken = getPriceOfToken(collToken);
uint256 priceOfLoanToken = getPriceOfToken(loanToken);
uint256 loanTokenDecimals = IERC20Metadata(loanToken).decimals();
uint256 index = IOlympus(GOHM_ADDR).index();
collTokenPriceInLoanToken = collToken == GOHM_ADDR
? (priceOfCollToken * (10 ** loanTokenDecimals) * index) /
(priceOfLoanToken * (10 ** SOHM_DECIMALS))
: (priceOfCollToken *
(10 ** loanTokenDecimals) *
(10 ** SOHM_DECIMALS)) / (priceOfLoanToken * index);
}
}