-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathOracleFeeds.sol
55 lines (44 loc) · 1.7 KB
/
OracleFeeds.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
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.26;
import "@openzeppelin/contracts/access/AccessControl.sol";
contract OracleFeeds is AccessControl {
bytes32 public constant GOV_ROLE = keccak256("GOV_ROLE");
// Mapping of token pairs to their price feed addresses
mapping(address => mapping(address => address)) public priceFeeds;
mapping(address => uint256) public feedHeartbeats;
constructor() {
_grantRole(GOV_ROLE, msg.sender);
}
/**
* @dev Sets the price feed for a given token pair
* @param tokenA Address of the first token
* @param tokenB Address of the second token
* @param priceFeed Address of the price feed oracle
* Note: address(0) is a special address that represents USD (IRL asset)
*/
function setPriceFeed(address tokenA, address tokenB, address priceFeed, uint256 heartbeat) external onlyRole(GOV_ROLE) {
priceFeeds[tokenA][tokenB] = priceFeed;
if (heartbeat == 0) {
heartbeat = 1 days;
}
feedHeartbeats[priceFeed] = heartbeat;
}
/**
* @dev Grants `role` to `account`.
* If `account` had not been already granted `role`, emits a {RoleGranted} event.
* @param role The role to grant
* @param account The account to grant the role to
*/
function grantRole(bytes32 role, address account) public virtual override onlyRole(GOV_ROLE) {
_grantRole(role, account);
}
/**
* @dev Revokes `role` from `account`.
* If `account` had been granted `role`, emits a {RoleRevoked} event.
* @param role The role to revoke
* @param account The account to revoke the role from
*/
function revokeRole(bytes32 role, address account) public virtual override onlyRole(GOV_ROLE) {
_revokeRole(role, account);
}
}