|
| 1 | +// SPDX-License-Identifier: MIT |
| 2 | +pragma solidity ^0.8.19; |
| 3 | + |
| 4 | +// import "../src/TestToken.sol"; |
| 5 | +import "../src/AlignedTokenV2.sol"; |
| 6 | +import "@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol"; |
| 7 | +import "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; |
| 8 | +import {ERC1967Utils} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Utils.sol"; |
| 9 | +import "forge-std/Script.sol"; |
| 10 | +import {Vm} from "forge-std/Vm.sol"; |
| 11 | +import {Utils} from "./Utils.sol"; |
| 12 | + |
| 13 | +/// @notice This script upgrades the ClaimableAirdrop contract to ClaimableAirdropV2. |
| 14 | +/// @dev The `ProxyAdmin` owner must be the runner of this script since it is the |
| 15 | +/// one that will call the upgradeAndCall function of the `ProxyAdmin`. |
| 16 | +contract UpgradeToClaimableAirdropV2 is Script { |
| 17 | + function run(string memory config) public { |
| 18 | + string memory root = vm.projectRoot(); |
| 19 | + string memory path = string.concat( |
| 20 | + root, |
| 21 | + "/script-config/config.", |
| 22 | + config, |
| 23 | + ".json" |
| 24 | + ); |
| 25 | + string memory config_json = vm.readFile(path); |
| 26 | + |
| 27 | + address _currentTokenProxy = stdJson.readAddress( |
| 28 | + config_json, |
| 29 | + ".tokenProxy" |
| 30 | + ); |
| 31 | + |
| 32 | + vm.startBroadcast(); |
| 33 | + AlignedTokenV2 _newToken = new AlignedTokenV2(); |
| 34 | + |
| 35 | + address _adminAddress = getAdminAddress(_currentTokenProxy); |
| 36 | + |
| 37 | + ProxyAdmin(_adminAddress).upgradeAndCall( |
| 38 | + ITransparentUpgradeableProxy(_currentTokenProxy), |
| 39 | + address(_newToken), |
| 40 | + abi.encodeCall(AlignedTokenV2.reinitialize, ()) |
| 41 | + ); |
| 42 | + |
| 43 | + vm.stopBroadcast(); |
| 44 | + } |
| 45 | + |
| 46 | + function getAdminAddress(address proxy) internal view returns (address) { |
| 47 | + address CHEATCODE_ADDRESS = 0x7109709ECfa91a80626fF3989D68f67F5b1DD12D; |
| 48 | + Vm vm = Vm(CHEATCODE_ADDRESS); |
| 49 | + |
| 50 | + bytes32 adminSlot = vm.load(proxy, ERC1967Utils.ADMIN_SLOT); |
| 51 | + return address(uint160(uint256(adminSlot))); |
| 52 | + } |
| 53 | +} |
0 commit comments