|
2 | 2 | pragma solidity ^0.8.30; |
3 | 3 |
|
4 | 4 | import {Script, stdJson} from "forge-std/Script.sol"; |
5 | | -import {ProxyForge} from "src/ProxyForge.sol"; |
6 | 5 |
|
7 | 6 | abstract contract BaseScript is Script { |
8 | | - using stdJson for string; |
9 | | - |
10 | | - string private constant DEFAULT_MNEMONIC = "test test test test test test test test test test test junk"; |
11 | | - |
12 | | - address internal broadcaster; |
13 | | - |
14 | | - modifier broadcast() { |
15 | | - vm.startBroadcast(broadcaster); |
16 | | - _; |
17 | | - vm.stopBroadcast(); |
18 | | - } |
19 | | - |
20 | | - modifier fork(string memory chainAlias) { |
21 | | - vm.createSelectFork(chainAlias); |
22 | | - _; |
23 | | - } |
24 | | - |
25 | | - function setUp() public virtual { |
26 | | - broadcaster = vm.rememberKey(configurePrivateKey()); |
27 | | - } |
28 | | - |
29 | | - function configurePrivateKey() internal view virtual returns (uint256 privateKey) { |
30 | | - privateKey = vm.envOr({ |
31 | | - name: "PRIVATE_KEY", |
32 | | - defaultValue: vm.deriveKey({ |
33 | | - mnemonic: vm.envOr({name: "MNEMONIC", defaultValue: DEFAULT_MNEMONIC}), |
34 | | - index: uint8(vm.envOr({name: "EOA_INDEX", defaultValue: uint256(0)})) |
35 | | - }) |
36 | | - }); |
37 | | - } |
38 | | - |
39 | | - function generateJson(string memory path, string memory name, address instance, bytes32 salt) internal { |
40 | | - string memory json = "json"; |
41 | | - json.serialize("address", instance); |
42 | | - json.serialize("blockNumber", vm.getBlockNumber()); |
43 | | - json.serialize("name", name); |
44 | | - json.serialize("salt", salt); |
45 | | - json = json.serialize("timestamp", vm.getBlockTimestamp()); |
46 | | - json.write(path); |
47 | | - } |
48 | | - |
49 | | - function prompt(string memory promptText) internal returns (string memory input) { |
50 | | - return prompt(promptText, new string(0)); |
51 | | - } |
52 | | - |
53 | | - function prompt(string memory promptText, string memory defaultValue) internal returns (string memory input) { |
54 | | - input = vm.prompt(string.concat(promptText, " (default: `", defaultValue, "`)")); |
55 | | - if (bytes(input).length == 0) input = defaultValue; |
56 | | - } |
57 | | - |
58 | | - function promptAddress(string memory promptText, address defaultValue) internal returns (address) { |
59 | | - return vm.parseAddress(prompt(promptText, vm.toString(defaultValue))); |
60 | | - } |
61 | | - |
62 | | - function promptAddress(string memory promptText) internal returns (address) { |
63 | | - return promptAddress(promptText, address(0)); |
64 | | - } |
65 | | - |
66 | | - function promptBool(string memory promptText, bool defaultValue) internal returns (bool) { |
67 | | - return vm.parseBool(prompt(promptText, vm.toString(defaultValue))); |
68 | | - } |
69 | | - |
70 | | - function promptBool(string memory promptText) internal returns (bool) { |
71 | | - return promptBool(promptText, false); |
72 | | - } |
73 | | - |
74 | | - function promptUint256(string memory promptText, uint256 defaultValue) internal returns (uint256) { |
75 | | - return vm.parseUint(prompt(promptText, vm.toString(defaultValue))); |
76 | | - } |
77 | | - |
78 | | - function promptUint256(string memory promptText) internal returns (uint256) { |
79 | | - return promptUint256(promptText, uint256(0)); |
80 | | - } |
81 | | - |
82 | | - function promptInt256(string memory promptText, int256 defaultValue) internal returns (int256) { |
83 | | - return vm.parseInt(prompt(promptText, vm.toString(defaultValue))); |
84 | | - } |
85 | | - |
86 | | - function promptInt256(string memory promptText) internal returns (int256) { |
87 | | - return promptInt256(promptText, int256(0)); |
88 | | - } |
89 | | - |
90 | | - function promptBytes32(string memory promptText, bytes32 defaultValue) internal returns (bytes32) { |
91 | | - return vm.parseBytes32(prompt(promptText, vm.toString(defaultValue))); |
92 | | - } |
93 | | - |
94 | | - function promptBytes32(string memory promptText) internal returns (bytes32) { |
95 | | - return promptBytes32(promptText, bytes32(0)); |
96 | | - } |
97 | | - |
98 | | - function promptBytes(string memory promptText, bytes memory defaultValue) internal returns (bytes memory) { |
99 | | - return vm.parseBytes(prompt(promptText, vm.toString(defaultValue))); |
100 | | - } |
101 | | - |
102 | | - function promptBytes(string memory promptText) internal returns (bytes memory) { |
103 | | - return promptBytes(promptText, new bytes(0)); |
104 | | - } |
| 7 | + using stdJson for string; |
| 8 | + |
| 9 | + string private constant DEFAULT_MNEMONIC = "test test test test test test test test test test test junk"; |
| 10 | + |
| 11 | + address internal broadcaster; |
| 12 | + |
| 13 | + modifier broadcast() { |
| 14 | + vm.startBroadcast(broadcaster); |
| 15 | + _; |
| 16 | + vm.stopBroadcast(); |
| 17 | + } |
| 18 | + |
| 19 | + modifier fork(string memory chainAlias) { |
| 20 | + vm.createSelectFork(chainAlias); |
| 21 | + _; |
| 22 | + } |
| 23 | + |
| 24 | + function setUp() public virtual { |
| 25 | + broadcaster = vm.rememberKey(configurePrivateKey()); |
| 26 | + } |
| 27 | + |
| 28 | + function configurePrivateKey() internal view virtual returns (uint256 privateKey) { |
| 29 | + privateKey = vm.envOr({ |
| 30 | + name: "PRIVATE_KEY", |
| 31 | + defaultValue: vm.deriveKey({ |
| 32 | + mnemonic: vm.envOr({name: "MNEMONIC", defaultValue: DEFAULT_MNEMONIC}), |
| 33 | + index: uint8(vm.envOr({name: "EOA_INDEX", defaultValue: uint256(0)})) |
| 34 | + }) |
| 35 | + }); |
| 36 | + } |
| 37 | + |
| 38 | + function generateJson(string memory path, string memory name, address instance, bytes32 salt) internal { |
| 39 | + string memory json = "json"; |
| 40 | + json.serialize("address", instance); |
| 41 | + json.serialize("blockNumber", vm.getBlockNumber()); |
| 42 | + json.serialize("name", name); |
| 43 | + json.serialize("salt", salt); |
| 44 | + json = json.serialize("timestamp", vm.getBlockTimestamp()); |
| 45 | + json.write(path); |
| 46 | + } |
| 47 | + |
| 48 | + function prompt(string memory promptText) internal returns (string memory input) { |
| 49 | + return prompt(promptText, new string(0)); |
| 50 | + } |
| 51 | + |
| 52 | + function prompt(string memory promptText, string memory defaultValue) internal returns (string memory input) { |
| 53 | + input = vm.prompt(string.concat(promptText, " (default: `", defaultValue, "`)")); |
| 54 | + if (bytes(input).length == 0) input = defaultValue; |
| 55 | + } |
| 56 | + |
| 57 | + function promptAddress(string memory promptText, address defaultValue) internal returns (address) { |
| 58 | + return vm.parseAddress(prompt(promptText, vm.toString(defaultValue))); |
| 59 | + } |
| 60 | + |
| 61 | + function promptAddress(string memory promptText) internal returns (address) { |
| 62 | + return promptAddress(promptText, address(0)); |
| 63 | + } |
| 64 | + |
| 65 | + function promptBool(string memory promptText, bool defaultValue) internal returns (bool) { |
| 66 | + return vm.parseBool(prompt(promptText, vm.toString(defaultValue))); |
| 67 | + } |
| 68 | + |
| 69 | + function promptBool(string memory promptText) internal returns (bool) { |
| 70 | + return promptBool(promptText, false); |
| 71 | + } |
| 72 | + |
| 73 | + function promptUint256(string memory promptText, uint256 defaultValue) internal returns (uint256) { |
| 74 | + return vm.parseUint(prompt(promptText, vm.toString(defaultValue))); |
| 75 | + } |
| 76 | + |
| 77 | + function promptUint256(string memory promptText) internal returns (uint256) { |
| 78 | + return promptUint256(promptText, uint256(0)); |
| 79 | + } |
| 80 | + |
| 81 | + function promptInt256(string memory promptText, int256 defaultValue) internal returns (int256) { |
| 82 | + return vm.parseInt(prompt(promptText, vm.toString(defaultValue))); |
| 83 | + } |
| 84 | + |
| 85 | + function promptInt256(string memory promptText) internal returns (int256) { |
| 86 | + return promptInt256(promptText, int256(0)); |
| 87 | + } |
| 88 | + |
| 89 | + function promptBytes32(string memory promptText, bytes32 defaultValue) internal returns (bytes32) { |
| 90 | + return vm.parseBytes32(prompt(promptText, vm.toString(defaultValue))); |
| 91 | + } |
| 92 | + |
| 93 | + function promptBytes32(string memory promptText) internal returns (bytes32) { |
| 94 | + return promptBytes32(promptText, bytes32(0)); |
| 95 | + } |
| 96 | + |
| 97 | + function promptBytes(string memory promptText, bytes memory defaultValue) internal returns (bytes memory) { |
| 98 | + return vm.parseBytes(prompt(promptText, vm.toString(defaultValue))); |
| 99 | + } |
| 100 | + |
| 101 | + function promptBytes(string memory promptText) internal returns (bytes memory) { |
| 102 | + return promptBytes(promptText, new bytes(0)); |
| 103 | + } |
105 | 104 | } |
0 commit comments