Skip to content

Commit

Permalink
refactor: rename deployer to broadcaster
Browse files Browse the repository at this point in the history
feat: use $ETH_FROM as broadcaster
  • Loading branch information
PaulRBerg committed Jul 3, 2023
1 parent 878032e commit 6236021
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
30 changes: 21 additions & 9 deletions script/Base.s.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19 <0.9.0;
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity >=0.8.19 <=0.9.0;

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

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

/// @dev The address of the contract deployer.
address internal deployer;
/// @dev The address of the broadcaster.
address internal broadcaster;

/// @dev Used to derive the deployer's address.
/// @dev Used to derive the broadcaster's address.
string internal mnemonic;

/// @dev Initializes the broadcaster's address using the following logic:
///
/// - If $ETH_FROM is defined, use it.
/// - Otherwise, derive the broadcaster address from $MNEMONIC.
/// - If $MNEMONIC is not defined, default to a test mnemonic.
///
/// The use case for $ETH_FROM is to specify the broadcaster key and its address via the command line.
constructor() {
mnemonic = vm.envOr("MNEMONIC", TEST_MNEMONIC);
(deployer,) = deriveRememberKey({ mnemonic: mnemonic, index: 0 });
address from = vm.envOr({ name: "ETH_FROM", defaultValue: address(0) });
if (from != address(0)) {
broadcaster = from;
} else {
mnemonic = vm.envOr({ name: "MNEMONIC", defaultValue: TEST_MNEMONIC });
(broadcaster,) = deriveRememberKey({ mnemonic: mnemonic, index: 0 });
}
}

modifier broadcaster() {
vm.startBroadcast(deployer);
modifier broadcast() {
vm.startBroadcast(broadcaster);
_;
vm.stopBroadcast();
}
Expand Down
2 changes: 1 addition & 1 deletion script/DeployTestToken.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { BaseScript } from "./Base.s.sol";

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

0 comments on commit 6236021

Please sign in to comment.