diff --git a/contracts/deploy/00-ethereum-pnk.ts b/contracts/deploy/00-ethereum-pnk.ts index 29d6a51b3..002237ef8 100644 --- a/contracts/deploy/00-ethereum-pnk.ts +++ b/contracts/deploy/00-ethereum-pnk.ts @@ -1,6 +1,7 @@ import { HardhatRuntimeEnvironment } from "hardhat/types"; import { DeployFunction } from "hardhat-deploy/types"; import disputeTemplate from "../test/fixtures/DisputeTemplate.simple.json"; +import { isSkipped } from "./utils"; enum Chains { GOERLI = 5, @@ -24,9 +25,8 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment) }; deployArbitration.tags = ["Pinakion"]; -deployArbitration.skip = async ({ getChainId }) => { - const chainId = Number(await getChainId()); - return !Chains[chainId]; +deployArbitration.skip = async ({ network }) => { + return isSkipped(network, !Chains[network.config.chainId ?? 0]); }; export default deployArbitration; diff --git a/contracts/deploy/00-home-chain-arbitrable.ts b/contracts/deploy/00-home-chain-arbitrable.ts index fe319dcd1..6370302b4 100644 --- a/contracts/deploy/00-home-chain-arbitrable.ts +++ b/contracts/deploy/00-home-chain-arbitrable.ts @@ -1,12 +1,7 @@ import { HardhatRuntimeEnvironment } from "hardhat/types"; import { DeployFunction } from "hardhat-deploy/types"; import disputeTemplate from "../test/fixtures/DisputeTemplate.simple.json"; - -enum HomeChains { - ARBITRUM_ONE = 42161, - ARBITRUM_GOERLI = 421613, - HARDHAT = 31337, -} +import { HomeChains, isSkipped } from "./utils"; const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { const { deployments, getNamedAccounts, getChainId } = hre; @@ -50,9 +45,8 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment) deployArbitration.tags = ["HomeArbitrable"]; deployArbitration.dependencies = ["Arbitration"]; -deployArbitration.skip = async ({ getChainId }) => { - const chainId = Number(await getChainId()); - return !HomeChains[chainId]; +deployArbitration.skip = async ({ network }) => { + return isSkipped(network, !HomeChains[network.config.chainId ?? 0]); }; export default deployArbitration; diff --git a/contracts/deploy/00-home-chain-arbitration.ts b/contracts/deploy/00-home-chain-arbitration.ts index b76d21793..311cc8867 100644 --- a/contracts/deploy/00-home-chain-arbitration.ts +++ b/contracts/deploy/00-home-chain-arbitration.ts @@ -1,13 +1,9 @@ import { HardhatRuntimeEnvironment } from "hardhat/types"; import { DeployFunction } from "hardhat-deploy/types"; import { BigNumber } from "ethers"; -import getContractAddress from "../deploy-helpers/getContractAddress"; - -enum HomeChains { - ARBITRUM_ONE = 42161, - ARBITRUM_GOERLI = 421613, - HARDHAT = 31337, -} +import getContractAddress from "./utils/getContractAddress"; +import { deployUpgradable } from "./utils/deployUpgradable"; +import { HomeChains, isSkipped } from "./utils"; const pnkByChain = new Map([ [HomeChains.ARBITRUM_ONE, "0x330bD769382cFc6d50175903434CCC8D206DCAE5"], @@ -63,51 +59,25 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment) }); const randomizer = randomizerByChain.get(Number(await getChainId())) ?? AddressZero; - const rng = await deploy("RandomizerRNG", { - skipIfAlreadyDeployed: true, - from: deployer, - args: [randomizer, deployer], - log: true, - }); - - const disputeKit = await deploy("DisputeKitClassic", { - from: deployer, - args: [deployer, AddressZero], - log: true, - }); + const rng = await deployUpgradable(hre, deployer, "RandomizerRNG", [randomizer, deployer]); - let nonce; - let KlerosCoreAddress; + const disputeKit = await deployUpgradable(hre, deployer, "DisputeKitClassic", [deployer, AddressZero]); - const klerosCoreDeployment = await deployments.getOrNull("KlerosCore"); - if (!klerosCoreDeployment) { - nonce = await ethers.provider.getTransactionCount(deployer); - KlerosCoreAddress = getContractAddress(deployer, nonce + 3); // Deploying an upgradeable version of SortionModule requires 2 transactions instead of 1 (implementation then proxy) - console.log("calculated future KlerosCore address for nonce %d: %s", nonce, KlerosCoreAddress); - } else { - KlerosCoreAddress = klerosCoreDeployment.address; + let klerosCoreAddress = await deployments.getOrNull("KlerosCore").then((deployment) => deployment?.address); + if (!klerosCoreAddress) { + const nonce = await ethers.provider.getTransactionCount(deployer); + klerosCoreAddress = getContractAddress(deployer, nonce + 3); // Deploying an upgradeable version of SortitionModule requires 2 transactions instead of 1 (implementation then proxy) + console.log("calculated future KlerosCore address for nonce %d: %s", nonce, klerosCoreAddress); } - const sortitionModule = 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 - }, - onUpgrade: { - methodName: "governor", - args: [], - }, - }, - }, - log: true, - }); + const sortitionModule = await deployUpgradable(hre, deployer, "SortitionModule", [ + deployer, + klerosCoreAddress, + 1800, // minStakingTime + 1800, // maxFreezingTime + rng.address, + RNG_LOOKAHEAD, + ]); const pnk = pnkByChain.get(chainId) ?? AddressZero; const dai = daiByChain.get(chainId) ?? AddressZero; @@ -115,37 +85,17 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment) const minStake = BigNumber.from(10).pow(20).mul(2); const alpha = 10000; const feeForJuror = BigNumber.from(10).pow(17); - const klerosCore = 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 - sortitionModule.address, - ], - }, - onUpgrade: { - methodName: "governor", - args: [], - }, - }, - }, - args: [], - log: true, - }); + const klerosCore = await deployUpgradable(hre, deployer, "KlerosCore", [ + 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 + sortitionModule.address, + ]); // execute DisputeKitClassic.changeCore() only if necessary const currentCore = await hre.ethers.getContractAt("DisputeKitClassic", disputeKit.address).then((dk) => dk.core()); @@ -163,9 +113,8 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment) }; deployArbitration.tags = ["Arbitration"]; -deployArbitration.skip = async ({ getChainId }) => { - const chainId = Number(await getChainId()); - return !HomeChains[chainId]; +deployArbitration.skip = async ({ network }) => { + return isSkipped(network, !HomeChains[network.config.chainId ?? 0]); }; const deployERC20AndFaucet = async (hre: HardhatRuntimeEnvironment, deployer: string, ticker: string) => { diff --git a/contracts/deploy/00-home-chain-pnk-faucet.ts b/contracts/deploy/00-home-chain-pnk-faucet.ts index 8760614f3..3b5c983be 100644 --- a/contracts/deploy/00-home-chain-pnk-faucet.ts +++ b/contracts/deploy/00-home-chain-pnk-faucet.ts @@ -1,11 +1,6 @@ import { HardhatRuntimeEnvironment } from "hardhat/types"; import { DeployFunction } from "hardhat-deploy/types"; - -enum HomeChains { - ARBITRUM_ONE = 42161, - ARBITRUM_GOERLI = 421613, - HARDHAT = 31337, -} +import { HomeChains, isSkipped } from "./utils"; const pnkByChain = new Map([ [HomeChains.ARBITRUM_ONE, "0x330bD769382cFc6d50175903434CCC8D206DCAE5"], @@ -39,9 +34,8 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment) }; deployArbitration.tags = ["PnkFaucet"]; -deployArbitration.skip = async ({ getChainId }) => { - const chainId = Number(await getChainId()); - return !HomeChains[chainId]; +deployArbitration.skip = async ({ network }) => { + return isSkipped(network, !HomeChains[network.config.chainId ?? 0]); }; export default deployArbitration; diff --git a/contracts/deploy/00-rng.ts b/contracts/deploy/00-rng.ts index 0c2f79940..065c24fa6 100644 --- a/contracts/deploy/00-rng.ts +++ b/contracts/deploy/00-rng.ts @@ -1,12 +1,7 @@ import { HardhatRuntimeEnvironment } from "hardhat/types"; import { DeployFunction } from "hardhat-deploy/types"; import { SortitionModule, RandomizerRNG } from "../typechain-types"; - -enum HomeChains { - ARBITRUM_ONE = 42161, - ARBITRUM_GOERLI = 421613, - HARDHAT = 31337, -} +import { HomeChains, isSkipped } from "./utils"; const pnkByChain = new Map([ [HomeChains.ARBITRUM_ONE, "0x330bD769382cFc6d50175903434CCC8D206DCAE5"], @@ -63,9 +58,8 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment) }; deployArbitration.tags = ["RNG"]; -deployArbitration.skip = async ({ getChainId }) => { - const chainId = Number(await getChainId()); - return !HomeChains[chainId]; +deployArbitration.skip = async ({ network }) => { + return isSkipped(network, !HomeChains[network.config.chainId ?? 0]); }; export default deployArbitration; diff --git a/contracts/deploy/01-foreign-gateway-on-ethereum.ts b/contracts/deploy/01-foreign-gateway-on-ethereum.ts index 1304fec72..16a67ccb0 100644 --- a/contracts/deploy/01-foreign-gateway-on-ethereum.ts +++ b/contracts/deploy/01-foreign-gateway-on-ethereum.ts @@ -1,12 +1,8 @@ import { HardhatRuntimeEnvironment } from "hardhat/types"; import { DeployFunction } from "hardhat-deploy/types"; -import getContractAddress from "../deploy-helpers/getContractAddress"; +import getContractAddress from "./utils/getContractAddress"; import { KlerosCore__factory } from "../typechain-types"; - -enum ForeignChains { - ETHEREUM_MAINNET = 1, - ETHEREUM_GOERLI = 5, -} +import { ForeignChains, HardhatChain, isSkipped } from "./utils"; const deployForeignGateway: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { const { ethers, deployments, getNamedAccounts, getChainId, config } = hre; @@ -56,9 +52,8 @@ const deployForeignGateway: DeployFunction = async (hre: HardhatRuntimeEnvironme }; deployForeignGateway.tags = ["ForeignGatewayOnEthereum"]; -deployForeignGateway.skip = async ({ getChainId }) => { - const chainId = Number(await getChainId()); - return !ForeignChains[chainId]; +deployForeignGateway.skip = async ({ network }) => { + return isSkipped(network, !ForeignChains[network.config.chainId ?? 0]); }; export default deployForeignGateway; diff --git a/contracts/deploy/01-foreign-gateway-on-gnosis.ts b/contracts/deploy/01-foreign-gateway-on-gnosis.ts index a9e33e708..ec57be903 100644 --- a/contracts/deploy/01-foreign-gateway-on-gnosis.ts +++ b/contracts/deploy/01-foreign-gateway-on-gnosis.ts @@ -1,14 +1,9 @@ import { parseUnits } from "ethers/lib/utils"; import { HardhatRuntimeEnvironment } from "hardhat/types"; import { DeployFunction } from "hardhat-deploy/types"; -import getContractAddress from "../deploy-helpers/getContractAddress"; +import getContractAddress from "./utils/getContractAddress"; import { KlerosCore__factory } from "../typechain-types"; - -enum ForeignChains { - GNOSIS_MAINNET = 100, - GNOSIS_CHIADO = 10200, - HARDHAT = 31337, -} +import { ForeignChains, isSkipped } from "./utils"; const ONE_GWEI = parseUnits("1", "gwei"); @@ -62,9 +57,8 @@ const deployForeignGateway: DeployFunction = async (hre: HardhatRuntimeEnvironme }; deployForeignGateway.tags = ["ForeignGatewayOnGnosis"]; -deployForeignGateway.skip = async ({ getChainId }) => { - const chainId = Number(await getChainId()); - return !ForeignChains[chainId]; +deployForeignGateway.skip = async ({ network }) => { + return isSkipped(network, !ForeignChains[network.config.chainId ?? 0]); }; export default deployForeignGateway; diff --git a/contracts/deploy/02-home-gateway-to-ethereum.ts b/contracts/deploy/02-home-gateway-to-ethereum.ts index be6defecc..596b3e1c6 100644 --- a/contracts/deploy/02-home-gateway-to-ethereum.ts +++ b/contracts/deploy/02-home-gateway-to-ethereum.ts @@ -1,11 +1,7 @@ import { HardhatRuntimeEnvironment } from "hardhat/types"; import { DeployFunction } from "hardhat-deploy/types"; import { ethers } from "hardhat"; - -enum HomeChains { - ARBITRUM_ONE = 42161, - ARBITRUM_GOERLI = 421613, -} +import { HardhatChain, HomeChains, isSkipped } from "./utils"; // TODO: use deterministic deployments @@ -42,9 +38,9 @@ const deployHomeGateway: DeployFunction = async (hre: HardhatRuntimeEnvironment) }; deployHomeGateway.tags = ["HomeGatewayToEthereum"]; -deployHomeGateway.skip = async ({ getChainId }) => { - const chainId = Number(await getChainId()); - return !HomeChains[chainId]; +deployHomeGateway.skip = async ({ network }) => { + const chainId = network.config.chainId ?? 0; + return isSkipped(network, !HomeChains[chainId] || HardhatChain[chainId] !== undefined); }; export default deployHomeGateway; diff --git a/contracts/deploy/02-home-gateway-to-gnosis.ts b/contracts/deploy/02-home-gateway-to-gnosis.ts index 7baaf71b0..5184007b5 100644 --- a/contracts/deploy/02-home-gateway-to-gnosis.ts +++ b/contracts/deploy/02-home-gateway-to-gnosis.ts @@ -1,10 +1,6 @@ import { HardhatRuntimeEnvironment } from "hardhat/types"; import { DeployFunction } from "hardhat-deploy/types"; - -enum HomeChains { - ARBITRUM_ONE = 42161, - ARBITRUM_GOERLI = 421613, -} +import { HardhatChain, HomeChains, isSkipped } from "./utils"; // TODO: use deterministic deployments @@ -35,9 +31,9 @@ const deployHomeGateway: DeployFunction = async (hre: HardhatRuntimeEnvironment) }; deployHomeGateway.tags = ["HomeGatewayToGnosis"]; -deployHomeGateway.skip = async ({ getChainId }) => { - const chainId = Number(await getChainId()); - return !HomeChains[chainId]; +deployHomeGateway.skip = async ({ network }) => { + const chainId = network.config.chainId ?? 0; + return isSkipped(network, !HomeChains[chainId] || HardhatChain[chainId] !== undefined); }; export default deployHomeGateway; diff --git a/contracts/deploy/03-vea-mock.ts b/contracts/deploy/03-vea-mock.ts index d7e09f550..aef1fb400 100644 --- a/contracts/deploy/03-vea-mock.ts +++ b/contracts/deploy/03-vea-mock.ts @@ -1,10 +1,9 @@ import { HardhatRuntimeEnvironment } from "hardhat/types"; import { DeployFunction } from "hardhat-deploy/types"; -import getContractAddress from "../deploy-helpers/getContractAddress"; +import getContractAddress from "./utils/getContractAddress"; import { KlerosCore__factory } from "../typechain-types"; import disputeTemplate from "../test/fixtures/DisputeTemplate.simple.json"; - -const HARDHAT_NETWORK = 31337; +import { HardhatChain, isSkipped } from "./utils"; // TODO: use deterministic deployments @@ -15,7 +14,7 @@ const deployHomeGateway: DeployFunction = async (hre: HardhatRuntimeEnvironment) // fallback to hardhat node signers on local network const deployer = (await getNamedAccounts()).deployer ?? (await hre.ethers.getSigners())[0].address; - console.log("Deploying to chainId %s with deployer %s", HARDHAT_NETWORK, deployer); + console.log("Deploying to chainId %s with deployer %s", HardhatChain.HARDHAT, deployer); const klerosCore = await deployments.get("KlerosCore"); @@ -28,7 +27,7 @@ const deployHomeGateway: DeployFunction = async (hre: HardhatRuntimeEnvironment) const homeGatewayAddress = getContractAddress(deployer, nonce + 1); console.log("Calculated future HomeGatewayToEthereum address for nonce %d: %s", nonce, homeGatewayAddress); - const homeChainIdAsBytes32 = hexZeroPad(hexlify(HARDHAT_NETWORK), 32); + const homeChainIdAsBytes32 = hexZeroPad(hexlify(HardhatChain.HARDHAT), 32); const foreignGateway = await deploy("ForeignGatewayOnEthereum", { from: deployer, contract: "ForeignGateway", @@ -44,7 +43,7 @@ const deployHomeGateway: DeployFunction = async (hre: HardhatRuntimeEnvironment) deployer, klerosCore.address, vea.address, - HARDHAT_NETWORK, + HardhatChain.HARDHAT, foreignGateway.address, ethers.constants.AddressZero, // feeToken ], @@ -86,6 +85,8 @@ const deployHomeGateway: DeployFunction = async (hre: HardhatRuntimeEnvironment) }; deployHomeGateway.tags = ["VeaMock"]; -deployHomeGateway.skip = async ({ getChainId }) => HARDHAT_NETWORK !== Number(await getChainId()); +deployHomeGateway.skip = async ({ network }) => { + return isSkipped(network, HardhatChain[network.config.chainId ?? 0] === undefined); +}; export default deployHomeGateway; diff --git a/contracts/deploy/04-foreign-arbitrable.ts b/contracts/deploy/04-foreign-arbitrable.ts index c0918c2ae..801c507af 100644 --- a/contracts/deploy/04-foreign-arbitrable.ts +++ b/contracts/deploy/04-foreign-arbitrable.ts @@ -2,13 +2,7 @@ import { HardhatRuntimeEnvironment } from "hardhat/types"; import { DeployFunction } from "hardhat-deploy/types"; import { parseUnits } from "ethers/lib/utils"; import disputeTemplate from "../test/fixtures/DisputeTemplate.simple.json"; - -enum ForeignChains { - ETHEREUM_MAINNET = 1, - ETHEREUM_GOERLI = 5, - GNOSIS_MAINNET = 100, - GNOSIS_CHIADO = 10200, -} +import { ForeignChains, isSkipped } from "./utils"; const foreignGatewayArtifactByChain = new Map([ [ForeignChains.ETHEREUM_MAINNET, "ForeignGatewayOnEthereum"], @@ -65,9 +59,8 @@ const deployForeignGateway: DeployFunction = async (hre: HardhatRuntimeEnvironme }; deployForeignGateway.tags = ["ForeignArbitrable"]; -deployForeignGateway.skip = async ({ getChainId }) => { - const chainId = Number(await getChainId()); - return !ForeignChains[chainId]; +deployForeignGateway.skip = async ({ network }) => { + return isSkipped(network, !ForeignChains[network.config.chainId ?? 0]); }; export default deployForeignGateway; diff --git a/contracts/deploy/04-klerosliquid-to-v2-gnosis.ts b/contracts/deploy/04-klerosliquid-to-v2-gnosis.ts index bc8c2bb18..0366f74ef 100644 --- a/contracts/deploy/04-klerosliquid-to-v2-gnosis.ts +++ b/contracts/deploy/04-klerosliquid-to-v2-gnosis.ts @@ -2,12 +2,7 @@ import { parseUnits, parseEther } from "ethers/lib/utils"; import { HardhatRuntimeEnvironment } from "hardhat/types"; import { DeployFunction } from "hardhat-deploy/types"; import disputeTemplate from "../test/fixtures/DisputeTemplate.simple.json"; - -enum ForeignChains { - GNOSIS_MAINNET = 100, - GNOSIS_CHIADO = 10200, - HARDHAT = 31337, -} +import { ForeignChains, isSkipped } from "./utils"; const wrappedPNKByChain = new Map([ [ForeignChains.GNOSIS_MAINNET, "0xcb3231aBA3b451343e0Fddfc45883c842f223846"], @@ -148,9 +143,8 @@ const deployKlerosLiquid: DeployFunction = async (hre: HardhatRuntimeEnvironment // }; deployKlerosLiquid.tags = ["KlerosLiquidOnGnosis"]; -deployKlerosLiquid.skip = async ({ getChainId }) => { - const chainId = Number(await getChainId()); - return !ForeignChains[chainId]; +deployKlerosLiquid.skip = async ({ network }) => { + return isSkipped(network, !ForeignChains[network.config.chainId ?? 0]); }; export default deployKlerosLiquid; diff --git a/contracts/deploy/fix1148.ts b/contracts/deploy/fix1148.ts index de31fa993..446464398 100644 --- a/contracts/deploy/fix1148.ts +++ b/contracts/deploy/fix1148.ts @@ -2,6 +2,7 @@ import { HardhatRuntimeEnvironment } from "hardhat/types"; import { DeployFunction } from "hardhat-deploy/types"; import { DisputeKitClassic, KlerosCore, SortitionModule } from "../typechain-types"; import assert from "node:assert"; +import { isSkipped } from "./utils"; enum HomeChains { ARBITRUM_ONE = 42161, @@ -55,9 +56,8 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment) }; deployArbitration.tags = ["Fix1148"]; -deployArbitration.skip = async ({ getChainId }) => { - const chainId = Number(await getChainId()); - return !HomeChains[chainId]; +deployArbitration.skip = async ({ network }) => { + return isSkipped(network, !HomeChains[network.config.chainId ?? 0]); }; export default deployArbitration; diff --git a/contracts/deploy/upgrade-kleros-core.ts b/contracts/deploy/upgrade-kleros-core.ts index 54c50269e..bd1cc1259 100644 --- a/contracts/deploy/upgrade-kleros-core.ts +++ b/contracts/deploy/upgrade-kleros-core.ts @@ -1,8 +1,8 @@ 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"; +import { deployUpgradable } from "./utils/deployUpgradable"; +import { isSkipped } from "./utils"; enum HomeChains { ARBITRUM_ONE = 42161, @@ -12,9 +12,7 @@ enum HomeChains { 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; @@ -23,57 +21,24 @@ const deployUpgradeKlerosCore: DeployFunction = async (hre: HardhatRuntimeEnviro 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"); + const sortitionModule = 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, - }); + await deployUpgradable(hre, deployer, "KlerosCore", [ + 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 + sortitionModule.address, + ]); } catch (err) { console.error(err); throw err; @@ -81,9 +46,8 @@ const deployUpgradeKlerosCore: DeployFunction = async (hre: HardhatRuntimeEnviro }; deployUpgradeKlerosCore.tags = ["Upgrade", "KlerosCore"]; -deployUpgradeKlerosCore.skip = async ({ getChainId }) => { - const chainId = Number(await getChainId()); - return !HomeChains[chainId]; +deployUpgradeKlerosCore.skip = async ({ network }) => { + return isSkipped(network, !HomeChains[network.config.chainId ?? 0]); }; export default deployUpgradeKlerosCore; diff --git a/contracts/deploy/upgrade-sortition-module.ts b/contracts/deploy/upgrade-sortition-module.ts index 310ff948d..e431b78f9 100644 --- a/contracts/deploy/upgrade-sortition-module.ts +++ b/contracts/deploy/upgrade-sortition-module.ts @@ -1,8 +1,7 @@ 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"; +import { deployUpgradable } from "./utils/deployUpgradable"; +import { isSkipped } from "./utils"; enum HomeChains { ARBITRUM_ONE = 42161, @@ -11,9 +10,7 @@ enum HomeChains { } const deployUpgradeSortitionModule: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { - const { ethers, deployments, getNamedAccounts, getChainId } = hre; - const { deploy, execute } = deployments; - const { AddressZero } = hre.ethers.constants; + const { deployments, getNamedAccounts, getChainId } = hre; const RNG_LOOKAHEAD = 20; // fallback to hardhat node signers on local network @@ -22,41 +19,19 @@ const deployUpgradeSortitionModule: DeployFunction = async (hre: HardhatRuntimeE 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; + 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: [], - }); + await deployUpgradable(hre, deployer, "SortitionModule", [ + deployer, + klerosCoreAddress, + 1800, // minStakingTime + 1800, // maxFreezingTime + rng.address, + RNG_LOOKAHEAD, + ]); } catch (err) { console.error(err); throw err; @@ -64,9 +39,8 @@ const deployUpgradeSortitionModule: DeployFunction = async (hre: HardhatRuntimeE }; deployUpgradeSortitionModule.tags = ["Upgrade", "SortitionModule"]; -deployUpgradeSortitionModule.skip = async ({ getChainId }) => { - const chainId = Number(await getChainId()); - return !HomeChains[chainId]; +deployUpgradeSortitionModule.skip = async ({ network }) => { + return isSkipped(network, !HomeChains[network.config.chainId ?? 0]); }; export default deployUpgradeSortitionModule; diff --git a/contracts/deploy/utils/deployUpgradable.ts b/contracts/deploy/utils/deployUpgradable.ts new file mode 100644 index 000000000..3402f18c2 --- /dev/null +++ b/contracts/deploy/utils/deployUpgradable.ts @@ -0,0 +1,31 @@ +import { DeployResult } from "hardhat-deploy/types"; +import { HardhatRuntimeEnvironment } from "hardhat/types"; + +export function deployUpgradable( + hre: HardhatRuntimeEnvironment, + deployer: string, + contract: string, + params: any[] +): Promise { + const { deploy } = hre.deployments; + return deploy(contract, { + from: deployer, + proxy: { + proxyContract: "UUPSProxy", + proxyArgs: ["{implementation}", "{data}"], + checkProxyAdmin: false, + checkABIConflict: false, + execute: { + init: { + methodName: "initialize", + args: params, + }, + onUpgrade: { + methodName: "governor", + args: [], + }, + }, + }, + log: true, + }); +} diff --git a/contracts/deploy-helpers/getContractAddress.js b/contracts/deploy/utils/getContractAddress.js similarity index 100% rename from contracts/deploy-helpers/getContractAddress.js rename to contracts/deploy/utils/getContractAddress.js diff --git a/contracts/deploy/utils/index.ts b/contracts/deploy/utils/index.ts new file mode 100644 index 000000000..2c5cfdd8c --- /dev/null +++ b/contracts/deploy/utils/index.ts @@ -0,0 +1,29 @@ +import { Network } from "hardhat/types"; + +// TODO: derive this from hardhat.config and make it rely on viem/chains + +export enum HardhatChain { + HARDHAT = 31337, +} + +export enum HomeChains { + ARBITRUM_ONE = 42161, + ARBITRUM_GOERLI = 421613, + HARDHAT = HardhatChain.HARDHAT, +} + +export enum ForeignChains { + ETHEREUM_MAINNET = 1, + ETHEREUM_GOERLI = 5, + GNOSIS_MAINNET = 100, + GNOSIS_CHIADO = 10200, + HARDHAT = HardhatChain.HARDHAT, +} + +export const isSkipped = async (network: Network, skip: boolean) => { + if (skip) { + console.error(`Error: incompatible network ${network.name} for this deployment script`); + return true; + } + return false; +}; diff --git a/contracts/src/arbitration/dispute-kits/BaseDisputeKit.sol b/contracts/src/arbitration/dispute-kits/BaseDisputeKit.sol deleted file mode 100644 index 878cf99bf..000000000 --- a/contracts/src/arbitration/dispute-kits/BaseDisputeKit.sol +++ /dev/null @@ -1,68 +0,0 @@ -// SPDX-License-Identifier: MIT - -/// @custom:authors: [@unknownunknown1, @jaybuidl] -/// @custom:reviewers: [] -/// @custom:auditors: [] -/// @custom:bounties: [] -/// @custom:deployments: [] - -pragma solidity 0.8.18; - -import "../interfaces/IDisputeKit.sol"; -import "../KlerosCore.sol"; - -/// @title BaseDisputeKit -/// Provides common basic behaviours to the Dispute Kit implementations. -abstract contract BaseDisputeKit is IDisputeKit { - // ************************************* // - // * Storage * // - // ************************************* // - - address public governor; // The governor of the contract. - KlerosCore public core; // The Kleros Core arbitrator - - // ************************************* // - // * Function Modifiers * // - // ************************************* // - - modifier onlyByGovernor() { - require(governor == msg.sender, "Access not allowed: Governor only."); - _; - } - - modifier onlyByCore() { - require(address(core) == msg.sender, "Access not allowed: KlerosCore only."); - _; - } - - /// @dev Constructor. - /// @param _governor The governor's address. - /// @param _core The KlerosCore arbitrator. - constructor(address _governor, KlerosCore _core) { - governor = _governor; - core = _core; - } - - // ************************ // - // * Governance * // - // ************************ // - - /// @dev Allows the governor to call anything on behalf of the contract. - /// @param _destination The destination of the call. - /// @param _amount The value sent with the call. - /// @param _data The data sent with the call. - function executeGovernorProposal( - address _destination, - uint256 _amount, - bytes memory _data - ) external onlyByGovernor { - (bool success, ) = _destination.call{value: _amount}(_data); - require(success, "Unsuccessful call"); - } - - /// @dev Checks that the chosen address satisfies certain conditions for being drawn. - /// @param _coreDisputeID ID of the dispute in the core contract. - /// @param _juror Chosen address. - /// @return Whether the address can be drawn or not. - function _postDrawCheck(uint256 _coreDisputeID, address _juror) internal virtual returns (bool); -} diff --git a/contracts/src/arbitration/dispute-kits/DisputeKitClassic.sol b/contracts/src/arbitration/dispute-kits/DisputeKitClassic.sol index cf4e927b3..28ed9bc95 100644 --- a/contracts/src/arbitration/dispute-kits/DisputeKitClassic.sol +++ b/contracts/src/arbitration/dispute-kits/DisputeKitClassic.sol @@ -8,8 +8,11 @@ pragma solidity 0.8.18; -import "./BaseDisputeKit.sol"; +import "../KlerosCore.sol"; +import "../interfaces/IDisputeKit.sol"; import "../interfaces/IEvidence.sol"; +import "../../proxy/UUPSProxiable.sol"; +import "../../proxy/Initializable.sol"; /// @title DisputeKitClassic /// Dispute kit implementation of the Kleros v1 features including: @@ -17,7 +20,7 @@ import "../interfaces/IEvidence.sol"; /// - a vote aggregation system: plurality, /// - an incentive system: equal split between coherent votes, /// - an appeal system: fund 2 choices only, vote on any choice. -contract DisputeKitClassic is BaseDisputeKit, IEvidence { +contract DisputeKitClassic is IDisputeKit, IEvidence, Initializable, UUPSProxiable { // ************************************* // // * Structs * // // ************************************* // @@ -61,6 +64,8 @@ contract DisputeKitClassic is BaseDisputeKit, IEvidence { uint256 public constant LOSER_APPEAL_PERIOD_MULTIPLIER = 5000; // Multiplier of the appeal period for the choice that wasn't voted for in the previous round, in basis points. Default is 1/2 of original appeal period. uint256 public constant ONE_BASIS_POINT = 10000; // One basis point, for scaling. + address public governor; // The governor of the contract. + KlerosCore public core; // The Kleros Core arbitrator Dispute[] public disputes; // Array of the locally created disputes. mapping(uint256 => uint256) public coreDisputeIDToLocal; // Maps the dispute ID in Kleros Core to the local dispute ID. @@ -119,21 +124,63 @@ contract DisputeKitClassic is BaseDisputeKit, IEvidence { // * Modifiers * // // ************************************* // + modifier onlyByGovernor() { + require(governor == msg.sender, "Access not allowed: Governor only."); + _; + } + + modifier onlyByCore() { + require(address(core) == msg.sender, "Access not allowed: KlerosCore only."); + _; + } + modifier notJumped(uint256 _coreDisputeID) { require(!disputes[coreDisputeIDToLocal[_coreDisputeID]].jumped, "Dispute jumped to a parent DK!"); _; } - /** @dev Constructor. - * @param _governor The governor's address. - * @param _core The KlerosCore arbitrator. - */ - constructor(address _governor, KlerosCore _core) BaseDisputeKit(_governor, _core) {} + // ************************************* // + // * Constructor * // + // ************************************* // + + /// @dev Constructor, initializing the implementation to reduce attack surface. + constructor() { + _disableInitializers(); + } + + /// @dev Initializer. + /// @param _governor The governor's address. + /// @param _core The KlerosCore arbitrator. + function initialize(address _governor, KlerosCore _core) external reinitializer(1) { + governor = _governor; + core = _core; + } // ************************ // // * Governance * // // ************************ // + /** + * @dev Access Control to perform implementation upgrades (UUPS Proxiable) + * @dev Only the governor can perform upgrades (`onlyByGovernor`) + */ + function _authorizeUpgrade(address) internal view override onlyByGovernor { + // NOP + } + + /// @dev Allows the governor to call anything on behalf of the contract. + /// @param _destination The destination of the call. + /// @param _amount The value sent with the call. + /// @param _data The data sent with the call. + function executeGovernorProposal( + address _destination, + uint256 _amount, + bytes memory _data + ) external onlyByGovernor { + (bool success, ) = _destination.call{value: _amount}(_data); + require(success, "Unsuccessful call"); + } + /// @dev Changes the `governor` storage variable. /// @param _governor The new value for the `governor` storage variable. function changeGovernor(address payable _governor) external onlyByGovernor { @@ -559,8 +606,11 @@ contract DisputeKitClassic is BaseDisputeKit, IEvidence { // * Internal * // // ************************************* // - /// @inheritdoc BaseDisputeKit - function _postDrawCheck(uint256 _coreDisputeID, address _juror) internal view override returns (bool) { + /// @dev Checks that the chosen address satisfies certain conditions for being drawn. + /// @param _coreDisputeID ID of the dispute in the core contract. + /// @param _juror Chosen address. + /// @return Whether the address can be drawn or not. + function _postDrawCheck(uint256 _coreDisputeID, address _juror) internal view returns (bool) { (uint96 courtID, , , , ) = core.disputes(_coreDisputeID); uint256 lockedAmountPerJuror = core .getRoundInfo(_coreDisputeID, core.getNumberOfRounds(_coreDisputeID) - 1) diff --git a/contracts/src/arbitration/dispute-kits/DisputeKitSybilResistant.sol b/contracts/src/arbitration/dispute-kits/DisputeKitSybilResistant.sol index eb907c87e..a0fed2592 100644 --- a/contracts/src/arbitration/dispute-kits/DisputeKitSybilResistant.sol +++ b/contracts/src/arbitration/dispute-kits/DisputeKitSybilResistant.sol @@ -8,8 +8,11 @@ pragma solidity 0.8.18; -import "./BaseDisputeKit.sol"; -import "../interfaces//IEvidence.sol"; +import "../KlerosCore.sol"; +import "../interfaces/IDisputeKit.sol"; +import "../interfaces/IEvidence.sol"; +import "../../proxy/UUPSProxiable.sol"; +import "../../proxy/Initializable.sol"; interface IProofOfHumanity { /// @dev Return true if the submission is registered and not expired. @@ -24,7 +27,7 @@ interface IProofOfHumanity { /// - a vote aggregation system: plurality, /// - an incentive system: equal split between coherent votes, /// - an appeal system: fund 2 choices only, vote on any choice. -contract DisputeKitSybilResistant is BaseDisputeKit, IEvidence { +contract DisputeKitSybilResistant is IDisputeKit, IEvidence, Initializable, UUPSProxiable { // ************************************* // // * Structs * // // ************************************* // @@ -69,10 +72,11 @@ contract DisputeKitSybilResistant is BaseDisputeKit, IEvidence { uint256 public constant LOSER_APPEAL_PERIOD_MULTIPLIER = 5000; // Multiplier of the appeal period for the choice that wasn't voted for in the previous round, in basis points. Default is 1/2 of original appeal period. uint256 public constant ONE_BASIS_POINT = 10000; // One basis point, for scaling. - IProofOfHumanity public poh; // The Proof of Humanity registry - + address public governor; // The governor of the contract. + KlerosCore public core; // The Kleros Core arbitrator Dispute[] public disputes; // Array of the locally created disputes. mapping(uint256 => uint256) public coreDisputeIDToLocal; // Maps the dispute ID in Kleros Core to the local dispute ID. + IProofOfHumanity public poh; // The Proof of Humanity registry // ************************************* // // * Events * // @@ -129,17 +133,36 @@ contract DisputeKitSybilResistant is BaseDisputeKit, IEvidence { // * Modifiers * // // ************************************* // + modifier onlyByGovernor() { + require(governor == msg.sender, "Access not allowed: Governor only."); + _; + } + + modifier onlyByCore() { + require(address(core) == msg.sender, "Access not allowed: KlerosCore only."); + _; + } + modifier notJumped(uint256 _coreDisputeID) { require(!disputes[coreDisputeIDToLocal[_coreDisputeID]].jumped, "Dispute jumped to a parent DK!"); _; } - /** @dev Constructor. - * @param _governor The governor's address. - * @param _core The KlerosCore arbitrator. - * @param _poh ProofOfHumanity contract. - */ - constructor(address _governor, KlerosCore _core, IProofOfHumanity _poh) BaseDisputeKit(_governor, _core) { + // ************************************* // + // * Constructor * // + // ************************************* // + + /// @dev Constructor, initializing the implementation to reduce attack surface. + constructor() { + _disableInitializers(); + } + + /// @dev Initializer. + /// @param _governor The governor's address. + /// @param _core The KlerosCore arbitrator. + function initialize(address _governor, KlerosCore _core, IProofOfHumanity _poh) external reinitializer(1) { + governor = _governor; + core = _core; poh = _poh; } @@ -147,6 +170,27 @@ contract DisputeKitSybilResistant is BaseDisputeKit, IEvidence { // * Governance * // // ************************ // + /** + * @dev Access Control to perform implementation upgrades (UUPS Proxiable) + * @dev Only the governor can perform upgrades (`onlyByGovernor`) + */ + function _authorizeUpgrade(address) internal view override onlyByGovernor { + // NOP + } + + /// @dev Allows the governor to call anything on behalf of the contract. + /// @param _destination The destination of the call. + /// @param _amount The value sent with the call. + /// @param _data The data sent with the call. + function executeGovernorProposal( + address _destination, + uint256 _amount, + bytes memory _data + ) external onlyByGovernor { + (bool success, ) = _destination.call{value: _amount}(_data); + require(success, "Unsuccessful call"); + } + /// @dev Changes the `governor` storage variable. /// @param _governor The new value for the `governor` storage variable. function changeGovernor(address payable _governor) external onlyByGovernor { @@ -583,7 +627,7 @@ contract DisputeKitSybilResistant is BaseDisputeKit, IEvidence { /// @param _coreDisputeID ID of the dispute in the core contract. /// @param _juror Chosen address. /// @return Whether the address can be drawn or not. - function _postDrawCheck(uint256 _coreDisputeID, address _juror) internal view override returns (bool) { + function _postDrawCheck(uint256 _coreDisputeID, address _juror) internal view returns (bool) { (uint96 courtID, , , , ) = core.disputes(_coreDisputeID); uint256 lockedAmountPerJuror = core .getRoundInfo(_coreDisputeID, core.getNumberOfRounds(_coreDisputeID) - 1) diff --git a/contracts/src/rng/RandomizerRNG.sol b/contracts/src/rng/RandomizerRNG.sol index 34361cb07..30fef82f5 100644 --- a/contracts/src/rng/RandomizerRNG.sol +++ b/contracts/src/rng/RandomizerRNG.sol @@ -4,10 +4,12 @@ pragma solidity 0.8.18; import "./RNG.sol"; import "./IRandomizer.sol"; +import "../proxy/UUPSProxiable.sol"; +import "../proxy/Initializable.sol"; /// @title Random Number Generator that uses Randomizer.ai /// https://randomizer.ai/ -contract RandomizerRNG is RNG { +contract RandomizerRNG is RNG, UUPSProxiable, Initializable { address public governor; // The address that can withdraw funds. uint256 public callbackGasLimit = 50000; // Gas limit for the randomizer callback @@ -24,10 +26,15 @@ contract RandomizerRNG is RNG { _; } - /// @dev Constructor. + /// @dev Constructor, initializing the implementation to reduce attack surface. + constructor() { + _disableInitializers(); + } + + /// @dev Initializer /// @param _randomizer Randomizer contract. /// @param _governor Governor of the contract. - constructor(IRandomizer _randomizer, address _governor) { + function initialize(IRandomizer _randomizer, address _governor) external reinitializer(1) { randomizer = _randomizer; governor = _governor; } @@ -36,6 +43,12 @@ contract RandomizerRNG is RNG { // * Governance * // // ************************ // + /** + * @dev Access Control to perform implementation upgrades (UUPS Proxiable) + * @dev Only the governor can perform upgrades (`onlyByGovernor`) + */ + function _authorizeUpgrade(address) internal view override onlyByGovernor {} + /// @dev Changes the governor of the contract. /// @param _governor The new governor. function changeGovernor(address _governor) external onlyByGovernor { diff --git a/contracts/test/arbitration/index.ts b/contracts/test/arbitration/index.ts index 8bf65831b..f3530437b 100644 --- a/contracts/test/arbitration/index.ts +++ b/contracts/test/arbitration/index.ts @@ -1,13 +1,7 @@ import { expect } from "chai"; import { deployments, ethers } from "hardhat"; import { BigNumber } from "ethers"; -import getContractAddress from "../../deploy-helpers/getContractAddress"; - -const ONE_ETH = BigNumber.from(10).pow(18); -const WINNER_STAKE_MULTIPLIER = 3000; -const LOSER_STAKE_MULTIPLIER = 7000; -const MULTIPLIER_DENOMINATOR = 10000; -const LOOKAHEAD = 20; +import { KlerosCore, DisputeKitClassic } from "../../typechain-types"; describe("DisputeKitClassic", async () => { // eslint-disable-next-line no-unused-vars @@ -32,16 +26,11 @@ describe("DisputeKitClassic", async () => { expect(events[0].args._courtID).to.equal(1); expect(events[0].args._parent).to.equal(0); expect(events[0].args._hiddenVotes).to.equal(false); - expect(events[0].args._minStake).to.equal(200); + expect(events[0].args._minStake).to.equal(ethers.utils.parseUnits("200", 18)); expect(events[0].args._alpha).to.equal(10000); - expect(events[0].args._feeForJuror).to.equal(100); - expect(events[0].args._jurorsForCourtJump).to.equal(3); - expect(events[0].args._timesPerPeriod).to.deep.equal([ - ethers.constants.Zero, - ethers.constants.Zero, - ethers.constants.Zero, - ethers.constants.Zero, - ]); + expect(events[0].args._feeForJuror).to.equal(ethers.utils.parseUnits("0.1", 18)); + expect(events[0].args._jurorsForCourtJump).to.equal(256); + expect(events[0].args._timesPerPeriod).to.deep.equal([0, 0, 0, 10]); expect(events[0].args._supportedDisputeKits).to.deep.equal([]); events = await core.queryFilter(core.filters.DisputeKitEnabled()); @@ -56,7 +45,9 @@ describe("DisputeKitClassic", async () => { "Access not allowed: KlerosCore only." ); - const tx = await core.connect(deployer).functions["createDispute(uint256,bytes)"](2, "0x00", { value: 1000 }); + const tx = await core + .connect(deployer) + .functions["createDispute(uint256,bytes)"](2, "0x00", { value: ethers.utils.parseEther("0.3") }); expect(tx).to.emit(core, "DisputeCreation").withArgs(0, deployer.address); expect(tx).to.emit(disputeKit, "DisputeCreation").withArgs(0, 2, "0x00"); @@ -71,79 +62,11 @@ describe("DisputeKitClassic", async () => { }); async function deployContracts(deployer) { - const rngFactory = await ethers.getContractFactory("BlockHashRNG", deployer); - const rng = await rngFactory.deploy(); - await rng.deployed(); - - const disputeKitFactory = await ethers.getContractFactory("DisputeKitClassic", deployer); - const disputeKit = await disputeKitFactory.deploy( - deployer.address, - ethers.constants.AddressZero // KlerosCore is set later once it is deployed - ); - await disputeKit.deployed(); - let nonce; - nonce = await deployer.getTransactionCount(); - nonce += 3; // SortitionModule is upgradeable, it deploys an implementation and a proxy - const KlerosCoreAddress = getContractAddress(deployer.address, nonce); - - const sortitionModuleDeployment = await deployments.deploy("SortitionModule_DisputeKitClassic", { - contract: "SortitionModule", - from: deployer.address, - proxy: { - proxyContract: "UUPSProxy", - proxyArgs: ["{implementation}", "{data}"], - execute: { - init: { - methodName: "initialize", - args: [deployer.address, KlerosCoreAddress, 120, 120, rng.address, LOOKAHEAD], // minStakingTime, maxFreezingTime - }, - onUpgrade: { - methodName: "governor", - args: [], - }, - }, - }, - log: true, - args: [], - }); - - const sortitionModule = await ethers.getContractAt("SortitionModule", sortitionModuleDeployment.address); - - const coreDeployment = await deployments.deploy("KlerosCore_DisputeKitClassic", { - contract: "KlerosCore", - from: deployer.address, - proxy: { - proxyContract: "UUPSProxy", - proxyArgs: ["{implementation}", "{data}"], - checkProxyAdmin: false, - checkABIConflict: false, - execute: { - init: { - methodName: "initialize", - args: [ - deployer.address, - ethers.constants.AddressZero, // should be an ERC20 - ethers.constants.AddressZero, // should be a Juror Prosecution module - disputeKit.address, - false, - [200, 10000, 100, 3], - [0, 0, 0, 0], - "0xfa", - sortitionModule.address, - ], - }, - onUpgrade: { - methodName: "governor", - args: [], - }, - }, - }, - args: [], - log: true, + await deployments.fixture(["Arbitration", "VeaMock"], { + fallbackToGlobal: true, + keepExistingDeployments: false, }); - const core = await ethers.getContractAt("KlerosCore", coreDeployment.address); - - await disputeKit.changeCore(core.address); - + const disputeKit = (await ethers.getContract("DisputeKitClassic")) as DisputeKitClassic; + const core = (await ethers.getContract("KlerosCore")) as KlerosCore; return [core, disputeKit]; } diff --git a/cspell.json b/cspell.json index 1aa319e95..44aec852d 100644 --- a/cspell.json +++ b/cspell.json @@ -29,6 +29,7 @@ "ipfs", "kleros", "linguo", + "Numberish", "Pinakion", "Realitio", "repartitions", @@ -37,6 +38,7 @@ "uncommify", "Unslashed", "unstake", + "UUPS", "viem", "wagmi" ],