-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathConfiguration.sol
More file actions
91 lines (73 loc) · 2.91 KB
/
Copy pathConfiguration.sol
File metadata and controls
91 lines (73 loc) · 2.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// SPDX-License-Identifier: UNLICENSED
pragma solidity =0.8.24;
import {Script} from "forge-std/Script.sol";
import {VmSafe} from "forge-std/Vm.sol";
import {stdToml} from "forge-std/StdToml.sol";
abstract contract Configuration is Script {
using stdToml for string;
/*******************
* State variables *
*******************/
string internal cfg;
string internal contractsCfg;
string internal contractsCfgPath;
/**********************
* Internal interface *
**********************/
function initialize(string memory workdir) internal {
string memory cfgPath = string(abi.encodePacked(workdir, "/config.toml"));
cfg = vm.readFile(cfgPath);
contractsCfgPath = string(abi.encodePacked(workdir, "/config-contracts.toml"));
contractsCfg = vm.readFile(contractsCfgPath);
}
function readUint(string memory key) internal view returns (uint256) {
return cfg.readUint(key);
}
function readAddress(string memory key) internal view returns (address) {
return cfg.readAddress(key);
}
function readString(string memory key) internal view returns (string memory) {
return cfg.readString(key);
}
function writeContract(address addr, string memory tomlPath) internal {
vm.writeToml(vm.toString(addr), contractsCfgPath, tomlPath);
}
/// @dev Ensure that `addr` is not the zero address.
/// This helps catch bugs arising from incorrect deployment order.
function notnull(address addr) internal pure returns (address) {
require(addr != address(0), "null address");
return addr;
}
function tryGetOverride(string memory name) internal returns (address) {
address addr;
string memory key;
if (keccak256(abi.encodePacked(name)) == keccak256(abi.encodePacked("L1_GAS_TOKEN"))) {
key = string(abi.encodePacked(".gas-token.", name));
} else {
key = string(abi.encodePacked(".contracts.overrides.", name));
}
if (!vm.keyExistsToml(cfg, key)) {
return address(0);
}
addr = cfg.readAddress(key);
if (addr.code.length == 0) {
(VmSafe.CallerMode callerMode, , ) = vm.readCallers();
// if we're ready to start broadcasting transactions, then we
// must ensure that the override contract has been deployed.
if (callerMode == VmSafe.CallerMode.Broadcast || callerMode == VmSafe.CallerMode.RecurrentBroadcast) {
revert(
string(
abi.encodePacked(
"[ERROR] override ",
name,
" = ",
vm.toString(addr),
" not deployed in broadcast mode"
)
)
);
}
}
return addr;
}
}