-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOracleWrapper.sol
52 lines (45 loc) · 1.48 KB
/
OracleWrapper.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
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
import "./interfaces/IBaseWrapper.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
contract OracelWrapper is Ownable {
struct Query {
IBaseWrapper module;
bytes queryData;
}
mapping(bytes => Query) public queries;
mapping(address => bool) public supportedModules;
event ModuleAdded(address indexed moduleAddress);
event QueryAdded(
address indexed moduleAddress,
bytes indexed queryIdentifier,
bytes indexed queryData
);
function getPrice(bytes calldata _queryId)
external
view
returns (
uint256,
uint256,
uint8
)
{
Query memory query = queries[_queryId];
return query.module.getPrice(query.queryData);
}
function addQuery(
bytes calldata _queryIdentifier,
bytes calldata _queryData,
address moduleAddress
) external onlyOwner {
require(supportedModules[moduleAddress], "Module address invalid");
Query memory query = Query(IBaseWrapper(moduleAddress), _queryData);
queries[_queryIdentifier] = query;
emit QueryAdded(moduleAddress, _queryIdentifier, _queryData);
}
function addModule(address moduleAddress) external onlyOwner {
require(moduleAddress != address(0), "Module address invalid");
supportedModules[moduleAddress] = true;
emit ModuleAdded(moduleAddress);
}
}