-
Notifications
You must be signed in to change notification settings - Fork 45
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
1 parent
d268bbd
commit 6b46a73
Showing
3 changed files
with
72 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,4 +20,5 @@ yarn.lock | |
env | ||
cache/ | ||
out/ | ||
.gas-snapshot | ||
.gas-snapshot | ||
broadcast/ |
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,67 @@ | ||
// SPDX-License-Identifier: AGPL-3.0 | ||
pragma solidity >=0.8.18; | ||
|
||
import "forge-std/Script.sol"; | ||
|
||
///@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); | ||
} | ||
|
||
// Deploy a contract to a deterministic address with create2 | ||
contract Deploy is Script { | ||
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); | ||
|
||
Deployer public deployer = | ||
Deployer(0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed); | ||
|
||
function run() external { | ||
vm.startBroadcast(); | ||
|
||
string[] memory cmds = new string[](2); | ||
cmds[0] = "vyper"; | ||
cmds[1] = "contracts/VaultFactory.vy"; | ||
|
||
///@notice compile the Vyper contract and return the bytecode | ||
bytes memory _bytecode = cheatCodes.ffi(cmds); | ||
|
||
bytes memory args = abi.encode( | ||
"Yearn v3.0.3 Vault Factory", | ||
0xcA78AF7443f3F8FA0148b746Cb18FF67383CDF3f, | ||
0x6f3cBE2ab3483EC4BA7B672fbdCa0E9B33F88db8 | ||
); | ||
|
||
//add args to the deployment bytecode | ||
bytes memory bytecode = abi.encodePacked(_bytecode, args); | ||
|
||
// Pick an unique salt | ||
uint256 salt = 48628676351035099281129189787297157113420477883337005618231542152101559208037; | ||
|
||
address contractAddress = deployer.deployCreate2( | ||
bytes32(salt), | ||
bytecode | ||
); | ||
|
||
console.log("Address is ", contractAddress); | ||
|
||
vm.stopBroadcast(); | ||
} | ||
} | ||
|
||
interface Deployer { | ||
event ContractCreation(address indexed newContract, bytes32 indexed salt); | ||
|
||
function deployCreate3( | ||
bytes32 salt, | ||
bytes memory initCode | ||
) external payable returns (address newContract); | ||
|
||
function deployCreate2( | ||
bytes32 salt, | ||
bytes memory initCode | ||
) external payable returns (address newContract); | ||
} |
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