Skip to content

Commit

Permalink
Update tooling to record script executions
Browse files Browse the repository at this point in the history
  • Loading branch information
shahthepro committed May 16, 2024
1 parent df1e6f4 commit aaae7d6
Show file tree
Hide file tree
Showing 7 changed files with 233 additions and 155 deletions.
4 changes: 1 addition & 3 deletions build/deployments.json
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
{
"1": {}
}
{ "1": { "executions": {}, "contracts": {} } }
8 changes: 4 additions & 4 deletions contracts/utils/Addresses.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ library Addresses {
address public constant OGV_REWARDS_PROXY = 0x7d82E86CF1496f9485a8ea04012afeb3C7489397;
address public constant VEOGV = 0x0C4576Ca1c365868E162554AF8e385dc3e7C66D9;

address public constant OUSD_BUYBACK = address(34);
address public constant OETH_BUYBACK = address(35);
address public constant OUSD_BUYBACK_IMPL = address(34);
address public constant OETH_BUYBACK_IMPL = address(35);
address public constant OUSD_BUYBACK = 0xD7B28d06365b85933c64E11e639EA0d3bC0e3BaB;
address public constant OETH_BUYBACK = 0xFD6c58850caCF9cCF6e8Aee479BFb4Df14a362D2;
address public constant OUSD_BUYBACK_IMPL = 0xbc77B8EFafabdF46f94Dfb4A422d541c5037799C;
address public constant OETH_BUYBACK_IMPL = 0x69D343A52bC13Dc19cBD0d2A77baC320CCB69B9a;
}
141 changes: 141 additions & 0 deletions script/deploy/DeployManager.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
// SPDX-License-Identifier: Unlicense
pragma solidity 0.8.10;

import "forge-std/Script.sol";
import "OpenZeppelin/openzeppelin-contracts@4.6.0/contracts/utils/Strings.sol";

import {BaseMainnetScript} from "./mainnet/BaseMainnetScript.sol";

import {XOGNSetup} from "./mainnet/010_xOGNSetup.sol";
import {OgnOgvMigrationScript} from "./mainnet/011_OgnOgvMigrationScript.sol";

contract DeployManager is Script {
mapping(string => address) public deployedContracts;
mapping(string => bool) public scriptsExecuted;

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

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

function getMainnetDeploymentFilePath() public view returns (string memory) {
return string(abi.encodePacked(vm.projectRoot(), "/build/deployments.json"));
}

function getForkDeploymentFilePath() public view returns (string memory) {
return string(abi.encodePacked(vm.projectRoot(), "/build/deployments-fork.json"));
}

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

string memory mainnetFilePath = getMainnetDeploymentFilePath();
if (!vm.isFile(mainnetFilePath)) {
// Create mainnet deployment file if it doesn't exist
vm.writeFile(
mainnetFilePath,
string(abi.encodePacked('{ "', chainIdStr, '": { "executions": {}, "contracts": {} } }'))
);
} else if (!vm.keyExistsJson(vm.readFile(mainnetFilePath), chainIdKey)) {
// Create network entry if it doesn't exist
vm.writeJson(
vm.serializeJson(chainIdStr, '{ "executions": {}, "contracts": {} }'), mainnetFilePath, chainIdKey
);
}

if (isForked()) {
// Duplicate Mainnet File
vm.writeFile(getForkDeploymentFilePath(), vm.readFile(mainnetFilePath));
}
}

function run() external {
// TODO: Use vm.readDir to recursively build this?
_runDeployFile(new XOGNSetup());
_runDeployFile(new OgnOgvMigrationScript());
}

