mirror of
https://github.com/vacp2p/foundry-template.git
synced 2025-02-17 09:46:30 +00:00
To allow deployment to different chains but using the same deployment scripts, this commit introduces a basic `DeploymentConfig` which can be extended as necessary in each project. There's a few things that should be considered: - `activeNetworkConfig` will be initialized via the constructor, at which point it is know what `block.chainid` is - To add new configuration settings, extend `NetworkConfig` - To add a new config for a different chain, extend the `if/else` block in the constructor so that it creates a `NetworkConfig` for the chain in question
40 lines
1.2 KiB
Solidity
40 lines
1.2 KiB
Solidity
//// SPDX-License-Identifier: UNLICENSED
|
|
|
|
pragma solidity >=0.8.19 <=0.9.0;
|
|
|
|
import { Script } from "forge-std/Script.sol";
|
|
|
|
contract DeploymentConfig is Script {
|
|
error DeploymentConfig_InvalidDeployerAddress();
|
|
error DeploymentConfig_NoConfigForChain(uint256);
|
|
|
|
struct NetworkConfig {
|
|
address deployer;
|
|
}
|
|
|
|
NetworkConfig public activeNetworkConfig;
|
|
|
|
address private deployer;
|
|
|
|
constructor(address _broadcaster) {
|
|
if (block.chainid == 31_337) {
|
|
activeNetworkConfig = getOrCreateAnvilEthConfig();
|
|
} else {
|
|
revert DeploymentConfig_NoConfigForChain(block.chainid);
|
|
}
|
|
if (_broadcaster == address(0)) revert DeploymentConfig_InvalidDeployerAddress();
|
|
deployer = _broadcaster;
|
|
}
|
|
|
|
function getOrCreateAnvilEthConfig() public view returns (NetworkConfig memory) {
|
|
return NetworkConfig({ deployer: deployer });
|
|
}
|
|
|
|
// This function is a hack to have it excluded by `forge coverage` until
|
|
// https://github.com/foundry-rs/foundry/issues/2988 is fixed.
|
|
// See: https://github.com/foundry-rs/foundry/issues/2988#issuecomment-1437784542
|
|
// for more info.
|
|
// solhint-disable-next-line
|
|
function test() public { }
|
|
}
|