-
Notifications
You must be signed in to change notification settings - Fork 1
fix: upgrade script #30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
6666b3d
fix: pre-audit build-info
Reinis-FRP a39c265
fix: upgrade script
Reinis-FRP 708c1c2
fix: update readme on upgrades
Reinis-FRP 4c7f4e2
fix: use encode call
Reinis-FRP ab04f51
fix: forge fmt
Reinis-FRP adf08aa
revert: deploy script fixes
Reinis-FRP 0fbfc22
fix: remove skipping storage check
Reinis-FRP 55aee82
fix: update readme
Reinis-FRP 9246550
fix: update readme
Reinis-FRP a3034ba
fix: upgrade prerequisites in readme
Reinis-FRP f7d83cc
fix: update readme
Reinis-FRP f28fd40
fix: update readme
Reinis-FRP 46447a3
fix: update readme
Reinis-FRP 8b21d61
fix: rebuild in readme
Reinis-FRP db82ed2
fix: forge fmt
Reinis-FRP dcdc7a2
fix: upgrade script naming
Reinis-FRP 3e9716d
fix: avoid duplication
Reinis-FRP 2fdc689
Merge branch 'master' into reinis-frp/upgrade-script
Reinis-FRP File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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,124 @@ | ||
| // SPDX-License-Identifier: AGPL-3.0-only | ||
| pragma solidity ^0.8.0; | ||
|
|
||
| import {Script} from "forge-std/Script.sol"; | ||
| import {console} from "forge-std/console.sol"; | ||
| import {Upgrades} from "@openzeppelin/foundry-upgrades/Upgrades.sol"; | ||
| import {Options} from "@openzeppelin/foundry-upgrades/Options.sol"; | ||
|
|
||
| import {ManagedOptimisticOracleV2} from "../src/optimistic-oracle-v2/implementation/ManagedOptimisticOracleV2.sol"; | ||
|
|
||
| /** | ||
| * @title Upgrade script for ManagedOptimisticOracleV2 | ||
| * @notice Upgrades the ManagedOptimisticOracleV2 contract implementation using OZ Upgrades | ||
| * | ||
| * Environment variables: | ||
| * - MNEMONIC: Required. The mnemonic phrase for the upgrade admin wallet | ||
| * - PROXY_ADDRESS: Required. Address of the existing proxy contract to upgrade | ||
| * - REFERENCE_BUILD_VERSION: Required. Integer version number to derive reference contract and build info dir (e.g., 1 for "build-info-v1:ManagedOptimisticOracleV2" and "old-builds/build-info-v1") | ||
| */ | ||
| contract UpgradeManagedOptimisticOracleV2 is Script { | ||
| function run() external { | ||
| uint256 deployerPrivateKey = _getDeployerPrivateKey(); | ||
| address deployerAddress = vm.addr(deployerPrivateKey); | ||
|
|
||
| // Get the proxy address to upgrade | ||
| address proxyAddress = vm.envAddress("PROXY_ADDRESS"); | ||
|
|
||
| // Fetch the upgrade admin from the contract | ||
| address upgradeAdmin = ManagedOptimisticOracleV2(proxyAddress).owner(); | ||
|
|
||
| // Required reference build version for upgrade validation | ||
| uint256 referenceBuildVersion = vm.envUint("REFERENCE_BUILD_VERSION"); | ||
|
|
||
| // Build upgrade validation options | ||
| Options memory opts; | ||
| opts.referenceContract = | ||
| string.concat("build-info-v", vm.toString(referenceBuildVersion), ":ManagedOptimisticOracleV2"); | ||
| opts.referenceBuildInfoDir = string.concat("old-builds/build-info-v", vm.toString(referenceBuildVersion)); | ||
|
|
||
| // Log initial setup | ||
| console.log("Deployer Address:", deployerAddress); | ||
| console.log("Upgrade Admin:", upgradeAdmin); | ||
| console.log("Proxy Address:", proxyAddress); | ||
| console.log("Reference Contract:", opts.referenceContract); | ||
| console.log("Reference Build Info Dir:", opts.referenceBuildInfoDir); | ||
|
|
||
| // Check if we need to impersonate or can execute directly | ||
| bool shouldImpersonate = upgradeAdmin != deployerAddress; | ||
|
|
||
| if (shouldImpersonate) { | ||
| // Multisig mode - deploy implementation and generate transaction data | ||
| console.log("\n=== IMPERSONATION MODE ==="); | ||
| console.log("MNEMONIC does not correspond to upgrade admin"); | ||
| console.log("Deploying new implementation and generating upgrade transaction data"); | ||
|
|
||
| // Deploy the new implementation | ||
| console.log("\n=== DEPLOYING NEW IMPLEMENTATION ==="); | ||
| vm.startBroadcast(deployerPrivateKey); | ||
| address newImplementationAddress = | ||
| Upgrades.prepareUpgrade("ManagedOptimisticOracleV2.sol:ManagedOptimisticOracleV2", opts); | ||
| vm.stopBroadcast(); | ||
| console.log("New Implementation Address:", newImplementationAddress); | ||
|
|
||
| // Generate upgrade transaction data | ||
| bytes memory upgradeData = | ||
| abi.encodeWithSignature("upgradeToAndCall(address,bytes)", newImplementationAddress, bytes("")); | ||
|
|
||
| // Simulate the upgrade transaction to verify it would succeed | ||
| console.log("\n=== SIMULATING UPGRADE TRANSACTION ==="); | ||
| vm.startPrank(upgradeAdmin); | ||
| (bool success, bytes memory result) = proxyAddress.call(upgradeData); | ||
| vm.stopPrank(); | ||
|
|
||
| if (success) { | ||
| console.log("Upgrade simulation successful!"); | ||
| } else { | ||
| console.log("Upgrade simulation failed!"); | ||
| console.log("Error:", vm.toString(result)); | ||
| revert("Upgrade simulation failed - check the error above"); | ||
| } | ||
|
|
||
| // Log transaction data for multisig | ||
| console.log("\n=== MULTISIG UPGRADE TRANSACTION DATA ==="); | ||
| console.log("Target Contract:", proxyAddress); | ||
| console.log("Transaction Data:", vm.toString(upgradeData)); | ||
| console.log("Upgrade Admin:", upgradeAdmin); | ||
| console.log("Chain ID:", block.chainid); | ||
| console.log("\nUse this transaction data in your multisig wallet to execute the upgrade."); | ||
| console.log("The new implementation has been deployed at:", newImplementationAddress); | ||
| } else { | ||
| // Direct mode - execute upgrade directly | ||
| console.log("\n=== DIRECT EXECUTION MODE ==="); | ||
| console.log("MNEMONIC corresponds to upgrade admin"); | ||
| console.log("Executing upgrade directly"); | ||
|
|
||
| // Start broadcasting transactions with the derived private key | ||
| vm.startBroadcast(deployerPrivateKey); | ||
|
|
||
| // Upgrade the proxy | ||
| Upgrades.upgradeProxy( | ||
| proxyAddress, "ManagedOptimisticOracleV2.sol:ManagedOptimisticOracleV2", bytes(""), opts | ||
| ); | ||
|
|
||
| vm.stopBroadcast(); | ||
|
|
||
| // Output upgrade summary | ||
| console.log("\n=== Upgrade Summary ==="); | ||
| console.log("Proxy Address:", proxyAddress); | ||
| console.log("New Implementation Address:", Upgrades.getImplementationAddress(proxyAddress)); | ||
| console.log("Chain ID:", block.chainid); | ||
| console.log("Upgrade Admin:", upgradeAdmin); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * @notice Derives the deployer's private key from the mnemonic | ||
| * @return deployerPrivateKey The derived private key for the deployer | ||
| */ | ||
| function _getDeployerPrivateKey() internal view returns (uint256) { | ||
| string memory mnemonic = vm.envString("MNEMONIC"); | ||
| // Derive the 0 index address from mnemonic | ||
| return vm.deriveKey(mnemonic, 0); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: here "upgrade admin" is the “default admin”?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, we made an alias
UPGRADE_ADMIN_ROLE = DEFAULT_ADMIN_ROLEthat is used inonlyUpgradeAdmincheck