-
Notifications
You must be signed in to change notification settings - Fork 21
/
ManualOracle.sol
60 lines (47 loc) · 2.03 KB
/
ManualOracle.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
// SPDX-License-Identifier: MIT
pragma solidity 0.8.23;
import {IOracle} from "./../interfaces/oracles/IOracle.sol";
import {Ownable} from "@openzeppelin-v5.0.0/contracts/access/Ownable.sol";
contract ManualOracle is IOracle, Ownable {
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* CUSTOM ERRORS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Invalid price, can't be negative or zero
error InvalidPrice();
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* EVENTS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Emitted when the price is updated
event UpdatedPrice(int256 _price);
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* CONSTANTS AND IMMUTABLES */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Current price, can be updated by the owner
int256 public price;
constructor(
int256 _price,
address _owner
) Ownable(_owner) {
_setPrice(_price);
}
function _setPrice(int256 _price) internal {
if (_price <= 0) revert InvalidPrice();
price = _price;
emit UpdatedPrice(_price);
}
function setPrice(int256 _price) external onlyOwner {
_setPrice(_price);
}
function decimals() external override pure returns (uint8) {
return 8;
}
function latestRoundData() external override view returns (
uint80 roundId,
int256 answer,
uint256 startedAt,
uint256 updatedAt,
uint80 answeredInRound
) {
return (uint80(0), price, 0, block.timestamp, uint80(0));
}
}