refactor: rename deployer to broadcaster

feat: use $ETH_FROM as broadcaster
This commit is contained in:
Paul Razvan Berg 2023-07-03 12:42:23 +03:00
parent 8209998bd7
commit 1baddd764a
No known key found for this signature in database
GPG Key ID: 94DB130BAB397DED
2 changed files with 22 additions and 10 deletions

View File

@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
pragma solidity >=0.8.19 <=0.9.0;
import { Script } from "forge-std/Script.sol";
@ -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 transaction broadcaster.
address internal broadcaster;
/// @dev Used to derive the deployer's address.
/// @dev Used to derive the broadcaster's address if $ETH_FROM is not defined.
string internal mnemonic;
/// @dev Initializes the transaction broadcaster like this:
///
/// - 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();
}

View File

@ -1,5 +1,5 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.19;
pragma solidity >=0.8.19 <=0.9.0;
import { Foo } from "../src/Foo.sol";
@ -7,7 +7,7 @@ import { BaseScript } from "./Base.s.sol";
/// @dev See the Solidity Scripting tutorial: https://book.getfoundry.sh/tutorials/solidity-scripting
contract Deploy is BaseScript {
function run() public broadcaster returns (Foo foo) {
function run() public broadcast returns (Foo foo) {
foo = new Foo();
}
}