-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample.sol
More file actions
65 lines (47 loc) · 2.17 KB
/
Example.sol
File metadata and controls
65 lines (47 loc) · 2.17 KB
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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
import "./FOInterfaceV1.sol";
import "./FOManagerInterfaceV1.sol";
/// @title Consumer Fact Oracle Contract
/// @notice This contract allows interaction with a Fact Oracle, providing methods to retrieve and manage oracle data
/// @dev Implements functions to fetch the latest data, data by timestamp, and accumulated values, with owner-only access control
contract ConsumerFOracle {
/* Oracle Setup */
FOInterfaceV1 public fOracle; /// @notice Instance of the FOInterfaceV1 to interact with the oracle
constructor(address _oracle) { /// @notice Constructor to initialize the ConsumerFOracle contract
owner = msg.sender;
updateOracle(_oracle);
}
function updateOracle(address _oracle) public onlyOwner { /// @notice Updates the oracle address
fOracle = FOInterfaceV1(_oracle);
}
/* Oracle Usage */
/// @notice Retrieves the latest data feed from the oracle and updates contract state variables
function getLast() public {
cdiDataFeed = fOracle.getLast();
}
/// @notice Retrieves the accumulated value of data feeds over a specified interval from the oracle
/// @param _start The start timestamp of the interval
/// @param _end The end timestamp of the interval
function getInterval(uint256 _start, uint256 _end) public {
accrued = fOracle.getInterval(_start, _end);
}
/// @notice Retrieves the data feed for a specific timestamp from the oracle and updates contract state variables
/// @param _timestamp The timestamp of the data feed to retrieve
function getDate(uint256 _timestamp) public {
cdiDataFeed = fOracle.getDate(_timestamp);
}
/* basic contract example */
address public owner;
DataFeed public cdiDataFeed;
int256 public accrued;
/// @notice Resets the contract state variables
function reset() public {
cdiDataFeed = DataFeed(0,0,0,0);
}
/// @dev Modifier to check if the caller is the contract owner
modifier onlyOwner() {
require(msg.sender == owner, "Caller is not the owner");
_;
}
}