From 32d5a6362d0b6e7d512b7a2e12aa82e10147ce6c Mon Sep 17 00:00:00 2001 From: zmalatrax Date: Sun, 3 Sep 2023 11:56:38 +0200 Subject: [PATCH] feat(proxy): add selective upgrade scripts --- contracts/deploy/upgrade-kleros-core.ts | 89 ++++++++++++++++++++ contracts/deploy/upgrade-sortition-module.ts | 72 ++++++++++++++++ 2 files changed, 161 insertions(+) create mode 100644 contracts/deploy/upgrade-kleros-core.ts create mode 100644 contracts/deploy/upgrade-sortition-module.ts diff --git a/contracts/deploy/upgrade-kleros-core.ts b/contracts/deploy/upgrade-kleros-core.ts new file mode 100644 index 000000000..54c50269e --- /dev/null +++ b/contracts/deploy/upgrade-kleros-core.ts @@ -0,0 +1,89 @@ +import { HardhatRuntimeEnvironment } from "hardhat/types"; +import { DeployFunction } from "hardhat-deploy/types"; +import { BigNumber } from "ethers"; +import getContractAddress from "../deploy-helpers/getContractAddress"; +import { get } from "http"; + +enum HomeChains { + ARBITRUM_ONE = 42161, + ARBITRUM_GOERLI = 421613, + HARDHAT = 31337, +} + +const deployUpgradeKlerosCore: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { + const { ethers, deployments, getNamedAccounts, getChainId } = hre; + const { deploy, execute } = deployments; + const { AddressZero } = hre.ethers.constants; + const RNG_LOOKAHEAD = 20; + + // fallback to hardhat node signers on local network + const deployer = (await getNamedAccounts()).deployer ?? (await hre.ethers.getSigners())[0].address; + const chainId = Number(await getChainId()); + console.log("Upgrading to %s with deployer %s", HomeChains[chainId], deployer); + + try { + const pnk = await deployments.get("PNK"); + + const dai = await deployments.get("DAI"); + + const weth = await deployments.get("WETH"); + + const rng = await deployments.get("RandomizerRNG"); + + const disputeKit = await deployments.get("DisputeKitClassic"); + + const minStake = BigNumber.from(10).pow(20).mul(2); + const alpha = 10000; + const feeForJuror = BigNumber.from(10).pow(17); + + // console.log("Upgrading the SortitionModule..."); + // const sortitionModuleDeployment = await deployments.get("SortitionModule") + const sortitionModuleDeployment = await deployments.get("SortitionModule"); + + console.log("Upgrading the KlerosCore..."); + const klerosCoreDeploymenent = await deploy("KlerosCore", { + from: deployer, + proxy: { + proxyContract: "UUPSProxy", + proxyArgs: ["{implementation}", "{data}"], + checkProxyAdmin: false, + checkABIConflict: false, + execute: { + init: { + methodName: "initialize", + args: [ + deployer, + pnk, + AddressZero, + disputeKit.address, + false, + [minStake, alpha, feeForJuror, 256], // minStake, alpha, feeForJuror, jurorsForCourtJump + [0, 0, 0, 10], // evidencePeriod, commitPeriod, votePeriod, appealPeriod + ethers.utils.hexlify(5), // Extra data for sortition module will return the default value of K + sortitionModuleDeployment.address, + ], + }, + // Workaround to bypass the current version of hardhat-deploy which fallback on `upgradeTo` when no updateMethod is defined + // To be replaced by `initialize` or any new function when upgrading while initializing again the proxy storage (reinitializer(uint version) modifier) + onUpgrade: { + methodName: "governor", + args: [], + }, + }, + }, + args: [], + log: true, + }); + } catch (err) { + console.error(err); + throw err; + } +}; + +deployUpgradeKlerosCore.tags = ["Upgrade", "KlerosCore"]; +deployUpgradeKlerosCore.skip = async ({ getChainId }) => { + const chainId = Number(await getChainId()); + return !HomeChains[chainId]; +}; + +export default deployUpgradeKlerosCore; diff --git a/contracts/deploy/upgrade-sortition-module.ts b/contracts/deploy/upgrade-sortition-module.ts new file mode 100644 index 000000000..310ff948d --- /dev/null +++ b/contracts/deploy/upgrade-sortition-module.ts @@ -0,0 +1,72 @@ +import { HardhatRuntimeEnvironment } from "hardhat/types"; +import { DeployFunction } from "hardhat-deploy/types"; +import { BigNumber } from "ethers"; +import getContractAddress from "../deploy-helpers/getContractAddress"; +import { get } from "http"; + +enum HomeChains { + ARBITRUM_ONE = 42161, + ARBITRUM_GOERLI = 421613, + HARDHAT = 31337, +} + +const deployUpgradeSortitionModule: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { + const { ethers, deployments, getNamedAccounts, getChainId } = hre; + const { deploy, execute } = deployments; + const { AddressZero } = hre.ethers.constants; + const RNG_LOOKAHEAD = 20; + + // fallback to hardhat node signers on local network + const deployer = (await getNamedAccounts()).deployer ?? (await hre.ethers.getSigners())[0].address; + const chainId = Number(await getChainId()); + console.log("Upgrading to %s with deployer %s", HomeChains[chainId], deployer); + + try { + const pnk = await deployments.get("PNK"); + + const dai = await deployments.get("DAI"); + + const weth = await deployments.get("WETH"); + + const rng = await deployments.get("RandomizerRNG"); + + const klerosCore = await deployments.get("KlerosCore"); + const KlerosCoreAddress = klerosCore.address; + + console.log("Upgrading the SortitionModule..."); + const sortitionModuleDeployment = await deploy("SortitionModule", { + from: deployer, + proxy: { + proxyContract: "UUPSProxy", + proxyArgs: ["{implementation}", "{data}"], + checkProxyAdmin: false, + checkABIConflict: false, + execute: { + init: { + methodName: "initialize", + args: [deployer, KlerosCoreAddress, 1800, 1800, rng.address, RNG_LOOKAHEAD], // minStakingTime, maxFreezingTime + }, + // Workaround to bypass the current version of hardhat-deploy which fallback on `upgradeTo` when no updateMethod is defined + // To be replaced by `initialize` or any new function when upgrading while initializing again the proxy storage (reinitializer(uint version) modifier) + onUpgrade: { + methodName: "governor", + args: [], + }, + }, + }, + log: true, + args: [], + }); + } catch (err) { + console.error(err); + throw err; + } +}; + +deployUpgradeSortitionModule.tags = ["Upgrade", "SortitionModule"]; +deployUpgradeSortitionModule.skip = async ({ getChainId }) => { + const chainId = Number(await getChainId()); + return !HomeChains[chainId]; +}; + +export default deployUpgradeSortitionModule;