-
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.
Update tooling to record script executions
- Loading branch information
1 parent
df1e6f4
commit aaae7d6
Showing
7 changed files
with
233 additions
and
155 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1 @@ | ||
{ | ||
"1": {} | ||
} | ||
{ "1": { "executions": {}, "contracts": {} } } |
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,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]; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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,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 {} | ||
} |
Oops, something went wrong.