Skip to content

Commit

Permalink
Updates to Deploy tooling (#437)
Browse files Browse the repository at this point in the history
* Updates to Deploy tooling

* Update whale address

* Update whale address

* Tooling fixes

* Fix tooling

* Update whale address

* Attempt at making tests stable
  • Loading branch information
shahthepro committed Jun 7, 2024
1 parent 2a8c8a0 commit 1d7d90e
Show file tree
Hide file tree
Showing 14 changed files with 81 additions and 75 deletions.
24 changes: 17 additions & 7 deletions 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 Expand Up @@ -50,26 +49,27 @@ library GovFive {
GovFiveAction memory propAction = prop.actions[i];

targets[i] = propAction.receiver;
payloads[i] =
abi.encodePacked(abi.encodePacked(bytes4(keccak256(bytes(propAction.fullsig)))), propAction.data);
payloads[i] = abi.encodePacked(bytes4(keccak256(bytes(propAction.fullsig))), propAction.data);
}

bytes32 salt = keccak256(bytes(prop.description));

TimelockController timelock = TimelockController(payable(Addresses.TIMELOCK));
receiver = Addresses.TIMELOCK;

opHash = timelock.hashOperationBatch(targets, values, payloads, hex"", salt);
opHash = timelock.hashOperationBatch(targets, values, payloads, bytes32(0), salt);

if (timelock.isOperation(opHash)) {
bytes4 executeSig = bytes4(keccak256(bytes("executeBatch(address[],uint256[],bytes[],bytes32,bytes32)")));

payload = abi.encodePacked(executeSig, abi.encode(targets, values, payloads, hex"", salt));
console.log("Yet to be exeucted.");
payload = abi.encodePacked(executeSig, abi.encode(targets, values, payloads, bytes32(0), salt));
} else {
bytes4 scheduleSig =
bytes4(keccak256(bytes("scheduleBatch(address[],uint256[],bytes[],bytes32,bytes32,delay)")));
bytes4(keccak256(bytes("scheduleBatch(address[],uint256[],bytes[],bytes32,bytes32,uint256)")));

payload = abi.encodePacked(scheduleSig, abi.encode(targets, values, payloads, hex"", salt, 2 days));
console.log("Yet to be scheduled.");
payload = abi.encodePacked(scheduleSig, abi.encode(targets, values, payloads, bytes32(0), salt, 2 days));
}
}

Expand Down Expand Up @@ -113,6 +113,10 @@ library GovFive {
console.log("Scheduling...");
(bool success, bytes memory data) = receiver.call(payload);

if (!success || !timelock.isOperation(opHash)) {
revert("Failed to schedule");
}

(receiver, payload, opHash) = getSafeTxData(prop);
}

Expand All @@ -125,6 +129,12 @@ library GovFive {

(bool success, bytes memory data) = receiver.call(payload);

if (!success || !timelock.isOperationDone(opHash)) {
revert("Failed to execute");
}

console.log("Executed");

vm.stopPrank();
}

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.

30 changes: 21 additions & 9 deletions script/deploy/DeployManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,23 @@ 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);
forkFileId = Strings.toString(block.timestamp);
}

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

function getMainnetDeploymentFilePath() public view returns (string memory) {
Expand All @@ -34,9 +39,11 @@ contract DeployManager is Script {
return string(abi.encodePacked(vm.projectRoot(), "/build/deployments-fork", forkFileId, ".json"));
}

function setUp() external {
forkFileId = Strings.toString(block.timestamp);
function setForkFileId(string memory _forkFileId) external {
forkFileId = _forkFileId;
}

function setUp() external {
string memory chainIdStr = Strings.toString(block.chainid);
string memory chainIdKey = string(abi.encodePacked(".", chainIdStr));

Expand All @@ -54,7 +61,7 @@ contract DeployManager is Script {
);
}

if (vm.isForkEnv()) {
if (isForked) {
// Duplicate Mainnet File
vm.writeFile(getForkDeploymentFilePath(), vm.readFile(mainnetFilePath));
}
Expand All @@ -70,7 +77,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 +125,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
13 changes: 4 additions & 9 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";
import {ERC20Votes} from "OpenZeppelin/[email protected]/contracts/token/ERC20/extensions/ERC20Votes.sol";
import {TimelockController} from "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 All @@ -45,9 +43,6 @@ contract XOGNGovernanceScript is BaseMainnetScript {

address xognGov = deployedContracts["XOGN_GOV"];

address ognRewardsSourceProxy = deployedContracts["OGN_REWARDS_SOURCE"];
address veOgvImpl = deployedContracts["VEOGV_IMPL"];

govProposal.setName("Grant access to OGN Governance");

govProposal.setDescription("Grant access to OGN Governance");
Expand Down Expand Up @@ -88,6 +83,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
8 changes: 7 additions & 1 deletion tests/staking/MigratorForkTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ contract MigratorForkTest is Test {
IMintableERC20 public ogn;

uint256 constant OGN_EPOCH = 1717041600; // May 30, 2024 GMT
address public ogvWhale = 0x70fCE97d671E81080CA3ab4cc7A59aAc2E117137;
address public ogvWhale = 0xD066c92d5dD4fD19E7F053Cf63EBB01Aaaa233CE;

constructor() {
deployManager = new DeployManager();

deployManager.setForkFileId(string(abi.encodePacked(vm.toString(block.chainid), "-MigratorForkTest")));

deployManager.setUp();
deployManager.run();
}
Expand All @@ -46,6 +48,10 @@ contract MigratorForkTest is Test {
ogv.approve(address(veogv), type(uint256).max);
vm.stopPrank();

vm.startPrank(Addresses.TIMELOCK);
ogn.mint(ogvWhale, 10_000_000 ether); // Mint some OGV for the whale
vm.stopPrank();

vm.warp(OGN_EPOCH + 100 days);

if (veogv.balanceOf(ogvWhale) == 0) {
Expand Down
Loading

0 comments on commit 1d7d90e

Please sign in to comment.