function _runDeployFile(BaseMainnetScript deployScript) internal {
string memory chainIdStr = Strings.toString(block.chainid);
string memory chainIdKey = string(abi.encodePacked(".", chainIdStr));

string memory contractsKey = string(abi.encodePacked(chainIdKey, ".contracts"));
string memory executionsKey = string(abi.encodePacked(chainIdKey, ".executions"));

string memory deploymentsFilePath = getDeploymentFilePath();
string memory fileContents = vm.readFile(deploymentsFilePath);

/**
* Execution History
*/
string memory currentExecutions = "";
string[] memory executionKeys = vm.parseJsonKeys(fileContents, executionsKey);

for (uint256 i = 0; i < executionKeys.length; ++i) {
uint256 deployedTimestamp =
vm.parseJsonUint(fileContents, string(abi.encodePacked(executionsKey, ".", executionKeys[i])));

currentExecutions = vm.serializeUint(executionsKey, executionKeys[i], deployedTimestamp);
scriptsExecuted[executionKeys[i]] = true;
}

if (scriptsExecuted[deployScript.DEPLOY_NAME()]) {
// TODO: Handle any active governance proposal
console.log("Skipping already deployed script");
return;
}

/**
* Pre-deployment
*/
BaseMainnetScript.DeployRecord[] memory deploys;
string memory networkDeployments = "";
string[] memory existingContracts = vm.parseJsonKeys(fileContents, contractsKey);
for (uint256 i = 0; i < existingContracts.length; ++i) {
address deployedAddr =
vm.parseJsonAddress(fileContents, string(abi.encodePacked(contractsKey, ".", existingContracts[i])));

networkDeployments = vm.serializeAddress(contractsKey, existingContracts[i], deployedAddr);

deployedContracts[existingContracts[i]] = deployedAddr;

deployScript.preloadDeployedContract(existingContracts[i], deployedAddr);
}

// Deployment
deployScript.setUp();
deployScript.run();

/**
* Post-deployment
*/
BaseMainnetScript.DeployRecord[] memory records = deployScript.getAllDeployRecords();

for (uint256 i = 0; i < records.length; ++i) {
string memory name = records[i].name;
address addr = records[i].addr;

console.log(string(abi.encodePacked("> Recorded Deploy of ", name, " at")), addr);
networkDeployments = vm.serializeAddress(contractsKey, name, addr);
deployedContracts[name] = addr;
}

vm.writeJson(networkDeployments, deploymentsFilePath, contractsKey);

/**
* Write Execution History
*/
currentExecutions = vm.serializeUint(executionsKey, deployScript.DEPLOY_NAME(), block.timestamp);

vm.writeJson(currentExecutions, deploymentsFilePath, executionsKey);
}

function getDeployment(string calldata contractName) external view returns (address) {
return deployedContracts[contractName];
}
}
105 changes: 0 additions & 105 deletions script/deploy/DeploymentManager.sol

This file was deleted.

67 changes: 67 additions & 0 deletions script/deploy/mainnet/010_xOGNSetup.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// 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 {FixedRateRewardsSourceProxy} from "contracts/upgrades/FixedRateRewardsSourceProxy.sol";
import {ExponentialStakingProxy} from "contracts/upgrades/ExponentialStakingProxy.sol";
import {MigratorProxy} from "contracts/upgrades/MigratorProxy.sol";

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

contract XOGNSetup is BaseMainnetScript {
FixedRateRewardsSourceProxy ognRewardsSourceProxy;
OgvStaking veOgvImpl;

string public constant override DEPLOY_NAME = "010_xOGNSetup";

constructor() {}

function _execute() internal override {
console.log("Deploy:");
console.log("------------");

// 1. Deploy proxy contracts
// Since these contracts reference each other, we deploy all the proxies first
// so that the addresses are available in implimentation constructors.
FixedRateRewardsSourceProxy ognRewardsSourceProxy = new FixedRateRewardsSourceProxy();
_recordDeploy("OGN_REWARDS_SOURCE", address(ognRewardsSourceProxy));

ExponentialStakingProxy xOgnProxy = new ExponentialStakingProxy();
_recordDeploy("XOGN", address(xOgnProxy));

//
// 2. XOGN implimentation and init
uint256 ognEpoch = 1717041600; // May 30, 2024 GMT
uint256 ognMinStaking = 30 * 24 * 60 * 60; // 30 days
ExponentialStaking xognImpl =
new ExponentialStaking(Addresses.OGN, ognEpoch, ognMinStaking, address(ognRewardsSourceProxy));
_recordDeploy("XOGN_IMPL", address(xognImpl));

console.log("- xOgnProxy init");
xOgnProxy.initialize(address(xognImpl), Addresses.TIMELOCK, "");

//
// 2. Rewards implimentation and init
uint256 rewardsPerSecond = 0; //TODO: Decide on the params
FixedRateRewardsSource fixedRateRewardsSourceImpl = new FixedRateRewardsSource(Addresses.OGN);
_recordDeploy("OGN_REWARDS_SOURCE_IMPL", address(fixedRateRewardsSourceImpl));

console.log("- OGN rewards init");
bytes memory implInitData = string.concat(
fixedRateRewardsSourceImpl.initialize.selector,
abi.encode(Addresses.STRATEGIST, address(xOgnProxy), rewardsPerSecond)
);
ognRewardsSourceProxy.initialize(address(fixedRateRewardsSourceImpl), Addresses.TIMELOCK, implInitData);
}

function _fork() internal override {}
}
Loading

0 comments on commit aaae7d6

Please sign in to comment.