-
Notifications
You must be signed in to change notification settings - Fork 513
Expand file tree
/
Copy pathLibConfigView.sol
More file actions
100 lines (80 loc) · 4.3 KB
/
Copy pathLibConfigView.sol
File metadata and controls
100 lines (80 loc) · 4.3 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
import {StdConfig} from "./StdConfig.sol";
import {Variable, LibVariable} from "./LibVariable.sol";
/// @notice A view into a StdConfig instance bound to a specific chain ID.
/// Provides ergonomic access to configuration variables without repeating the chain ID.
struct ConfigView {
StdConfig stdConfig;
uint256 chainId;
}
/// @notice Library providing helper methods for ConfigView.
/// All methods delegate to StdConfig, automatically passing the bound chainId.
library LibConfigView {
// -- GETTER ---------------------------------------------------------------
/// @notice Reads a configuration variable for the bound chain ID.
/// @param self The ConfigView instance.
/// @param key The configuration variable key.
/// @return Variable struct containing the type and ABI-encoded value.
function get(ConfigView memory self, string memory key) internal view returns (Variable memory) {
return self.stdConfig.get(self.chainId, key);
}
// -- SETTERS (SINGLE VALUES) ----------------------------------------------
/// @notice Sets a boolean configuration variable.
function set(ConfigView memory self, string memory key, bool value) internal {
self.stdConfig.set(self.chainId, key, LibVariable.from(value));
}
/// @notice Sets an address configuration variable.
function set(ConfigView memory self, string memory key, address value) internal {
self.stdConfig.set(self.chainId, key, LibVariable.from(value));
}
/// @notice Sets a bytes32 configuration variable.
function set(ConfigView memory self, string memory key, bytes32 value) internal {
self.stdConfig.set(self.chainId, key, LibVariable.from(value));
}
/// @notice Sets a uint256 configuration variable.
function set(ConfigView memory self, string memory key, uint256 value) internal {
self.stdConfig.set(self.chainId, key, LibVariable.from(value));
}
/// @notice Sets an int256 configuration variable.
function set(ConfigView memory self, string memory key, int256 value) internal {
self.stdConfig.set(self.chainId, key, LibVariable.from(value));
}
/// @notice Sets a string configuration variable.
function set(ConfigView memory self, string memory key, string memory value) internal {
self.stdConfig.set(self.chainId, key, LibVariable.from(value));
}
/// @notice Sets a bytes configuration variable.
function set(ConfigView memory self, string memory key, bytes memory value) internal {
self.stdConfig.set(self.chainId, key, LibVariable.from(value));
}
// -- SETTERS (ARRAYS) -----------------------------------------------------
/// @notice Sets a boolean array configuration variable.
function set(ConfigView memory self, string memory key, bool[] memory value) internal {
self.stdConfig.set(self.chainId, key, LibVariable.from(value));
}
/// @notice Sets an address array configuration variable.
function set(ConfigView memory self, string memory key, address[] memory value) internal {
self.stdConfig.set(self.chainId, key, LibVariable.from(value));
}
/// @notice Sets a bytes32 array configuration variable.
function set(ConfigView memory self, string memory key, bytes32[] memory value) internal {
self.stdConfig.set(self.chainId, key, LibVariable.from(value));
}
/// @notice Sets a uint256 array configuration variable.
function set(ConfigView memory self, string memory key, uint256[] memory value) internal {
self.stdConfig.set(self.chainId, key, LibVariable.from(value));
}
/// @notice Sets an int256 array configuration variable.
function set(ConfigView memory self, string memory key, int256[] memory value) internal {
self.stdConfig.set(self.chainId, key, LibVariable.from(value));
}
/// @notice Sets a string array configuration variable.
function set(ConfigView memory self, string memory key, string[] memory value) internal {
self.stdConfig.set(self.chainId, key, LibVariable.from(value));
}
/// @notice Sets a bytes array configuration variable.
function set(ConfigView memory self, string memory key, bytes[] memory value) internal {
self.stdConfig.set(self.chainId, key, LibVariable.from(value));
}
}