-
Notifications
You must be signed in to change notification settings - Fork 411
feat: config helper contract #715
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
src/Base.sol
Outdated
console.log("----------"); | ||
console.log(string.concat("Loading config from '", filePath, "'")); | ||
config = new StdConfig(filePath); | ||
vm.makePersistent(address(config)); | ||
console.log("Config successfully loaded"); | ||
console.log("----------"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since the StdConfig
constructor impl uses try catch blocks and there may be several errors in the traces, i thought it would be useful to add some logs to easily identify the config loading block
…std into rusowsky/config-helper
Will this only allow for setting the rpc:
or will it be possible to also configure |
i only thought of a let me look into it and assess the feasibility of the impl with the rest of the team. I will definitely try to add support for it if possible, thanks for the suggestion. |
@sakulstra are solc setting relevant to you even if the cheatcode is not available yet? if so, i could add them, but otherwise i'd wait until the requested cheatcode is supported |
@0xrusowsky For us this has been a major issue since forever yes - not so much related to this cheatcode. Our main usecase is to calculate create2 addresses on the different chains within a single script and that's currently simply impossible if one chain requires |
@0xrusowsky just in case that was not clear - for us is no issue to w8 a few weeks or sth. No need to decouple this if it means additional work. As this problem exists for a while now, we've built lot's of workarounds which work okayish for the most part. |
@sakulstra yes, that's clear. good that we have the issue linked now |
This PR introduces a new contract,
StdConfig
, which encapsulates all the logic to read and write from a user-defined.toml
config file that sticks to a predetermined structure (access permissions must be granted viafoundry.toml
as usual).It also introduces a new abstract contract,
Config
, which can be inherited together withTest
andScript
. Users can then tap into the new features thatConfig
andStdConfig
enable to streamline the setup of multi-chain environments.Features
Comprehensive + Easily Programmable Config File
The TOML structure must have top-level keys representing the target chains. Under each chain key, variables are organized by type in separate sub-tables like
[<chain>.<type>]
.uint
or a valid alloy-chain alias.bool
,address
,uint
,bytes32
,string
, orbytes
.Ease dev burden when dealing with Multi-Chain Setups
The new
Config
abstract contract introduces a minimal set of storage variables that expose the user config:These variables are populated with a single function that users can call when setting up their tests or scripts:
Intuitive and type-safe API with
StdConfig
andLibVariable
StdConfig
reads, resolves, and parses all variables when initialized, caching them in storage.StdConfig
exposes a genericget
method that returns aVariable
struct. This struct holds the raw data and its type information.LibVariable
library is used to safely cast theVariable
struct to a concrete Solidity type. This ensures type safety at runtime, reverting with a clear error if a variable is missing or cast incorrectly.StdConfig
supports bidirectional (read + write capabilities) configuration management:writeToFile
parameter enables automatic persistence of changes.function writeUpdatesBackToFile(bool)
to toggle write behavior at runtime.Usage example