diff --git a/src/HuffConfig.sol b/src/HuffConfig.sol index aa995c1..13a85e9 100644 --- a/src/HuffConfig.sol +++ b/src/HuffConfig.sol @@ -25,6 +25,9 @@ contract HuffConfig { /// @notice value to deploy the contract with uint256 public value; + /// @notice whether to broadcast the deployment tx + bool public should_broadcast; + /// @notice constant overrides for the current compilation environment Constant[] public const_overrides; @@ -84,6 +87,12 @@ contract HuffConfig { return this; } + /// @notice sets whether to broadcast the deployment + function set_broadcast(bool broadcast) public returns (HuffConfig) { + should_broadcast = broadcast; + return this; + } + /// @notice Checks for huffc binary conflicts function binary_check() public { string[] memory bincheck = new string[](1); @@ -196,6 +205,7 @@ contract HuffConfig { /// @notice deploy the bytecode with the create instruction address deployedAddress; + if (should_broadcast) vm.broadcast(); assembly { let val := sload(value.slot) deployedAddress := create(val, add(concatenated, 0x20), mload(concatenated)) diff --git a/src/HuffDeployer.sol b/src/HuffDeployer.sol index 769d7d7..a4eacb3 100755 --- a/src/HuffDeployer.sol +++ b/src/HuffDeployer.sol @@ -5,6 +5,7 @@ import {Vm} from "forge-std/Vm.sol"; import {HuffConfig} from "./HuffConfig.sol"; library HuffDeployer { + /// @notice Create a new huff config function config() public returns (HuffConfig) { return new HuffConfig(); @@ -17,6 +18,13 @@ library HuffDeployer { return config().deploy(fileName); } + /// @notice Compiles a Huff contract and returns the address that the contract was deployeod to + /// @param fileName - The file name of the Huff contract. For example, the file name for "SimpleStore.huff" is "SimpleStore" + /// @return The address that the contract was deployed to + function broadcast(string memory fileName) internal returns (address) { + return config().set_broadcast(true).deploy(fileName); + } + /// @notice Compiles a Huff contract and returns the address that the contract was deployeod to /// @param fileName - The file name of the Huff contract. For example, the file name for "SimpleStore.huff" is "SimpleStore" /// @param value - Value to deploy with @@ -28,6 +36,17 @@ library HuffDeployer { return config().with_value(value).deploy(fileName); } + /// @notice Compiles a Huff contract and returns the address that the contract was deployeod to + /// @param fileName - The file name of the Huff contract. For example, the file name for "SimpleStore.huff" is "SimpleStore" + /// @param value - Value to deploy with + /// @return The address that the contract was deployed to + function broadcast_with_value( + string memory fileName, + uint256 value + ) internal returns (address) { + return config().set_broadcast(true).with_value(value).deploy(fileName); + } + /// @notice Compiles a Huff contract and returns the address that the contract was deployeod to /// @param fileName - The file name of the Huff contract. For example, the file name for "SimpleStore.huff" is "SimpleStore" /// @param args - Constructor Args to append to the bytecode @@ -39,6 +58,17 @@ library HuffDeployer { return config().with_args(args).deploy(fileName); } + /// @notice Compiles a Huff contract and returns the address that the contract was deployeod to + /// @param fileName - The file name of the Huff contract. For example, the file name for "SimpleStore.huff" is "SimpleStore" + /// @param args - Constructor Args to append to the bytecode + /// @return The address that the contract was deployed to + function broadcast_with_args( + string memory fileName, + bytes memory args + ) internal returns (address) { + return config().set_broadcast(true).with_args(args).deploy(fileName); + } + /// @notice Compiles a Huff contract and returns the address that the contract was deployeod to /// @param fileName - The file name of the Huff contract. For example, the file name for "SimpleStore.huff" is "SimpleStore" /// @param code - Code to append to the file source code (e.g. a constructor macro to make the contract instantiable) @@ -50,6 +80,17 @@ library HuffDeployer { return config().with_code(code).deploy(fileName); } + /// @notice Compiles a Huff contract and returns the address that the contract was deployeod to + /// @param fileName - The file name of the Huff contract. For example, the file name for "SimpleStore.huff" is "SimpleStore" + /// @param code - Code to append to the file source code (e.g. a constructor macro to make the contract instantiable) + /// @return The address that the contract was deployed to + function broadcast_with_code( + string memory fileName, + string memory code + ) internal returns (address) { + return config().set_broadcast(true).with_code(code).deploy(fileName); + } + /// @notice Compiles a Huff contract and returns the address that the contract was deployeod to /// @param fileName - The file name of the Huff contract. For example, the file name for "SimpleStore.huff" is "SimpleStore" /// @param code - Code to append to the file source code (e.g. a constructor macro to make the contract instantiable) @@ -62,4 +103,17 @@ library HuffDeployer { ) internal returns (address) { return config().with_code(code).with_args(args).deploy(fileName); } + + /// @notice Compiles a Huff contract and returns the address that the contract was deployeod to + /// @param fileName - The file name of the Huff contract. For example, the file name for "SimpleStore.huff" is "SimpleStore" + /// @param code - Code to append to the file source code (e.g. a constructor macro to make the contract instantiable) + /// @param args - Constructor Args to append to the bytecode + /// @return The address that the contract was deployed to + function broadcast_with_code_args( + string memory fileName, + string memory code, + bytes memory args + ) internal returns (address) { + return config().set_broadcast(true).with_code(code).with_args(args).deploy(fileName); + } } diff --git a/src/test/HuffConfig.t.sol b/src/test/HuffConfig.t.sol index 575883f..fbcaa2f 100644 --- a/src/test/HuffConfig.t.sol +++ b/src/test/HuffConfig.t.sol @@ -39,4 +39,10 @@ contract HuffConfigTest is Test { assertEq(key, k); assertEq(value, v); } + + function testSetBroadcast(bool broadcast) public { + config.set_broadcast(broadcast); + bool b = config.should_broadcast(); + assertEq(b, broadcast); + } }