2023-04-29 10:11:35 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2023-07-03 09:42:23 +00:00
|
|
|
pragma solidity >=0.8.19 <=0.9.0;
|
2023-04-29 10:11:35 +00:00
|
|
|
|
|
|
|
import { Script } from "forge-std/Script.sol";
|
|
|
|
|
|
|
|
abstract contract BaseScript is Script {
|
|
|
|
/// @dev Included to enable compilation of the script without a $MNEMONIC environment variable.
|
|
|
|
string internal constant TEST_MNEMONIC = "test test test test test test test test test test test junk";
|
|
|
|
|
|
|
|
/// @dev Needed for the deterministic deployments.
|
|
|
|
bytes32 internal constant ZERO_SALT = bytes32(0);
|
|
|
|
|
2023-07-03 09:42:23 +00:00
|
|
|
/// @dev The address of the transaction broadcaster.
|
|
|
|
address internal broadcaster;
|
2023-04-29 10:11:35 +00:00
|
|
|
|
2023-07-03 09:42:23 +00:00
|
|
|
/// @dev Used to derive the broadcaster's address if $ETH_FROM is not defined.
|
2023-04-29 10:11:35 +00:00
|
|
|
string internal mnemonic;
|
|
|
|
|
2023-07-03 09:42:23 +00:00
|
|
|
/// @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.
|
2023-04-29 10:11:35 +00:00
|
|
|
constructor() {
|
2023-07-03 09:42:23 +00:00
|
|
|
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 });
|
|
|
|
}
|
2023-04-29 10:11:35 +00:00
|
|
|
}
|
|
|
|
|
2023-07-03 09:42:23 +00:00
|
|
|
modifier broadcast() {
|
|
|
|
vm.startBroadcast(broadcaster);
|
2023-04-29 10:11:35 +00:00
|
|
|
_;
|
|
|
|
vm.stopBroadcast();
|
|
|
|
}
|
|
|
|
}
|