|
| 1 | +// SPDX-License-Identifier: MIT |
| 2 | +pragma solidity 0.8.24; |
| 3 | + |
| 4 | +import { Script } from "forge-std/Script.sol"; |
| 5 | + |
| 6 | +contract HelperConfig is Script { |
| 7 | + /*////////////////////////////////////////////////////////////// |
| 8 | + ERRORS |
| 9 | + //////////////////////////////////////////////////////////////*/ |
| 10 | + error HelperConfig__InvalidChainId(); |
| 11 | + |
| 12 | + /*////////////////////////////////////////////////////////////// |
| 13 | + TYPES |
| 14 | + //////////////////////////////////////////////////////////////*/ |
| 15 | + struct NetworkConfig { |
| 16 | + address someVar; |
| 17 | + } |
| 18 | + |
| 19 | + /*////////////////////////////////////////////////////////////// |
| 20 | + STATE VARIABLES |
| 21 | + //////////////////////////////////////////////////////////////*/ |
| 22 | + uint256 constant ETH_MAINNET_CHAIN_ID = 1; |
| 23 | + uint256 constant ETH_SEPOLIA_CHAIN_ID = 11_155_111; |
| 24 | + |
| 25 | + uint256 constant ZKSYNC_MAINNET_CHAIN_ID = 324; |
| 26 | + uint256 constant ZKSYNC_SEPOLIA_CHAIN_ID = 300; |
| 27 | + |
| 28 | + uint256 constant POLYGON_MAINNET_CHAIN_ID = 137; |
| 29 | + uint256 constant POLYGON_MUMBAI_CHAIN_ID = 80_001; |
| 30 | + |
| 31 | + // Local network state variables |
| 32 | + NetworkConfig public localNetworkConfig; |
| 33 | + mapping(uint256 chainId => NetworkConfig) public networkConfigs; |
| 34 | + |
| 35 | + /*////////////////////////////////////////////////////////////// |
| 36 | + FUNCTIONS |
| 37 | + //////////////////////////////////////////////////////////////*/ |
| 38 | + constructor() { |
| 39 | + networkConfigs[ETH_MAINNET_CHAIN_ID] = getEthMainnetConfig(); |
| 40 | + networkConfigs[ETH_SEPOLIA_CHAIN_ID] = getZkSyncSepoliaConfig(); |
| 41 | + networkConfigs[ZKSYNC_MAINNET_CHAIN_ID] = getZkSyncConfig(); |
| 42 | + networkConfigs[ZKSYNC_SEPOLIA_CHAIN_ID] = getZkSyncSepoliaConfig(); |
| 43 | + networkConfigs[POLYGON_MAINNET_CHAIN_ID] = getPolygonMainnetConfig(); |
| 44 | + networkConfigs[POLYGON_MUMBAI_CHAIN_ID] = getPolygonMumbaiConfig(); |
| 45 | + } |
| 46 | + |
| 47 | + function getConfigByChainId(uint256 chainId) public returns (NetworkConfig memory) { |
| 48 | + if (networkConfigs[chainId].someVar != address(0)) { |
| 49 | + return networkConfigs[chainId]; |
| 50 | + } else { |
| 51 | + return getOrCreateAnvilEthConfig(); |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + function getActiveNetworkConfig() public returns (NetworkConfig memory) { |
| 56 | + return getConfigByChainId(block.chainid); |
| 57 | + } |
| 58 | + |
| 59 | + /*////////////////////////////////////////////////////////////// |
| 60 | + CONFIGS |
| 61 | + //////////////////////////////////////////////////////////////*/ |
| 62 | + function getEthMainnetConfig() public pure returns (NetworkConfig memory) { |
| 63 | + return NetworkConfig({ someVar: address(1) }); |
| 64 | + } |
| 65 | + |
| 66 | + function getZkSyncConfig() public pure returns (NetworkConfig memory) { |
| 67 | + return NetworkConfig({ someVar: address(1) }); |
| 68 | + } |
| 69 | + |
| 70 | + function getZkSyncSepoliaConfig() public pure returns (NetworkConfig memory) { |
| 71 | + return NetworkConfig({ someVar: address(1) }); |
| 72 | + } |
| 73 | + |
| 74 | + function getPolygonMainnetConfig() public pure returns (NetworkConfig memory) { |
| 75 | + return NetworkConfig({ someVar: address(1) }); |
| 76 | + } |
| 77 | + |
| 78 | + function getPolygonMumbaiConfig() public pure returns (NetworkConfig memory) { |
| 79 | + return NetworkConfig({ someVar: address(1) }); |
| 80 | + } |
| 81 | + |
| 82 | + /*////////////////////////////////////////////////////////////// |
| 83 | + LOCAL CONFIG |
| 84 | + //////////////////////////////////////////////////////////////*/ |
| 85 | + function getOrCreateAnvilEthConfig() public returns (NetworkConfig memory) { |
| 86 | + if (localNetworkConfig.someVar != address(0)) { |
| 87 | + return localNetworkConfig; |
| 88 | + } |
| 89 | + |
| 90 | + _deployMocks(); |
| 91 | + |
| 92 | + localNetworkConfig = NetworkConfig({ someVar: address(1) }); |
| 93 | + return localNetworkConfig; |
| 94 | + } |
| 95 | + |
| 96 | + /* |
| 97 | + * Add your mocks, deploy and return them here for your local anvil network |
| 98 | + */ |
| 99 | + function _deployMocks() internal { } |
| 100 | +} |
0 commit comments