From 51b806db16a7c199e9c83fe7b1893a6da355f607 Mon Sep 17 00:00:00 2001 From: Schlagonia Date: Fri, 20 Oct 2023 15:08:30 -0600 Subject: [PATCH] chore: update deployments --- README.md | 7 ++- script/DeployAprOracle.s.sol | 43 +++++++++++++++++++ ...Deploy.s.sol => DeployCommonTrigger.s.sol} | 7 +-- 3 files changed, 50 insertions(+), 7 deletions(-) create mode 100644 script/DeployAprOracle.s.sol rename script/{Deploy.s.sol => DeployCommonTrigger.s.sol} (86%) diff --git a/README.md b/README.md index c796db6..aaddee8 100644 --- a/README.md +++ b/README.md @@ -47,15 +47,14 @@ This can be done permissionlessly if the most recent contract has not yet been d 1. Add your deployers Private key under PRIVATE_KEY in your .env file. - NOTE: make sure to add `0x` to the beginning of the key. -2. Enter what contract you want to deploy on line 9 - `ContractFile.sol:ContractName` -2. Run the deployment script +2. Run the deployment script for the contract you want to deploy. ```sh - forge script script/Deploy.s.sol:Deploy --broadcast --rpc-url YOUR_RPC + forge script script/DeployContractName.s.sol:DeployContractName --broadcast --rpc-url YOUR_RPC_URL ``` - You can do a dry run before officially deploying by removing the `--broadcast` flag. - For chains that don't support 1559 tx's you may need to add a `--legacy` flag. 3. The address the contract was deployed at will print in the console and should match any other chain the same version has been deployed on. + ## Swapper helper contracts For strategies that need to swap reward tokens back into 'asset' a series of 'swapper' contracts have been pre-developed to make your preferred method as easy as possible to use. diff --git a/script/DeployAprOracle.s.sol b/script/DeployAprOracle.s.sol new file mode 100644 index 0000000..dd112e3 --- /dev/null +++ b/script/DeployAprOracle.s.sol @@ -0,0 +1,43 @@ +// SPDX-License-Identifier: AGPL-3.0 +pragma solidity 0.8.18; + +import "forge-std/Script.sol"; + +// Deploy a contract to a deterministic address with create2 +contract DeployAprOracle is Script { + + Deployer public deployer = Deployer(0x8D85e7c9A4e369E53Acc8d5426aE1568198b0112); + + function run() external { + uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY"); + vm.startBroadcast(deployerPrivateKey); + + // Get the bytecode + bytes memory bytecode = abi.encodePacked(vm.getCode("AprOracle.sol:AprOracle")); + + // Pick an unique salt + uint256 salt = uint256(keccak256("APR Oracle")); + + address contractAddress = deployer.deploy(bytecode, salt); + + console.log("Address is ", contractAddress); + + vm.stopBroadcast(); + } +} + +contract Deployer { + event Deployed(address addr, uint256 salt); + + function deploy(bytes memory code, uint256 salt) external returns (address) { + address addr; + assembly { + addr := create2(0, add(code, 0x20), mload(code), salt) + if iszero(extcodesize(addr)) { + revert(0, 0) + } + } + emit Deployed(addr, salt); + return addr; + } +} \ No newline at end of file diff --git a/script/Deploy.s.sol b/script/DeployCommonTrigger.s.sol similarity index 86% rename from script/Deploy.s.sol rename to script/DeployCommonTrigger.s.sol index 952aef5..45595ed 100644 --- a/script/Deploy.s.sol +++ b/script/DeployCommonTrigger.s.sol @@ -4,7 +4,7 @@ pragma solidity 0.8.18; import "forge-std/Script.sol"; // Deploy a contract to a deterministic address with create2 -contract Deploy is Script { +contract DeployCommonTrigger is Script { Deployer public deployer = Deployer(0x8D85e7c9A4e369E53Acc8d5426aE1568198b0112); @@ -13,13 +13,14 @@ contract Deploy is Script { vm.startBroadcast(deployerPrivateKey); // Encode constructor arguments - bytes memory construct = abi.encode(); + bytes memory construct = abi.encode(0x33333333D5eFb92f19a5F94a43456b3cec2797AE); // Append constructor args to the bytecode bytes memory bytecode = abi.encodePacked(vm.getCode("CommonReportTrigger.sol:CommonReportTrigger"), construct); + // Pick an unique salt - uint256 salt = uint256(keccak256("v3.0.0")); + uint256 salt = uint256(keccak256("Common Trigger")); address contractAddress = deployer.deploy(bytecode, salt);