-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(faucet): improvements to faucet deployment scripts (#375)
feat(faucet): foundry scripts for deploying and configuring faucet drippie
- Loading branch information
1 parent
92e994b
commit 5e3852c
Showing
3 changed files
with
121 additions
and
150 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
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,35 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
import {Vm} from "forge-std/Vm.sol"; | ||
import {console} from "forge-std/console.sol"; | ||
|
||
/// @title DeployHelper | ||
/// @notice Library for deploying contracts. | ||
library DeployHelper { | ||
/// @notice Foundry cheatcode VM. | ||
Vm private constant VM = Vm(address(uint160(uint256(keccak256("hevm cheat code"))))); | ||
// @notice Deploys a contract using the CREATE2 opcode. | ||
// @param _name The name of the contract. | ||
// @param _creationCode The contract creation code. | ||
// @param _constructorParams The constructor parameters. | ||
|
||
function deployCreate2(string memory _name, bytes memory _creationCode, bytes memory _constructorParams) | ||
public | ||
returns (address addr_) | ||
{ | ||
bytes32 salt = keccak256(bytes(_name)); | ||
bytes memory initCode = abi.encodePacked(_creationCode, _constructorParams); | ||
address preComputedAddress = VM.computeCreate2Address(salt, keccak256(initCode)); | ||
if (preComputedAddress.code.length > 0) { | ||
console.log("%s already deployed at %s", _name, preComputedAddress); | ||
addr_ = preComputedAddress; | ||
} else { | ||
assembly { | ||
addr_ := create2(0, add(initCode, 0x20), mload(initCode), salt) | ||
} | ||
require(addr_ != address(0), "deployment failed"); | ||
console.log("%s deployed at %s", _name, addr_); | ||
} | ||
} | ||
} |