This repository has been archived by the owner on Sep 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathGLPPriceOracle.sol
51 lines (42 loc) · 1.66 KB
/
GLPPriceOracle.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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
import { IPriceOracle } from "../OracleInterface/IPriceOracle.sol";
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
import { Address } from "@openzeppelin/contracts/utils/Address.sol";
import { IGLPManager } from "../OracleInterface/IGLPManager.sol";
import { ParseBytes } from "../../Libs/ParseBytes.sol";
contract GLPPriceOracle is IPriceOracle, Ownable {
using Address for address;
using ParseBytes for bytes;
string public description;
uint8 public decimals;
address public asset;
// GLP has default precision as 30
uint8 public constant MAX_DECIMALS = 30;
// GLP Manager address
IGLPManager public glpManager;
constructor(string memory _description, address _underlying, uint8 _decimals, address _glpManager) {
if (_decimals > MAX_DECIMALS) revert InvalidDecimals();
if (!_glpManager.isContract()) revert notContract();
description = _description;
decimals = _decimals;
asset = _underlying;
glpManager = IGLPManager(_glpManager);
}
function getLatestPrice(
bytes calldata _maximise
)
external
view
override
returns (uint256 _currentPrice, uint256 _lastPrice, uint256 _lastUpdateTimestamp, uint8 _decimals)
{
bool isMax = _maximise.parse32BytesToBool();
uint256 price = glpManager.getPrice(isMax);
return (price, price, block.timestamp, decimals);
}
function setGlpManager(address _glpManager) external onlyOwner {
if (!_glpManager.isContract()) revert notContract();
glpManager = IGLPManager(_glpManager);
}
}