-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
97 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
|
||
pragma solidity >=0.8.7 <0.9.0; | ||
|
||
///@notice This cheat codes interface is named _CheatCodes so you can use the CheatCodes interface in other testing files without errors | ||
interface _CheatCodes { | ||
function ffi(string[] calldata) external returns (bytes memory); | ||
} | ||
|
||
contract PuffDeployer { | ||
|
||
address constant HEVM_ADDRESS = address(bytes20(uint160(uint256(keccak256("hevm cheat code"))))); | ||
|
||
/// @notice Initializes cheat codes in order to use ffi to compile Vyper contracts | ||
_CheatCodes cheatCodes = _CheatCodes(HEVM_ADDRESS); | ||
|
||
///@notice Compiles a Huff contract and returns the address that the contract was deployeod to | ||
///@notice If deployment fails, an error will be thrown | ||
///@param fileName - The file name of the Huff contract. | ||
///@return deployedAddress - The address that the contract was deployed to | ||
|
||
function deployContract(string memory fileName) public returns (address) { | ||
///@notice create a list of strings with the commands necessary to compile Vyper contracts | ||
string[] memory cmds = new string[](3); | ||
cmds[0] = "puffc"; | ||
cmds[1] = "-b"; | ||
cmds[2] = fileName; | ||
|
||
///@notice compile the Huff contract and return the bytecode | ||
bytes memory bytecode = cheatCodes.ffi(cmds); | ||
|
||
///@notice deploy the bytecode with the create instruction | ||
address deployedAddress; | ||
assembly { | ||
deployedAddress := create(0, add(bytecode, 0x20), mload(bytecode)) | ||
} | ||
|
||
///@notice check that the deployment was successful | ||
require( | ||
deployedAddress != address(0), | ||
"PuffDeployer could not deploy contract" | ||
); | ||
|
||
///@notice return the address that the contract was deployed to | ||
return deployedAddress; | ||
} | ||
|
||
} | ||
|
||
|
||
contract HuffDeployer { | ||
|
||
address constant HEVM_ADDRESS = address(bytes20(uint160(uint256(keccak256("hevm cheat code"))))); | ||
|
||
/// @notice Initializes cheat codes in order to use ffi to compile Vyper contracts | ||
_CheatCodes cheatCodes = _CheatCodes(HEVM_ADDRESS); | ||
|
||
///@notice Compiles a Huff contract and returns the address that the contract was deployeod to | ||
///@notice If deployment fails, an error will be thrown | ||
///@param fileName - The file name of the Vyper contract. For example, the file name for "SimpleStore.vy" is "SimpleStore" | ||
///@return deployedAddress - The address that the contract was deployed to | ||
|
||
function deployContract(string memory fileName) public returns (address) { | ||
///@notice create a list of strings with the commands necessary to compile Vyper contracts | ||
string[] memory cmds = new string[](3); | ||
cmds[0] = "huffc"; | ||
cmds[1] = "-b"; | ||
cmds[2] = fileName; | ||
|
||
///@notice compile the Vyper contract and return the bytecode | ||
bytes memory bytecode = cheatCodes.ffi(cmds); | ||
|
||
///@notice deploy the bytecode with the create instruction | ||
address deployedAddress; | ||
assembly { | ||
deployedAddress := create(0, add(bytecode, 0x20), mload(bytecode)) | ||
} | ||
|
||
///@notice check that the deployment was successful | ||
require( | ||
deployedAddress != address(0), | ||
"PuffDeployer could not deploy contract" | ||
); | ||
|
||
///@notice return the address that the contract was deployed to | ||
return deployedAddress; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters