|
| 1 | +import { HardhatRuntimeEnvironment } from "hardhat/types"; |
| 2 | +import { DeployFunction } from "hardhat-deploy/types"; |
| 3 | +import { BigNumber } from "ethers"; |
| 4 | +import getContractAddress from "../deploy-helpers/getContractAddress"; |
| 5 | +import { get } from "http"; |
| 6 | + |
| 7 | +enum HomeChains { |
| 8 | + ARBITRUM_ONE = 42161, |
| 9 | + ARBITRUM_GOERLI = 421613, |
| 10 | + HARDHAT = 31337, |
| 11 | +} |
| 12 | + |
| 13 | +const deployUpgradeKlerosCore: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { |
| 14 | + const { ethers, deployments, getNamedAccounts, getChainId } = hre; |
| 15 | + const { deploy, execute } = deployments; |
| 16 | + const { AddressZero } = hre.ethers.constants; |
| 17 | + const RNG_LOOKAHEAD = 20; |
| 18 | + |
| 19 | + // fallback to hardhat node signers on local network |
| 20 | + const deployer = (await getNamedAccounts()).deployer ?? (await hre.ethers.getSigners())[0].address; |
| 21 | + const chainId = Number(await getChainId()); |
| 22 | + console.log("Upgrading to %s with deployer %s", HomeChains[chainId], deployer); |
| 23 | + |
| 24 | + try { |
| 25 | + const pnk = await deployments.get("PNK"); |
| 26 | + |
| 27 | + const dai = await deployments.get("DAI"); |
| 28 | + |
| 29 | + const weth = await deployments.get("WETH"); |
| 30 | + |
| 31 | + const rng = await deployments.get("RandomizerRNG"); |
| 32 | + |
| 33 | + const disputeKit = await deployments.get("DisputeKitClassic"); |
| 34 | + |
| 35 | + const minStake = BigNumber.from(10).pow(20).mul(2); |
| 36 | + const alpha = 10000; |
| 37 | + const feeForJuror = BigNumber.from(10).pow(17); |
| 38 | + |
| 39 | + // console.log("Upgrading the SortitionModule..."); |
| 40 | + // const sortitionModuleDeployment = await deployments.get("SortitionModule") |
| 41 | + const sortitionModuleDeployment = await deployments.get("SortitionModule"); |
| 42 | + |
| 43 | + console.log("Upgrading the KlerosCore..."); |
| 44 | + const klerosCoreDeploymenent = await deploy("KlerosCore", { |
| 45 | + from: deployer, |
| 46 | + proxy: { |
| 47 | + proxyContract: "UUPSProxy", |
| 48 | + proxyArgs: ["{implementation}", "{data}"], |
| 49 | + checkProxyAdmin: false, |
| 50 | + checkABIConflict: false, |
| 51 | + execute: { |
| 52 | + init: { |
| 53 | + methodName: "initialize", |
| 54 | + args: [ |
| 55 | + deployer, |
| 56 | + pnk, |
| 57 | + AddressZero, |
| 58 | + disputeKit.address, |
| 59 | + false, |
| 60 | + [minStake, alpha, feeForJuror, 256], // minStake, alpha, feeForJuror, jurorsForCourtJump |
| 61 | + [0, 0, 0, 10], // evidencePeriod, commitPeriod, votePeriod, appealPeriod |
| 62 | + ethers.utils.hexlify(5), // Extra data for sortition module will return the default value of K |
| 63 | + sortitionModuleDeployment.address, |
| 64 | + ], |
| 65 | + }, |
| 66 | + // Workaround to bypass the current version of hardhat-deploy which fallback on `upgradeTo` when no updateMethod is defined |
| 67 | + // To be replaced by `initialize` or any new function when upgrading while initializing again the proxy storage (reinitializer(uint version) modifier) |
| 68 | + onUpgrade: { |
| 69 | + methodName: "governor", |
| 70 | + args: [], |
| 71 | + }, |
| 72 | + }, |
| 73 | + }, |
| 74 | + args: [], |
| 75 | + log: true, |
| 76 | + }); |
| 77 | + } catch (err) { |
| 78 | + console.error(err); |
| 79 | + throw err; |
| 80 | + } |
| 81 | +}; |
| 82 | + |
| 83 | +deployUpgradeKlerosCore.tags = ["Upgrade", "KlerosCore"]; |
| 84 | +deployUpgradeKlerosCore.skip = async ({ getChainId }) => { |
| 85 | + const chainId = Number(await getChainId()); |
| 86 | + return !HomeChains[chainId]; |
| 87 | +}; |
| 88 | + |
| 89 | +export default deployUpgradeKlerosCore; |
0 commit comments