|
| 1 | +// SPDX-License-Identifier: MIT |
| 2 | +pragma solidity ^0.8.13; |
| 3 | + |
| 4 | +import {StdConfig} from "./StdConfig.sol"; |
| 5 | +import {Variable} from "./LibVariable.sol"; |
| 6 | + |
| 7 | +/// @notice A view into a StdConfig instance bound to a specific chain ID. |
| 8 | +/// Provides ergonomic access to configuration variables without repeating the chain ID. |
| 9 | +struct ConfigView { |
| 10 | + StdConfig stdConfig; |
| 11 | + uint256 chainId; |
| 12 | +} |
| 13 | + |
| 14 | +/// @notice Library providing helper methods for ConfigView. |
| 15 | +/// All methods delegate to StdConfig, automatically passing the bound chainId. |
| 16 | +library LibConfigView { |
| 17 | + // -- GETTER --------------------------------------------------------------- |
| 18 | + |
| 19 | + /// @notice Reads a configuration variable for the bound chain ID. |
| 20 | + /// @param self The ConfigView instance. |
| 21 | + /// @param key The configuration variable key. |
| 22 | + /// @return Variable struct containing the type and ABI-encoded value. |
| 23 | + function get(ConfigView memory self, string memory key) internal view returns (Variable memory) { |
| 24 | + return self.stdConfig.get(self.chainId, key); |
| 25 | + } |
| 26 | + |
| 27 | + // -- SETTERS (SINGLE VALUES) ---------------------------------------------- |
| 28 | + |
| 29 | + /// @notice Sets a boolean configuration variable. |
| 30 | + function set(ConfigView memory self, string memory key, bool value) internal { |
| 31 | + self.stdConfig.set(self.chainId, key, value); |
| 32 | + } |
| 33 | + |
| 34 | + /// @notice Sets an address configuration variable. |
| 35 | + function set(ConfigView memory self, string memory key, address value) internal { |
| 36 | + self.stdConfig.set(self.chainId, key, value); |
| 37 | + } |
| 38 | + |
| 39 | + /// @notice Sets a bytes32 configuration variable. |
| 40 | + function set(ConfigView memory self, string memory key, bytes32 value) internal { |
| 41 | + self.stdConfig.set(self.chainId, key, value); |
| 42 | + } |
| 43 | + |
| 44 | + /// @notice Sets a uint256 configuration variable. |
| 45 | + function set(ConfigView memory self, string memory key, uint256 value) internal { |
| 46 | + self.stdConfig.set(self.chainId, key, value); |
| 47 | + } |
| 48 | + |
| 49 | + /// @notice Sets an int256 configuration variable. |
| 50 | + function set(ConfigView memory self, string memory key, int256 value) internal { |
| 51 | + self.stdConfig.set(self.chainId, key, value); |
| 52 | + } |
| 53 | + |
| 54 | + /// @notice Sets a string configuration variable. |
| 55 | + function set(ConfigView memory self, string memory key, string memory value) internal { |
| 56 | + self.stdConfig.set(self.chainId, key, value); |
| 57 | + } |
| 58 | + |
| 59 | + /// @notice Sets a bytes configuration variable. |
| 60 | + function set(ConfigView memory self, string memory key, bytes memory value) internal { |
| 61 | + self.stdConfig.set(self.chainId, key, value); |
| 62 | + } |
| 63 | + |
| 64 | + // -- SETTERS (ARRAYS) ----------------------------------------------------- |
| 65 | + |
| 66 | + /// @notice Sets a boolean array configuration variable. |
| 67 | + function set(ConfigView memory self, string memory key, bool[] memory value) internal { |
| 68 | + self.stdConfig.set(self.chainId, key, value); |
| 69 | + } |
| 70 | + |
| 71 | + /// @notice Sets an address array configuration variable. |
| 72 | + function set(ConfigView memory self, string memory key, address[] memory value) internal { |
| 73 | + self.stdConfig.set(self.chainId, key, value); |
| 74 | + } |
| 75 | + |
| 76 | + /// @notice Sets a bytes32 array configuration variable. |
| 77 | + function set(ConfigView memory self, string memory key, bytes32[] memory value) internal { |
| 78 | + self.stdConfig.set(self.chainId, key, value); |
| 79 | + } |
| 80 | + |
| 81 | + /// @notice Sets a uint256 array configuration variable. |
| 82 | + function set(ConfigView memory self, string memory key, uint256[] memory value) internal { |
| 83 | + self.stdConfig.set(self.chainId, key, value); |
| 84 | + } |
| 85 | + |
| 86 | + /// @notice Sets an int256 array configuration variable. |
| 87 | + function set(ConfigView memory self, string memory key, int256[] memory value) internal { |
| 88 | + self.stdConfig.set(self.chainId, key, value); |
| 89 | + } |
| 90 | + |
| 91 | + /// @notice Sets a string array configuration variable. |
| 92 | + function set(ConfigView memory self, string memory key, string[] memory value) internal { |
| 93 | + self.stdConfig.set(self.chainId, key, value); |
| 94 | + } |
| 95 | + |
| 96 | + /// @notice Sets a bytes array configuration variable. |
| 97 | + function set(ConfigView memory self, string memory key, bytes[] memory value) internal { |
| 98 | + self.stdConfig.set(self.chainId, key, value); |
| 99 | + } |
| 100 | +} |
0 commit comments