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 1
/
GLPOracle.sol
59 lines (46 loc) · 2.11 KB
/
GLPOracle.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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
import {Errors} from "../utils/Errors.sol";
import {IOracle} from "../core/IOracle.sol";
import {IGLPManager} from "./IGLPManager.sol";
import {AggregatorV3Interface} from "../chainlink/AggregatorV3Interface.sol";
/**
@title GLP Oracle
*/
contract GLPOracle is IOracle {
/* -------------------------------------------------------------------------- */
/* STATE VARIABLES */
/* -------------------------------------------------------------------------- */
/// @notice address of gmx manager
IGLPManager public immutable manager;
/// @notice ETH USD Chainlink price feed
AggregatorV3Interface immutable ethUsdPriceFeed;
/* -------------------------------------------------------------------------- */
/* CONSTRUCTOR */
/* -------------------------------------------------------------------------- */
/**
@notice Contract constructor
@param _manager address of gmx vault
@param _ethFeed address of eth usdc chainlink feed
*/
constructor(IGLPManager _manager, AggregatorV3Interface _ethFeed) {
manager = _manager;
ethUsdPriceFeed = _ethFeed;
}
/* -------------------------------------------------------------------------- */
/* PUBLIC FUNCTIONS */
/* -------------------------------------------------------------------------- */
/// @inheritdoc IOracle
function getPrice(address) external view returns (uint) {
return manager.getPrice(false) / (getEthPrice() * 1e4);
}
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);
}
}