/
OracleDaemonConfig.sol
85 lines (61 loc) · 2.68 KB
/
OracleDaemonConfig.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// SPDX-FileCopyrightText: 2023 Lido <info@lido.fi>
// SPDX-License-Identifier: GPL-3.0
/* See contracts/COMPILERS.md */
pragma solidity 0.8.9;
import {AccessControlEnumerable} from "./utils/access/AccessControlEnumerable.sol";
contract OracleDaemonConfig is AccessControlEnumerable {
bytes32 public constant CONFIG_MANAGER_ROLE = keccak256("CONFIG_MANAGER_ROLE");
mapping(string => bytes) private values;
constructor(address _admin, address[] memory _configManagers) {
if (_admin == address(0)) revert ZeroAddress();
_grantRole(DEFAULT_ADMIN_ROLE, _admin);
for (uint256 i = 0; i < _configManagers.length; ) {
if (_configManagers[i] == address(0)) revert ZeroAddress();
_grantRole(CONFIG_MANAGER_ROLE, _configManagers[i]);
unchecked {
++i;
}
}
}
function set(string calldata _key, bytes calldata _value) external onlyRole(CONFIG_MANAGER_ROLE) {
if (values[_key].length > 0) revert ValueExists(_key);
if (_value.length == 0) revert EmptyValue(_key);
values[_key] = _value;
emit ConfigValueSet(_key, _value);
}
function update(string calldata _key, bytes calldata _value) external onlyRole(CONFIG_MANAGER_ROLE) {
if (values[_key].length == 0) revert ValueDoesntExist(_key);
if (_value.length == 0) revert EmptyValue(_key);
if (keccak256(values[_key]) == keccak256(_value)) revert ValueIsSame(_key, _value);
values[_key] = _value;
emit ConfigValueUpdated(_key, _value);
}
function unset(string calldata _key) external onlyRole(CONFIG_MANAGER_ROLE) {
if (values[_key].length == 0) revert ValueDoesntExist(_key);
delete values[_key];
emit ConfigValueUnset(_key);
}
function get(string calldata _key) external view returns (bytes memory) {
if (values[_key].length == 0) revert ValueDoesntExist(_key);
return values[_key];
}
function getList(string[] calldata _keys) external view returns (bytes[] memory) {
bytes[] memory results = new bytes[](_keys.length);
for (uint256 i = 0; i < _keys.length; ) {
if (values[_keys[i]].length == 0) revert ValueDoesntExist(_keys[i]);
results[i] = values[_keys[i]];
unchecked {
++i;
}
}
return results;
}
error ValueExists(string key);
error EmptyValue(string key);
error ValueDoesntExist(string key);
error ZeroAddress();
error ValueIsSame(string key, bytes value);
event ConfigValueSet(string key, bytes value);
event ConfigValueUpdated(string key, bytes value);
event ConfigValueUnset(string key);
}