-
Notifications
You must be signed in to change notification settings - Fork 418
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
Merged
+2,075
−16
Merged
Changes from all commits
Commits
Show all changes
56 commits
Select commit
Hold shift + click to select a range
1982a2f
feat: config helper contract
0xrusowsky 03c82f0
feat: auto-load config
0xrusowsky bbd5f8d
add unit tests
0xrusowsky 7e67e9c
test all types
0xrusowsky df41ccf
test: write config
0xrusowsky cd346a6
update Vm docs
0xrusowsky 8128951
rename to `vm.activeChain()` to `vm.getChainId()`
0xrusowsky a1fe691
improve docs
0xrusowsky 405d958
more docs
0xrusowsky 158f4db
fix doc typo
0xrusowsky bad0161
update fn names to `get` and `set` for consistency
0xrusowsky a3c4e60
use backwards compatible solidity
0xrusowsky 2be7d97
fix: pragma
0xrusowsky 3dbe7d3
fix: use backwards compatible solidity
0xrusowsky f30626e
don't use `string.concat`
0xrusowsky 53a4cc5
add abidecoder v2
0xrusowsky 279f9e7
use pragma experimental ABIEncoderV2
0xrusowsky dc4315b
Merge branch 'master' into rusowsky/config-helper
0xrusowsky fae314f
fix: constructor visibility
0xrusowsky a97051f
Merge branch 'rusowsky/config-helper' of github.com:foundry-rs/forge-…
0xrusowsky b98e7a4
use initializer rather than constructor
0xrusowsky 4ad83e2
style: fmt
0xrusowsky 251258e
smarter storage layout
0xrusowsky 20047e2
don't use `string.concat`
0xrusowsky 07cdba7
run `vm.py`
0xrusowsky 6a53426
use constructor and disable warning
0xrusowsky c6aecac
better security and UX with `LibVariable` (#716)
0xrusowsky c4122e2
backwards-compatibility: drop custom errors + global 'using for' (#717)
0xrusowsky 61431b0
missing experimental abi
0xrusowsky 2a386d9
style: fmt + typos
0xrusowsky d3b49b4
more style
0xrusowsky 3c91387
ci: exclude `test/Config.t.sol` for stable
0xrusowsky 8a264ef
update Vm.t.sol with new hash
0xrusowsky a5d3fc0
Revert "backwards-compatibility: drop custom errors + global 'using f…
0xrusowsky 21f844d
CI: skip config-related contracts in old versions
0xrusowsky 3c23f73
ci: always skip test
0xrusowsky 1465e12
fix: ci
0xrusowsky 8fa3ec5
fix: typo
0xrusowsky e178cd0
set `writeToFile` on constructor
0xrusowsky 319ae20
downcast support for all uint types
0xrusowsky 3cf9c66
fix: mistakenly erased fn sig
0xrusowsky b6128a0
add integer support
0xrusowsky 8bd86d7
more tests
0xrusowsky a686262
style: fmt
0xrusowsky e764436
tests for fn `writeUpdatesBackToFile()`
0xrusowsky 8afa879
fix: rmv .env file
0xrusowsky 0f97a2f
fix: use `string.concat()` again
0xrusowsky a59383a
style: fmt
0xrusowsky 93c3d25
fix: more `string.concat()`
0xrusowsky b4ce8ee
chore: run `vm.py`
0xrusowsky c49c8ab
update solc ignored error codes
0xrusowsky 75ac3e3
fix: forbid writting to file unless scripting
0xrusowsky c086c2e
improve docs
0xrusowsky 9802415
Update StdConfig.sol
0xrusowsky 2788a6c
more docs
0xrusowsky 16d1087
Update src/StdConfig.sol
zerosnacks File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,16 @@ | ||
[profile.default] | ||
fs_permissions = [{ access = "read-write", path = "./"}] | ||
fs_permissions = [{ access = "read-write", path = "./" }] | ||
optimizer = true | ||
optimizer_runs = 200 | ||
|
||
# A list of solidity error codes to ignore. | ||
# 3860 = init-code-size | ||
ignored_error_codes = [3860] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for other reviewers - this already happens in master but not showing up as no |
||
|
||
[rpc_endpoints] | ||
# The RPC URLs are modified versions of the default for testing initialization. | ||
mainnet = "https://eth.merkle.io" # Different API key. | ||
optimism_sepolia = "https://sepolia.optimism.io/" # Adds a trailing slash. | ||
mainnet = "https://eth.merkle.io" # Different API key. | ||
optimism_sepolia = "https://sepolia.optimism.io/" # Adds a trailing slash. | ||
arbitrum_one_sepolia = "https://sepolia-rollup.arbitrum.io/rpc/" # Adds a trailing slash. | ||
needs_undefined_env_var = "${UNDEFINED_RPC_URL_PLACEHOLDER}" | ||
|
||
|
@@ -20,4 +24,4 @@ multiline_func_header = 'attributes_first' | |
quote_style = 'double' | ||
number_underscore = 'preserve' | ||
single_line_statement_blocks = 'preserve' | ||
ignore = ["src/console.sol", "src/console2.sol"] | ||
ignore = ["src/console.sol", "src/console2.sol"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.13; | ||
|
||
import {console} from "./console.sol"; | ||
import {StdConfig} from "./StdConfig.sol"; | ||
import {CommonBase} from "./Base.sol"; | ||
|
||
/// @notice Boilerplate to streamline the setup of multi-chain environments. | ||
abstract contract Config is CommonBase { | ||
// -- STORAGE (CONFIG + CHAINS + FORKS) ------------------------------------ | ||
|
||
/// @dev Contract instance holding the data from the TOML config file. | ||
StdConfig internal config; | ||
|
||
/// @dev Array of chain IDs for which forks have been created. | ||
uint256[] internal chainIds; | ||
|
||
/// @dev A mapping from a chain ID to its initialized fork ID. | ||
mapping(uint256 => uint256) internal forkOf; | ||
|
||
// -- HELPER FUNCTIONS ----------------------------------------------------- | ||
|
||
/// @notice Loads configuration from a file. | ||
/// | ||
/// @dev This function instantiates a `Config` contract, caching all its config variables. | ||
/// | ||
/// @param filePath: the path to the TOML configuration file. | ||
/// @param writeToFile: whether updates are written back to the TOML file. | ||
function _loadConfig(string memory filePath, bool writeToFile) internal { | ||
console.log("----------"); | ||
console.log(string.concat("Loading config from '", filePath, "'")); | ||
config = new StdConfig(filePath, writeToFile); | ||
vm.makePersistent(address(config)); | ||
console.log("Config successfully loaded"); | ||
console.log("----------"); | ||
} | ||
|
||
/// @notice Loads configuration from a file and creates forks for each specified chain. | ||
/// | ||
/// @dev This function instantiates a `Config` contract, caching all its config variables, | ||
/// reads the configured chain ids, and iterates through them to create a fork for each one. | ||
/// It also creates a map `forkOf[chainId] -> forkId` to easily switch between forks. | ||
/// | ||
/// @param filePath: the path to the TOML configuration file. | ||
/// @param writeToFile: whether updates are written back to the TOML file. | ||
function _loadConfigAndForks(string memory filePath, bool writeToFile) internal { | ||
_loadConfig(filePath, writeToFile); | ||
|
||
console.log("Setting up forks for the configured chains..."); | ||
uint256[] memory chains = config.getChainIds(); | ||
for (uint256 i = 0; i < chains.length; i++) { | ||
uint256 chainId = chains[i]; | ||
uint256 forkId = vm.createFork(config.getRpcUrl(chainId)); | ||
forkOf[chainId] = forkId; | ||
chainIds.push(chainId); | ||
} | ||
console.log("Forks successfully created"); | ||
console.log("----------"); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.