Base.s.sol
1 // SPDX-License-Identifier: UNLICENSED 2 pragma solidity >=0.8.17 <=0.9.0; 3 4 import { Script } from "forge-std/Script.sol"; 5 6 abstract contract BaseScript is Script { 7 /// @dev Included to enable compilation of the script without a $MNEMONIC environment variable. 8 string internal constant TEST_MNEMONIC = "test test test test test test test test test test test junk"; 9 10 /// @dev The address of the transaction broadcaster. 11 address internal broadcaster; 12 13 /// @dev Used to derive the broadcaster's address if $ETH_FROM is not defined. 14 string internal mnemonic; 15 16 /// @dev Initializes the transaction broadcaster like this: 17 /// 18 /// - If $ETH_FROM is defined, use it. 19 /// - Otherwise, derive the broadcaster address from $MNEMONIC. 20 /// - If $MNEMONIC is not defined, default to a test mnemonic. 21 /// 22 /// The use case for $ETH_FROM is to specify the broadcaster key and its address via the command line. 23 constructor() { 24 address from = vm.envOr({ name: "ETH_FROM", defaultValue: address(0) }); 25 if (from != address(0)) { 26 broadcaster = from; 27 } else { 28 mnemonic = vm.envOr({ name: "MNEMONIC", defaultValue: TEST_MNEMONIC }); 29 (broadcaster,) = deriveRememberKey({ mnemonic: mnemonic, index: 0 }); 30 } 31 } 32 33 modifier broadcast() { 34 vm.startBroadcast(broadcaster); 35 _; 36 vm.stopBroadcast(); 37 } 38 }