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 pathCustomPriceOracle.sol
71 lines (55 loc) · 2.04 KB
/
CustomPriceOracle.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
64
65
66
67
68
69
70
71
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
import { IPriceOracle } from "../OracleInterface/IPriceOracle.sol";
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
contract CustomPriceOracle is IPriceOracle, Ownable {
string public description;
uint256 public currentPrice;
uint256 public lastPrice;
uint256 public lastUpdateTimestamp;
uint8 public decimals;
address public asset;
uint8 public constant MAX_DECIMALS = 18;
mapping(address => bool) private trustedNodes;
modifier isTrusted() {
if (!trustedNodes[msg.sender]) revert NotTrustedAddress();
_;
}
modifier checkNonZeroAddress(address _addr) {
if (_addr == address(0)) revert ZeroAddress();
_;
}
constructor(string memory _description, address _underlying, uint8 _decimals) {
if (_decimals > MAX_DECIMALS) revert InvalidDecimals();
description = _description;
decimals = _decimals;
asset = _underlying;
}
function registerTrustedNode(address _node) external checkNonZeroAddress(_node) onlyOwner {
trustedNodes[_node] = true;
emit NodeRegistered(address(this), _node);
}
function unregisterTrustedNode(address _node) external checkNonZeroAddress(_node) onlyOwner {
trustedNodes[_node] = false;
emit NodeUnRegistered(address(this), _node);
}
function isTrustedNode(address _node) external view returns (bool) {
return trustedNodes[_node];
}
function updatePrice(uint256 _newPrice) external isTrusted {
lastPrice = currentPrice;
currentPrice = _newPrice;
lastUpdateTimestamp = block.timestamp;
emit PriceUpdated(address(this), currentPrice, lastUpdateTimestamp);
}
function getLatestPrice(
bytes calldata
)
external
view
override
returns (uint256 _currentPrice, uint256 _lastPrice, uint256 _lastUpdateTimestamp, uint8 _decimals)
{
return (currentPrice, lastPrice, lastUpdateTimestamp, decimals);
}
}