From c10b443129d3b0b6047d2fc88ea12681c5ed8693 Mon Sep 17 00:00:00 2001 From: SoraSuegami Date: Thu, 5 Sep 2024 17:32:41 +0900 Subject: [PATCH] Add upgrade contract for core --- packages/contracts/script/UpgradeCore.s.sol | 42 +++++++++++++++++++ ...istry.s.sol => UpgradeTokenRegistry.s.sol} | 5 +-- 2 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 packages/contracts/script/UpgradeCore.s.sol rename packages/contracts/script/{XX_UpgradeTokenRegistry.s.sol => UpgradeTokenRegistry.s.sol} (96%) diff --git a/packages/contracts/script/UpgradeCore.s.sol b/packages/contracts/script/UpgradeCore.s.sol new file mode 100644 index 00000000..b24316d7 --- /dev/null +++ b/packages/contracts/script/UpgradeCore.s.sol @@ -0,0 +1,42 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity ^0.8.13; + +import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol"; +import "forge-std/Script.sol"; +import "forge-std/console.sol"; +import "../src/EmailWalletCore.sol"; + +contract Upgrade is Script { + function run() external { + uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY"); + if (deployerPrivateKey == 0) { + console.log("PRIVATE_KEY env var not set"); + return; + } + + address core = vm.envAddress("CORE"); + if (core == address(0)) { + console.log("CORE env var not set. Deploy EmailWalletCore and set env var"); + return; + } + + vm.startBroadcast(deployerPrivateKey); + + // FIXME Set new TokenRegistry implementation + // e.g. TokenRegistryV2 tokenRegistryImpl = new TokenRegistryV2(); + EmailWalletCore coreImpl = new EmailWalletCore(); + + EmailWalletCore coreProxy = EmailWalletCore(payable(core)); + coreProxy.upgradeTo(address(coreImpl)); + + // If you want to call some v2 function, refer to the following steps + // + // TokenRegistryV2 tokenRegistryV2 = TokenRegistryV2(address(tokenRegistry)); + // address usdc = tokenRegistry.getTokenAddress(0, "USDC"); + + vm.stopBroadcast(); + + console.log("Core implementation deployed at: %s", address(coreImpl)); + console.log("---- DONE ----"); + } +} diff --git a/packages/contracts/script/XX_UpgradeTokenRegistry.s.sol b/packages/contracts/script/UpgradeTokenRegistry.s.sol similarity index 96% rename from packages/contracts/script/XX_UpgradeTokenRegistry.s.sol rename to packages/contracts/script/UpgradeTokenRegistry.s.sol index 59b7ab91..d0d07313 100644 --- a/packages/contracts/script/XX_UpgradeTokenRegistry.s.sol +++ b/packages/contracts/script/UpgradeTokenRegistry.s.sol @@ -6,9 +6,8 @@ import "forge-std/Script.sol"; import "forge-std/console.sol"; import "../src/utils/TokenRegistry.sol"; -contract Deploy is Script { +contract Upgrade is Script { function run() external { - uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY"); if (deployerPrivateKey == 0) { console.log("PRIVATE_KEY env var not set"); @@ -34,7 +33,7 @@ contract Deploy is Script { // // TokenRegistryV2 tokenRegistryV2 = TokenRegistryV2(address(tokenRegistry)); // address usdc = tokenRegistry.getTokenAddress(0, "USDC"); - + vm.stopBroadcast(); console.log("TokenRegistry implementation deployed at: %s", address(tokenRegistryImpl));