Skip to content

Commit

Permalink
fix: scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
Schlagonia committed Sep 23, 2024
1 parent ac51750 commit 3f93cec
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 36 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,15 @@ Deployment of periphery contracts such as the [Apr Oracle](https://github.com/ye

This can be done permissionlessly if the most recent contract has not yet been deployed on a chain you would like to use it on.

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.
1. If you have not added a keystore private key to foundry before add your address to use

```shell
$ cast wallet import --interactive <wallet_name>
```

2. Run the deployment script for the contract you want to deploy.
```sh
forge script script/DeployContractName.s.sol:DeployContractName --broadcast --rpc-url YOUR_RPC_URL
forge script script/DeployContractName.s.sol:DeployContractName --broadcast --rpc-url YOUR_RPC_URL --account ACCOUNT_NAME
```
- 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.
Expand Down
28 changes: 28 additions & 0 deletions script/BaseScript.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// SPDX-License-Identifier: AGPL-3.0
pragma solidity >=0.8.18;

import "forge-std/Script.sol";

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);
}

// Deploy a contract to a deterministic address with create2
contract BaseScript is Script {

Deployer public deployer = Deployer(0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed);

address public v3Safe = 0x33333333D5eFb92f19a5F94a43456b3cec2797AE;

address public initGov;
}
20 changes: 4 additions & 16 deletions script/DeployAprOracle.s.sol
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
// SPDX-License-Identifier: AGPL-3.0
pragma solidity >=0.8.18;

import "forge-std/Script.sol";
import "./BaseScript.sol";

// Deploy a contract to a deterministic address with create2
contract DeployAprOracle is Script {

Deployer public deployer = Deployer(0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed);
contract DeployAprOracle is BaseScript {

function run() external {
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
vm.startBroadcast(deployerPrivateKey);
vm.startBroadcast();

// Encode constructor arguments
bytes memory construct = abi.encode(0x33333333D5eFb92f19a5F94a43456b3cec2797AE);
bytes memory construct = abi.encode(v3Safe);

// Get the bytecode
bytes memory bytecode = abi.encodePacked(vm.getCode("AprOracle.sol:AprOracle"), construct);
Expand All @@ -27,13 +24,4 @@ contract DeployAprOracle is Script {

vm.stopBroadcast();
}
}

contract Deployer {
event ContractCreation(address indexed newContract, bytes32 indexed salt);

function deployCreate2(
bytes32 salt,
bytes memory initCode
) public payable returns (address newContract) {}
}
18 changes: 3 additions & 15 deletions script/DeployAuctionFactory.sol
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
// SPDX-License-Identifier: AGPL-3.0
pragma solidity >=0.8.18;

import "forge-std/Script.sol";
import "./BaseScript.sol";

// Deploy a contract to a deterministic address with create2
contract DeployAuctionFactory is Script {

Deployer public deployer = Deployer(0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed);
contract DeployAuctionFactory is BaseScript {

function run() external {
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
vm.startBroadcast(deployerPrivateKey);
vm.startBroadcast();

// Get the bytecode
bytes memory bytecode = abi.encodePacked(vm.getCode("AuctionFactory.sol:AuctionFactory"));
Expand All @@ -24,13 +21,4 @@ contract DeployAuctionFactory is Script {

vm.stopBroadcast();
}
}

interface Deployer {
event ContractCreation(address indexed newContract, bytes32 indexed salt);

function deployCreate3(
bytes32 salt,
bytes memory initCode
) external payable returns (address newContract);
}
3 changes: 1 addition & 2 deletions script/DeployCommonTrigger.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ contract DeployCommonTrigger is Script {
Deployer public deployer = Deployer(0x8D85e7c9A4e369E53Acc8d5426aE1568198b0112);

function run() external {
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
vm.startBroadcast(deployerPrivateKey);
vm.startBroadcast();

// Encode constructor arguments
bytes memory construct = abi.encode(0x33333333D5eFb92f19a5F94a43456b3cec2797AE);
Expand Down
24 changes: 24 additions & 0 deletions script/DeployInitGov.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// SPDX-License-Identifier: AGPL-3.0
pragma solidity >=0.8.18;

import "./BaseScript.sol";

// Deploy a contract to a deterministic address with create2
contract DeployAuctionFactory is BaseScript {

function run() external {
vm.startBroadcast();

// Get the bytecode
bytes memory bytecode = abi.encodePacked(vm.getCode("InitGov.sol:InitGov"));

// Pick an unique salt
bytes32 salt = keccak256("Init Gov");

address contractAddress = deployer.deployCreate2(salt, bytecode);

console.log("Address is ", contractAddress);

vm.stopBroadcast();
}
}

0 comments on commit 3f93cec

Please sign in to comment.