Skip to content

Commit 7b5abbc

Browse files
committed
refactor: rename deployer to broadcaster
feat: use $ETH_FROM as broadcaster
1 parent 878032e commit 7b5abbc

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

script/Base.s.sol

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: MIT
2-
pragma solidity >=0.8.19 <0.9.0;
2+
pragma solidity >=0.8.19 <=0.9.0;
33

44
import { Script } from "forge-std/Script.sol";
55

@@ -10,19 +10,31 @@ abstract contract BaseScript is Script {
1010
/// @dev Needed for the deterministic deployments.
1111
bytes32 internal constant ZERO_SALT = bytes32(0);
1212

13-
/// @dev The address of the contract deployer.
14-
address internal deployer;
13+
/// @dev The address of the transaction broadcaster.
14+
address internal broadcaster;
1515

16-
/// @dev Used to derive the deployer's address.
16+
/// @dev Used to derive the broadcaster's address if $ETH_FROM is not defined.
1717
string internal mnemonic;
1818

19+
/// @dev Initializes the transaction broadcaster like this:
20+
///
21+
/// - If $ETH_FROM is defined, use it.
22+
/// - Otherwise, derive the broadcaster address from $MNEMONIC.
23+
/// - If $MNEMONIC is not defined, default to a test mnemonic.
24+
///
25+
/// The use case for $ETH_FROM is to specify the broadcaster key and its address via the command line.
1926
constructor() {
20-
mnemonic = vm.envOr("MNEMONIC", TEST_MNEMONIC);
21-
(deployer,) = deriveRememberKey({ mnemonic: mnemonic, index: 0 });
27+
address from = vm.envOr({ name: "ETH_FROM", defaultValue: address(0) });
28+
if (from != address(0)) {
29+
broadcaster = from;
30+
} else {
31+
mnemonic = vm.envOr({ name: "MNEMONIC", defaultValue: TEST_MNEMONIC });
32+
(broadcaster,) = deriveRememberKey({ mnemonic: mnemonic, index: 0 });
33+
}
2234
}
2335

24-
modifier broadcaster() {
25-
vm.startBroadcast(deployer);
36+
modifier broadcast() {
37+
vm.startBroadcast(broadcaster);
2638
_;
2739
vm.stopBroadcast();
2840
}

script/DeployTestToken.s.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { BaseScript } from "./Base.s.sol";
99

1010
/// @notice Deploys a test ERC-20 token with infinite minting and burning capabilities.
1111
contract DeployTestToken is Script, BaseScript {
12-
function run() public virtual broadcaster returns (ERC20GodMode token) {
12+
function run() public virtual broadcast returns (ERC20GodMode token) {
1313
token = new ERC20GodMode("Test token", "TKN", 18);
1414
}
1515
}

0 commit comments

Comments
 (0)