|
| 1 | +// SPDX-License-Identifier: SEE LICENSE IN LICENSE |
| 2 | +pragma solidity 0.8.29; |
| 3 | + |
| 4 | +import "forge-std/Script.sol"; |
| 5 | +import "../../src/MigrationRelease.sol"; |
| 6 | +import { ITransparentUpgradeableProxy } from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; |
| 7 | +import "@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol"; |
| 8 | + |
| 9 | +/** |
| 10 | + * @title UpgradeRelease |
| 11 | + * @dev Upgrade script for MigrationRelease contract |
| 12 | + * This script handles: |
| 13 | + * 1. Deployment of the new implementation contract |
| 14 | + * 2. Upgrading the proxy to point to the new implementation |
| 15 | + */ |
| 16 | +contract UpgradeReleaseScript is Script { |
| 17 | + // Storage slot for ProxyAdmin in TransparentUpgradeableProxy |
| 18 | + bytes32 constant PROXY_ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103; |
| 19 | + |
| 20 | + function run() external { |
| 21 | + // Get private key from environment |
| 22 | + uint256 deployerPrivateKey = vm.envUint("DEPLOYER_OWNER"); |
| 23 | + address deployerAddress = vm.addr(deployerPrivateKey); |
| 24 | + |
| 25 | + // Get proxy address from environment |
| 26 | + address proxyAddress = 0x95CFE535e2Eea0EB1620fa1d10549b67e284Ba52; |
| 27 | + |
| 28 | + vm.startBroadcast(deployerPrivateKey); |
| 29 | + |
| 30 | + console.log("Upgrading contracts with address:", deployerAddress); |
| 31 | + console.log("Current proxy address:", proxyAddress); |
| 32 | + |
| 33 | + // Deploy new implementation |
| 34 | + MigrationRelease newImplementation = new MigrationRelease(); |
| 35 | + console.log("New MigrationRelease implementation deployed at:", address(newImplementation)); |
| 36 | + |
| 37 | + // Get the proxy admin contract from storage slot |
| 38 | + address proxyAdminAddress = address(uint160(uint256(vm.load(proxyAddress, PROXY_ADMIN_SLOT)))); |
| 39 | + ProxyAdmin proxyAdmin = ProxyAdmin(proxyAdminAddress); |
| 40 | + console.log("ProxyAdmin address:", proxyAdminAddress); |
| 41 | + |
| 42 | + // Upgrade the proxy to point to the new implementation |
| 43 | + proxyAdmin.upgradeAndCall( |
| 44 | + ITransparentUpgradeableProxy(payable(proxyAddress)), address(newImplementation), bytes("") |
| 45 | + ); |
| 46 | + console.log("Proxy upgraded to new implementation"); |
| 47 | + |
| 48 | + vm.stopBroadcast(); |
| 49 | + } |
| 50 | +} |
0 commit comments