Skip to content
This repository has been archived by the owner on Sep 9, 2024. It is now read-only.

feat: add broadcast functions #22

Merged
merged 5 commits into from
Aug 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/HuffConfig.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -84,6 +87,12 @@ contract HuffConfig {
return this;
}

/// @notice sets whether to broadcast the deployment
function set_broadcast(bool broadcast) public returns (HuffConfig) {
ncitron marked this conversation as resolved.
Show resolved Hide resolved
should_broadcast = broadcast;
return this;
}

/// @notice Checks for huffc binary conflicts
function binary_check() public {
string[] memory bincheck = new string[](1);
Expand Down Expand Up @@ -196,6 +205,7 @@ contract HuffConfig {

/// @notice deploy the bytecode with the create instruction
address deployedAddress;
if (should_broadcast) vm.broadcast();
clabby marked this conversation as resolved.
Show resolved Hide resolved
assembly {
let val := sload(value.slot)
deployedAddress := create(val, add(concatenated, 0x20), mload(concatenated))
Expand Down
54 changes: 54 additions & 0 deletions src/HuffDeployer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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);
}
}
6 changes: 6 additions & 0 deletions src/test/HuffConfig.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}