From 0adbb24bee4e74b7f2ccb8326fafc09ac3040b30 Mon Sep 17 00:00:00 2001 From: Noah Citron Date: Sun, 31 Jul 2022 20:10:21 -0400 Subject: [PATCH 1/5] add broadcast function --- src/HuffConfig.sol | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/HuffConfig.sol b/src/HuffConfig.sol index aa995c1..d1e98b4 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 broadcast; + /// @notice constant overrides for the current compilation environment Constant[] public const_overrides; @@ -209,4 +212,9 @@ contract HuffConfig { /// @notice return the address that the contract was deployed to return deployedAddress; } + + function broadcast(string memory file) public payable returns (address) { + vm.broadcast(); + deploy(file); + } } From 04dac698b25360bf15a2efd085723dadf17f0e7d Mon Sep 17 00:00:00 2001 From: Noah Citron Date: Sun, 31 Jul 2022 20:58:59 -0400 Subject: [PATCH 2/5] better ergonomics for broadcasting --- src/HuffConfig.sol | 14 ++++++----- src/HuffDeployer.sol | 55 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 6 deletions(-) diff --git a/src/HuffConfig.sol b/src/HuffConfig.sol index d1e98b4..40b0fc3 100644 --- a/src/HuffConfig.sol +++ b/src/HuffConfig.sol @@ -26,7 +26,7 @@ contract HuffConfig { uint256 public value; /// @notice whether to broadcast the deployment tx - bool public broadcast; + bool public should_broadcast; /// @notice constant overrides for the current compilation environment Constant[] public const_overrides; @@ -87,6 +87,12 @@ contract HuffConfig { return this; } + /// @notice sets whether to broadcast the deployment + function set_broadcast(bool broadcast) public Returns (HuffConfig) { + should_broadcast = true; + return this; + } + /// @notice Checks for huffc binary conflicts function binary_check() public { string[] memory bincheck = new string[](1); @@ -199,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)) @@ -212,9 +219,4 @@ contract HuffConfig { /// @notice return the address that the contract was deployed to return deployedAddress; } - - function broadcast(string memory file) public payable returns (address) { - vm.broadcast(); - deploy(file); - } } diff --git a/src/HuffDeployer.sol b/src/HuffDeployer.sol index 769d7d7..cc291e9 100755 --- a/src/HuffDeployer.sol +++ b/src/HuffDeployer.sol @@ -5,9 +5,14 @@ import {Vm} from "forge-std/Vm.sol"; import {HuffConfig} from "./HuffConfig.sol"; library HuffDeployer { + + Vm constant vm = Vm(0x7109709ECfa91a80626fF3989D68f67F5b1DD12D); + /// @notice Create a new huff config function config() public returns (HuffConfig) { + vm.stopBroadcast(); return new HuffConfig(); + // vm.startBroadcast(); } /// @notice Compiles a Huff contract and returns the address that the contract was deployeod to @@ -17,6 +22,10 @@ library HuffDeployer { return config().deploy(fileName); } + 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 +37,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 +59,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 +81,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 +104,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); + } } From 7b91e93013483965540edff7c8186679a89926c3 Mon Sep 17 00:00:00 2001 From: Noah Citron Date: Sun, 31 Jul 2022 21:00:33 -0400 Subject: [PATCH 3/5] cleanup --- src/HuffConfig.sol | 2 +- src/HuffDeployer.sol | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/src/HuffConfig.sol b/src/HuffConfig.sol index 40b0fc3..b4d1169 100644 --- a/src/HuffConfig.sol +++ b/src/HuffConfig.sol @@ -88,7 +88,7 @@ contract HuffConfig { } /// @notice sets whether to broadcast the deployment - function set_broadcast(bool broadcast) public Returns (HuffConfig) { + function set_broadcast(bool broadcast) public returns (HuffConfig) { should_broadcast = true; return this; } diff --git a/src/HuffDeployer.sol b/src/HuffDeployer.sol index cc291e9..a7fa035 100755 --- a/src/HuffDeployer.sol +++ b/src/HuffDeployer.sol @@ -6,13 +6,9 @@ import {HuffConfig} from "./HuffConfig.sol"; library HuffDeployer { - Vm constant vm = Vm(0x7109709ECfa91a80626fF3989D68f67F5b1DD12D); - /// @notice Create a new huff config function config() public returns (HuffConfig) { - vm.stopBroadcast(); return new HuffConfig(); - // vm.startBroadcast(); } /// @notice Compiles a Huff contract and returns the address that the contract was deployeod to From 8f1a1e6508db4e5600415ffcbb44eedb88ca80e9 Mon Sep 17 00:00:00 2001 From: Noah Citron Date: Sun, 31 Jul 2022 21:04:02 -0400 Subject: [PATCH 4/5] fix set_broadcast --- src/HuffConfig.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/HuffConfig.sol b/src/HuffConfig.sol index b4d1169..13a85e9 100644 --- a/src/HuffConfig.sol +++ b/src/HuffConfig.sol @@ -89,7 +89,7 @@ contract HuffConfig { /// @notice sets whether to broadcast the deployment function set_broadcast(bool broadcast) public returns (HuffConfig) { - should_broadcast = true; + should_broadcast = broadcast; return this; } From 505af18cb58cd4fbaa4428feda16d8067a6065c4 Mon Sep 17 00:00:00 2001 From: Noah Citron Date: Wed, 3 Aug 2022 11:47:47 -0400 Subject: [PATCH 5/5] add tests and cleanup --- src/HuffDeployer.sol | 7 +++++-- src/test/HuffConfig.t.sol | 6 ++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/HuffDeployer.sol b/src/HuffDeployer.sol index a7fa035..a4eacb3 100755 --- a/src/HuffDeployer.sol +++ b/src/HuffDeployer.sol @@ -18,8 +18,11 @@ library HuffDeployer { return config().deploy(fileName); } - 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" + /// @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 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); + } }