Skip to content

Commit

Permalink
Updates to Deploy tooling
Browse files Browse the repository at this point in the history
  • Loading branch information
shahthepro committed Jun 6, 2024
1 parent db9d7ba commit 56288de
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 60 deletions.
1 change: 0 additions & 1 deletion contracts/utils/GovFive.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {Addresses} from "contracts/utils/Addresses.sol";
import "forge-std/console.sol";

import {TimelockController} from "OpenZeppelin/[email protected]/contracts/governance/TimelockController.sol";
import "OpenZeppelin/[email protected]/contracts/utils/Strings.sol";

library GovFive {
struct GovFiveAction {
Expand Down
5 changes: 1 addition & 4 deletions contracts/utils/GovProposalHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ pragma solidity 0.8.10;
import {Addresses} from "contracts/utils/Addresses.sol";
import "forge-std/console.sol";

import "OpenZeppelin/[email protected]/contracts/utils/Strings.sol";
import {IGovernor} from "OpenZeppelin/[email protected]/contracts/governance/IGovernor.sol";
import {Governance} from "../Governance.sol";

import "contracts/utils/VmHelper.sol";
import {Vm} from "forge-std/Vm.sol";

struct GovAction {
address target;
Expand All @@ -24,8 +23,6 @@ struct GovProposal {
}

library GovProposalHelper {
using VmHelper for Vm;

function id(GovProposal memory prop) internal view returns (uint256 proposalId) {
bytes32 descriptionHash = keccak256(bytes(prop.description));
(address[] memory targets, uint256[] memory values, bytes[] memory calldatas) = getParams(prop);
Expand Down
21 changes: 0 additions & 21 deletions contracts/utils/VmHelper.sol

This file was deleted.

23 changes: 16 additions & 7 deletions script/deploy/DeployManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,22 @@ import {MigrationZapperScript} from "./mainnet/012_MigrationZapperScript.sol";
import {UpgradeMigratorScript} from "./mainnet/013_UpgradeMigratorScript.sol";
import {XOGNGovernanceScript} from "./mainnet/014_xOGNGovernanceScript.sol";

import "contracts/utils/VmHelper.sol";
import {VmSafe} from "forge-std/Vm.sol";

contract DeployManager is Script {
using VmHelper for Vm;

mapping(string => address) public deployedContracts;
mapping(string => bool) public scriptsExecuted;

string internal forkFileId = "";

bool public isForked;

constructor() {
isForked = vm.isContext(VmSafe.ForgeContext.ScriptDryRun) || vm.isContext(VmSafe.ForgeContext.TestGroup);
}

function getDeploymentFilePath() public view returns (string memory) {
return vm.isForkEnv() ? getForkDeploymentFilePath() : getMainnetDeploymentFilePath();
return isForked ? getForkDeploymentFilePath() : getMainnetDeploymentFilePath();
}

function getMainnetDeploymentFilePath() public view returns (string memory) {
Expand Down Expand Up @@ -54,7 +58,7 @@ contract DeployManager is Script {
);
}

if (vm.isForkEnv()) {
if (isForked) {
// Duplicate Mainnet File
vm.writeFile(getForkDeploymentFilePath(), vm.readFile(mainnetFilePath));
}
Expand All @@ -70,7 +74,11 @@ contract DeployManager is Script {
}

function _runDeployFile(BaseMainnetScript deployScript) internal {
if (deployScript.skip()) {
if (deployScript.proposalExecuted()) {
// No action to do
return;
} else if (deployScript.skip()) {
console.log("Skipping deployment (skip() == true)");
return;
}

Expand Down Expand Up @@ -114,9 +122,10 @@ contract DeployManager is Script {
}

if (scriptsExecuted[deployScript.DEPLOY_NAME()]) {
console.log("Skipping deployment (already deployed)");

// Governance handling
deployScript.handleGovernanceProposal();
console.log("Skipping already deployed script");
} else {
// Deployment
deployScript.setUp();
Expand Down
1 change: 1 addition & 0 deletions script/deploy/mainnet/010_xOGNSetupScript.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {IMintableERC20} from "contracts/interfaces/IMintableERC20.sol";

contract XOGNSetupScript is BaseMainnetScript {
string public constant override DEPLOY_NAME = "010_xOGNSetup";
bool public constant override proposalExecuted = true;

constructor() {}

Expand Down
1 change: 1 addition & 0 deletions script/deploy/mainnet/011_OgnOgvMigrationScript.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ contract OgnOgvMigrationScript is BaseMainnetScript {
using GovProposalHelper for GovProposal;

string public constant override DEPLOY_NAME = "011_OgnOgvMigration";
bool public constant override proposalExecuted = true;

GovProposal public govProposal;

Expand Down
4 changes: 1 addition & 3 deletions script/deploy/mainnet/012_MigrationZapperScript.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,18 @@ import {Governance} from "contracts/Governance.sol";

import {GovFive} from "contracts/utils/GovFive.sol";

import {VmHelper} from "utils/VmHelper.sol";

import {MigrationZapper} from "contracts/MigrationZapper.sol";

import "OpenZeppelin/[email protected]/contracts/token/ERC20/extensions/ERC20Votes.sol";
import "OpenZeppelin/[email protected]/contracts/governance/TimelockController.sol";

contract MigrationZapperScript is BaseMainnetScript {
using GovFive for GovFive.GovFiveProposal;
using VmHelper for Vm;

GovFive.GovFiveProposal public govProposal;

string public constant override DEPLOY_NAME = "012_MigrationZapper";
bool public constant override proposalExecuted = true;

constructor() {}

Expand Down
11 changes: 1 addition & 10 deletions script/deploy/mainnet/013_UpgradeMigratorScript.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,21 @@
pragma solidity 0.8.10;

import "./BaseMainnetScript.sol";
import {Vm} from "forge-std/Vm.sol";

import {Addresses} from "contracts/utils/Addresses.sol";

import {Timelock} from "contracts/Timelock.sol";
import {Governance} from "contracts/Governance.sol";

import {GovFive} from "contracts/utils/GovFive.sol";

import {VmHelper} from "utils/VmHelper.sol";

import {Migrator} from "contracts/Migrator.sol";
import {OgvStaking} from "contracts/OgvStaking.sol";

import "OpenZeppelin/[email protected]/contracts/token/ERC20/extensions/ERC20Votes.sol";
import "OpenZeppelin/[email protected]/contracts/governance/TimelockController.sol";

contract UpgradeMigratorScript is BaseMainnetScript {
using GovFive for GovFive.GovFiveProposal;
using VmHelper for Vm;

GovFive.GovFiveProposal public govProposal;

string public constant override DEPLOY_NAME = "013_UpgradeMigrator";
bool public constant override proposalExecuted = false;

constructor() {}

Expand Down
6 changes: 2 additions & 4 deletions script/deploy/mainnet/014_xOGNGovernanceScript.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,16 @@ import {Governance} from "contracts/Governance.sol";

import {GovFive} from "contracts/utils/GovFive.sol";

import {VmHelper} from "utils/VmHelper.sol";

import "OpenZeppelin/[email protected]/contracts/token/ERC20/extensions/ERC20Votes.sol";
import "OpenZeppelin/[email protected]/contracts/governance/TimelockController.sol";

contract XOGNGovernanceScript is BaseMainnetScript {
using GovFive for GovFive.GovFiveProposal;
using VmHelper for Vm;

GovFive.GovFiveProposal public govProposal;

string public constant override DEPLOY_NAME = "014_xOGNGovernance";
bool public constant override proposalExecuted = false;

uint256 public constant OGN_EPOCH = 1717041600; // May 30, 2024 GMT

Expand Down Expand Up @@ -88,6 +86,6 @@ contract XOGNGovernanceScript is BaseMainnetScript {

function skip() external view override returns (bool) {
// Don't deploy on Mainnet for now
return !vm.isForkEnv();
return !this.isForked();
}
}
26 changes: 16 additions & 10 deletions script/deploy/mainnet/BaseMainnetScript.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,18 @@

pragma solidity 0.8.10;

import "forge-std/Script.sol";
import "OpenZeppelin/[email protected]/contracts/utils/Strings.sol";
import "forge-std/console.sol";

import {Script} from "forge-std/Script.sol";
import {Vm, VmSafe} from "forge-std/Vm.sol";

import {Addresses} from "contracts/utils/Addresses.sol";
import {GovProposal, GovProposalHelper} from "contracts/utils/GovProposalHelper.sol";

import "utils/VmHelper.sol";

abstract contract BaseMainnetScript is Script {
using VmHelper for Vm;
using GovProposalHelper for GovProposal;

uint256 public deployBlockNum = type(uint256).max;
bool isForked = false;

// DeployerRecord stuff to be extracted as well
struct DeployRecord {
Expand All @@ -42,6 +40,10 @@ abstract contract BaseMainnetScript is Script {
deployedContracts[name] = addr;
}

function isForked() public view returns (bool) {
return vm.isContext(VmSafe.ForgeContext.ScriptDryRun) || vm.isContext(VmSafe.ForgeContext.TestGroup);
}

function setUp() external {}

function run() external {
Expand All @@ -54,9 +56,7 @@ abstract contract BaseMainnetScript is Script {
return;
}

isForked = vm.isForkEnv();

if (isForked) {
if (this.isForked()) {
address impersonator = Addresses.INITIAL_DEPLOYER;
console.log("Running script on mainnet fork impersonating: %s", impersonator);
vm.startPrank(impersonator);
Expand All @@ -69,7 +69,7 @@ abstract contract BaseMainnetScript is Script {

_execute();

if (isForked) {
if (this.isForked()) {
vm.stopPrank();
_buildGovernanceProposal();
_fork();
Expand All @@ -80,6 +80,8 @@ abstract contract BaseMainnetScript is Script {

function DEPLOY_NAME() external view virtual returns (string memory);

function proposalExecuted() external view virtual returns (bool);

function skip() external view virtual returns (bool) {
return false;
}
Expand All @@ -91,6 +93,10 @@ abstract contract BaseMainnetScript is Script {
function _buildGovernanceProposal() internal virtual {}

function handleGovernanceProposal() external virtual {
if (this.proposalExecuted()) {
return;
}

_buildGovernanceProposal();
_fork();
}
Expand Down

0 comments on commit 56288de

Please sign in to comment.