-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into shah/apy-script
- Loading branch information
Showing
15 changed files
with
295 additions
and
56 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
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
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
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 |
---|---|---|
|
@@ -6,6 +6,7 @@ import {Vm} from "forge-std/Vm.sol"; | |
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 { | ||
|
@@ -35,22 +36,99 @@ library GovFive { | |
prop.actions.push(GovFiveAction({receiver: receiver, fullsig: fullsig, data: data})); | ||
} | ||
|
||
function printTxData(GovFiveProposal storage prop) internal { | ||
function getSafeTxData(GovFiveProposal memory prop) | ||
internal | ||
returns (address receiver, bytes memory payload, bytes32 opHash) | ||
{ | ||
uint256 actionCount = prop.actions.length; | ||
|
||
address[] memory targets = new address[](actionCount); | ||
uint256[] memory values = new uint256[](actionCount); | ||
bytes[] memory payloads = new bytes[](actionCount); | ||
|
||
for (uint256 i = 0; i < prop.actions.length; i++) { | ||
GovFiveAction memory propAction = prop.actions[i]; | ||
|
||
targets[i] = propAction.receiver; | ||
payloads[i] = | ||
abi.encodePacked(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); | ||
|
||
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)); | ||
} else { | ||
bytes4 scheduleSig = | ||
bytes4(keccak256(bytes("scheduleBatch(address[],uint256[],bytes[],bytes32,bytes32,delay)"))); | ||
|
||
payload = abi.encodePacked(scheduleSig, abi.encode(targets, values, payloads, hex"", salt, 2 days)); | ||
} | ||
} | ||
|
||
function printTxData(GovFiveProposal memory prop) internal { | ||
uint256 actionCount = prop.actions.length; | ||
|
||
if (actionCount == 0) { | ||
return; | ||
} | ||
|
||
(address receiver, bytes memory payload, bytes32 opHash) = getSafeTxData(prop); | ||
|
||
console.log("-----------------------------------"); | ||
console.log("Create following tx on Gnosis safe:"); | ||
console.log("-----------------------------------"); | ||
for (uint256 i = 0; i < prop.actions.length; i++) { | ||
GovFiveAction memory propAction = prop.actions[i]; | ||
bytes memory sig = abi.encodePacked(bytes4(keccak256(bytes(propAction.fullsig)))); | ||
console.log("Address:", receiver); | ||
console.log("Data:"); | ||
console.logBytes(payload); | ||
} | ||
|
||
function executeWithTimelock(GovFiveProposal memory prop) internal { | ||
address VM_ADDRESS = address(uint160(uint256(keccak256("hevm cheat code")))); | ||
Vm vm = Vm(VM_ADDRESS); | ||
|
||
uint256 actionCount = prop.actions.length; | ||
|
||
if (actionCount == 0) { | ||
return; | ||
} | ||
|
||
console.log("### Tx", i + 1); | ||
console.log("Address:", propAction.receiver); | ||
console.log("Data:"); | ||
console.logBytes(abi.encodePacked(sig, propAction.data)); | ||
vm.startPrank(Addresses.GOV_MULTISIG); | ||
(address receiver, bytes memory payload, bytes32 opHash) = getSafeTxData(prop); | ||
|
||
TimelockController timelock = TimelockController(payable(Addresses.TIMELOCK)); | ||
|
||
if (timelock.isOperationDone(opHash)) { | ||
return; | ||
} | ||
|
||
if (!timelock.isOperation(opHash)) { | ||
console.log("Scheduling..."); | ||
(bool success, bytes memory data) = receiver.call(payload); | ||
|
||
(receiver, payload, opHash) = getSafeTxData(prop); | ||
} | ||
|
||
if (!timelock.isOperationReady(opHash)) { | ||
vm.roll(1); | ||
vm.warp(timelock.getTimestamp(opHash) + 10); | ||
} | ||
|
||
console.log("Executing..."); | ||
|
||
(bool success, bytes memory data) = receiver.call(payload); | ||
|
||
vm.stopPrank(); | ||
} | ||
|
||
function execute(GovFiveProposal storage prop) internal { | ||
function execute(GovFiveProposal memory prop) internal { | ||
address VM_ADDRESS = address(uint160(uint256(keccak256("hevm cheat code")))); | ||
Vm vm = Vm(VM_ADDRESS); | ||
for (uint256 i = 0; i < prop.actions.length; i++) { | ||
|
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
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
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,65 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
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"; | ||
|
||
constructor() {} | ||
|
||
function _execute() internal override { | ||
console.log("Deploy:"); | ||
console.log("------------"); | ||
|
||
// Deploy veOGV implementation | ||
uint256 ogvMinStaking = 30 * 24 * 60 * 60; // 2592000 -> 30 days | ||
uint256 ogvEpoch = OgvStaking(Addresses.VEOGV).epoch(); // Use old value. | ||
OgvStaking veOgvImpl = new OgvStaking( | ||
Addresses.OGV, ogvEpoch, ogvMinStaking, Addresses.OGV_REWARDS_PROXY, deployedContracts["MIGRATOR"] | ||
); | ||
_recordDeploy("VEOGV_IMPL", address(veOgvImpl)); | ||
|
||
// Deploy migrator implementation | ||
Migrator migratorImpl = new Migrator(Addresses.OGV, Addresses.OGN, Addresses.VEOGV, deployedContracts["XOGN"]); | ||
_recordDeploy("MIGRATOR_IMPL", address(migratorImpl)); | ||
} | ||
|
||
function _buildGovernanceProposal() internal override { | ||
govProposal.action( | ||
deployedContracts["MIGRATOR"], "upgradeTo(address)", abi.encode(deployedContracts["MIGRATOR_IMPL"]) | ||
); | ||
|
||
govProposal.action( | ||
deployedContracts["VEOGV"], "upgradeTo(address)", abi.encode(deployedContracts["VEOGV_IMPL"]) | ||
); | ||
} | ||
|
||
function _fork() internal override { | ||
// Simulate proposal | ||
govProposal.printTxData(); | ||
govProposal.executeWithTimelock(); | ||
} | ||
} |
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
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
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
Oops, something went wrong.