Skip to content

Commit ed64da7

Browse files
author
Ryan
committed
Updated scripts
1 parent a6ba704 commit ed64da7

3 files changed

Lines changed: 42 additions & 58 deletions

File tree

script/BaseScript.sol

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -23,83 +23,83 @@ abstract contract BaseScript is Script {
2323
}
2424

2525
function setUp() public virtual {
26-
uint256 privateKey = vm.envOr({
26+
broadcaster = vm.rememberKey(configurePrivateKey());
27+
}
28+
29+
function configurePrivateKey() internal view virtual returns (uint256 privateKey) {
30+
privateKey = vm.envOr({
2731
name: "PRIVATE_KEY",
2832
defaultValue: vm.deriveKey({
2933
mnemonic: vm.envOr({name: "MNEMONIC", defaultValue: DEFAULT_MNEMONIC}),
3034
index: uint8(vm.envOr({name: "EOA_INDEX", defaultValue: uint256(0)}))
3135
})
3236
});
33-
34-
broadcaster = vm.rememberKey(privateKey);
3537
}
3638

3739
function generateJson(string memory path, string memory name, address instance, bytes32 salt) internal {
3840
string memory json = "json";
3941
json.serialize("address", instance);
4042
json.serialize("blockNumber", vm.getBlockNumber());
4143
json.serialize("name", name);
42-
json.serialize("salt", vm.toString(salt));
44+
json.serialize("salt", salt);
4345
json = json.serialize("timestamp", vm.getBlockTimestamp());
4446
json.write(path);
4547
}
4648

49+
function prompt(string memory promptText) internal returns (string memory input) {
50+
return prompt(promptText, new string(0));
51+
}
52+
4753
function prompt(string memory promptText, string memory defaultValue) internal returns (string memory input) {
48-
input = _prompt(promptText, defaultValue);
54+
input = vm.prompt(string.concat(promptText, " (default: `", defaultValue, "`)"));
4955
if (bytes(input).length == 0) input = defaultValue;
5056
}
5157

5258
function promptAddress(string memory promptText, address defaultValue) internal returns (address) {
53-
string memory input = _prompt(promptText, vm.toString(defaultValue));
54-
if (bytes(input).length == 0) return defaultValue;
55-
return vm.parseAddress(input);
59+
return vm.parseAddress(prompt(promptText, vm.toString(defaultValue)));
5660
}
5761

5862
function promptAddress(string memory promptText) internal returns (address) {
5963
return promptAddress(promptText, address(0));
6064
}
6165

6266
function promptBool(string memory promptText, bool defaultValue) internal returns (bool) {
63-
string memory input = _prompt(promptText, vm.toString(defaultValue));
64-
if (bytes(input).length == 0) return defaultValue;
65-
return vm.parseBool(input);
67+
return vm.parseBool(prompt(promptText, vm.toString(defaultValue)));
6668
}
6769

6870
function promptBool(string memory promptText) internal returns (bool) {
6971
return promptBool(promptText, false);
7072
}
7173

72-
function promptBytes(string memory promptText, bytes memory defaultValue) internal returns (bytes memory) {
73-
string memory input = _prompt(promptText, vm.toString(defaultValue));
74-
if (bytes(input).length == 0) return defaultValue;
75-
return vm.parseBytes(input);
74+
function promptUint256(string memory promptText, uint256 defaultValue) internal returns (uint256) {
75+
return vm.parseUint(prompt(promptText, vm.toString(defaultValue)));
7676
}
7777

78-
function promptBytes(string memory promptText) internal returns (bytes memory) {
79-
return promptBytes(promptText, new bytes(0));
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));
8088
}
8189

8290
function promptBytes32(string memory promptText, bytes32 defaultValue) internal returns (bytes32) {
83-
string memory input = _prompt(promptText, vm.toString(defaultValue));
84-
if (bytes(input).length == 0) return defaultValue;
85-
return vm.parseBytes32(input);
91+
return vm.parseBytes32(prompt(promptText, vm.toString(defaultValue)));
8692
}
8793

8894
function promptBytes32(string memory promptText) internal returns (bytes32) {
8995
return promptBytes32(promptText, bytes32(0));
9096
}
9197

92-
function promptUint(string memory promptText, uint256 defaultValue) internal returns (uint256) {
93-
string memory input = _prompt(promptText, vm.toString(defaultValue));
94-
if (bytes(input).length == 0) return defaultValue;
95-
return vm.parseUint(input);
96-
}
97-
98-
function promptUint(string memory promptText) internal returns (uint256) {
99-
return promptUint(promptText, uint256(0));
98+
function promptBytes(string memory promptText, bytes memory defaultValue) internal returns (bytes memory) {
99+
return vm.parseBytes(prompt(promptText, vm.toString(defaultValue)));
100100
}
101101

102-
function _prompt(string memory promptText, string memory defaultValue) private returns (string memory input) {
103-
return vm.prompt(string.concat(promptText, " (default: '", defaultValue, "')"));
102+
function promptBytes(string memory promptText) internal returns (bytes memory) {
103+
return promptBytes(promptText, new bytes(0));
104104
}
105105
}

script/DeployProxy.s.sol

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// SPDX-License-Identifier: MIT
22
pragma solidity ^0.8.30;
33

4-
import {console2 as console} from "forge-std/console2.sol";
54
import {IProxyForge} from "src/interfaces/IProxyForge.sol";
65
import {BaseScript} from "./BaseScript.sol";
76

@@ -13,24 +12,17 @@ contract DeployProxy is BaseScript {
1312

1413
address implementation = vm.promptAddress("Implementation");
1514
address owner = promptAddress("Owner", broadcaster);
15+
1616
bool isDeterministic = promptBool("Is Deterministic");
17-
bytes32 salt = promptBytes32("Salt");
18-
bytes memory data = promptBytes("Data");
17+
bytes32 salt;
18+
if (isDeterministic) salt = promptBytes32("Salt");
1919

20-
console.log();
21-
console.log("======================================================================");
22-
console.log("Chain ID:", block.chainid);
20+
bytes memory data = promptBytes("Data");
21+
uint256 value;
22+
if (data.length != 0) value = promptUint256("msg.value");
2323

2424
proxy = isDeterministic
25-
? FORGE.deployDeterministicAndCall(implementation, owner, salt, data)
26-
: FORGE.deployAndCall(implementation, owner, data);
27-
28-
console.log("Proxy:", proxy);
29-
console.log("Implementation:", implementation);
30-
console.log("Owner:", owner);
31-
if (isDeterministic) console.log("Salt:", vm.toString(salt));
32-
console.log("Data:", vm.toString(data));
33-
console.log("======================================================================");
34-
console.log();
25+
? FORGE.deployDeterministicAndCall{value: value}(implementation, owner, salt, data)
26+
: FORGE.deployAndCall{value: value}(implementation, owner, data);
3527
}
3628
}

script/UpgradeProxy.s.sol

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// SPDX-License-Identifier: MIT
22
pragma solidity ^0.8.30;
33

4-
import {console2 as console} from "forge-std/console2.sol";
54
import {IProxyForge} from "src/interfaces/IProxyForge.sol";
65
import {BaseScript} from "./BaseScript.sol";
76

@@ -13,18 +12,11 @@ contract UpgradeProxy is BaseScript {
1312

1413
address proxy = vm.promptAddress("Proxy");
1514
address implementation = vm.promptAddress("Implementation");
16-
bytes memory data = promptBytes("Data");
17-
18-
console.log();
19-
console.log("======================================================================");
20-
console.log("Chain ID:", block.chainid);
2115

22-
FORGE.upgradeAndCall(proxy, implementation, data);
16+
bytes memory data = promptBytes("Data");
17+
uint256 value;
18+
if (data.length != 0) value = promptUint256("msg.value");
2319

24-
console.log("Proxy:", proxy);
25-
console.log("Implementation:", implementation);
26-
console.log("Data:", vm.toString(data));
27-
console.log("======================================================================");
28-
console.log();
20+
FORGE.upgradeAndCall{value: value}(proxy, implementation, data);
2921
}
3022
}

0 commit comments

Comments
 (0)