Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
- run: |
case "${{ matrix.flags }}" in
*"solc:0.8.0"* | *"solc:0.7"* | *"solc:0.6"*)
forge build --skip test --skip Config --skip StdConfig --skip LibVariable --deny-warnings ${{ matrix.flags }}
forge build --skip test --skip Config --skip StdConfig --skip LibVariable --skip MockCounter --deny-warnings ${{ matrix.flags }}
;;
*)
forge build --skip test --deny-warnings ${{ matrix.flags }}
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
cache/
out/
out-cancun/
out-shanghai/
.vscode
.idea
16 changes: 16 additions & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,22 @@ optimizer_runs = 200
# 3860 = init-code-size
ignored_error_codes = [3860]

[profile.shanghai]
fs_permissions = [{ access = "read-write", path = "./" }]
optimizer = true
optimizer_runs = 200
evm_version = "shanghai"
out = "out-shanghai"
ignored_error_codes = [3860]

[profile.cancun]
fs_permissions = [{ access = "read-write", path = "./" }]
optimizer = true
optimizer_runs = 200
evm_version = "cancun"
out = "out-cancun"
ignored_error_codes = [3860]

[rpc_endpoints]
# The RPC URLs are modified versions of the default for testing initialization.
mainnet = "https://reth-ethereum.ithaca.xyz/rpc"
Expand Down
410 changes: 393 additions & 17 deletions src/Config.sol

Large diffs are not rendered by default.

100 changes: 100 additions & 0 deletions src/LibConfigView.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,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));
}
}
74 changes: 74 additions & 0 deletions src/LibVariable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -474,4 +474,78 @@ library LibVariable {
{
return abi.decode(self.data, (bytes[]));
}

// -- FACTORY FUNCTIONS (SINGLE VALUES) ------------------------------------

/// @notice Creates a `Variable` from a `bool` value.
function from(bool value) internal pure returns (Variable memory) {
return Variable(Type(TypeKind.Bool, false), abi.encode(value));
}

/// @notice Creates a `Variable` from an `address` value.
function from(address value) internal pure returns (Variable memory) {
return Variable(Type(TypeKind.Address, false), abi.encode(value));
}

/// @notice Creates a `Variable` from a `bytes32` value.
function from(bytes32 value) internal pure returns (Variable memory) {
return Variable(Type(TypeKind.Bytes32, false), abi.encode(value));
}

/// @notice Creates a `Variable` from a `uint256` value.
function from(uint256 value) internal pure returns (Variable memory) {
return Variable(Type(TypeKind.Uint256, false), abi.encode(value));
}

/// @notice Creates a `Variable` from an `int256` value.
function from(int256 value) internal pure returns (Variable memory) {
return Variable(Type(TypeKind.Int256, false), abi.encode(value));
}

/// @notice Creates a `Variable` from a `string` value.
function from(string memory value) internal pure returns (Variable memory) {
return Variable(Type(TypeKind.String, false), abi.encode(value));
}

/// @notice Creates a `Variable` from a `bytes` value.
function from(bytes memory value) internal pure returns (Variable memory) {
return Variable(Type(TypeKind.Bytes, false), abi.encode(value));
}

// -- FACTORY FUNCTIONS (ARRAYS) -------------------------------------------

/// @notice Creates a `Variable` from a `bool` array.
function from(bool[] memory value) internal pure returns (Variable memory) {
return Variable(Type(TypeKind.Bool, true), abi.encode(value));
}

/// @notice Creates a `Variable` from an `address` array.
function from(address[] memory value) internal pure returns (Variable memory) {
return Variable(Type(TypeKind.Address, true), abi.encode(value));
}

/// @notice Creates a `Variable` from a `bytes32` array.
function from(bytes32[] memory value) internal pure returns (Variable memory) {
return Variable(Type(TypeKind.Bytes32, true), abi.encode(value));
}

/// @notice Creates a `Variable` from a `uint256` array.
function from(uint256[] memory value) internal pure returns (Variable memory) {
return Variable(Type(TypeKind.Uint256, true), abi.encode(value));
}

/// @notice Creates a `Variable` from an `int256` array.
function from(int256[] memory value) internal pure returns (Variable memory) {
return Variable(Type(TypeKind.Int256, true), abi.encode(value));
}

/// @notice Creates a `Variable` from a `string` array.
function from(string[] memory value) internal pure returns (Variable memory) {
return Variable(Type(TypeKind.String, true), abi.encode(value));
}

/// @notice Creates a `Variable` from a `bytes` array.
function from(bytes[] memory value) internal pure returns (Variable memory) {
return Variable(Type(TypeKind.Bytes, true), abi.encode(value));
}
}
Loading
Loading