|
| 1 | +import { HardhatRuntimeEnvironment } from "hardhat/types"; |
| 2 | +import { DeployFunction } from "hardhat-deploy/types"; |
| 3 | +import { DisputeKitClassic, KlerosCore } from "../typechain-types"; |
| 4 | +import assert from "node:assert"; |
| 5 | + |
| 6 | +enum HomeChains { |
| 7 | + ARBITRUM_ONE = 42161, |
| 8 | + ARBITRUM_GOERLI = 421613, |
| 9 | + HARDHAT = 31337, |
| 10 | +} |
| 11 | + |
| 12 | +const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { |
| 13 | + const { deployments, getNamedAccounts, getChainId } = hre; |
| 14 | + const { deploy, execute } = deployments; |
| 15 | + const { AddressZero } = hre.ethers.constants; |
| 16 | + |
| 17 | + // fallback to hardhat node signers on local network |
| 18 | + const deployer = (await getNamedAccounts()).deployer ?? (await hre.ethers.getSigners())[0].address; |
| 19 | + const chainId = Number(await getChainId()); |
| 20 | + console.log("Deploying to %s with deployer %s", HomeChains[chainId], deployer); |
| 21 | + |
| 22 | + const oldDisputeKitId = 1; |
| 23 | + const newDisputeKitId = 2; |
| 24 | + |
| 25 | + const klerosCore = (await hre.ethers.getContract("KlerosCore")) as KlerosCore; |
| 26 | + const oldDisputeKit = (await hre.ethers.getContract("DisputeKitClassic")) as DisputeKitClassic; |
| 27 | + |
| 28 | + await deploy("DisputeKitClassic", { |
| 29 | + from: deployer, |
| 30 | + args: [deployer, AddressZero], |
| 31 | + log: true, |
| 32 | + }); |
| 33 | + |
| 34 | + // DK.changeCore() only if necessary |
| 35 | + const newDisputeKit = (await hre.ethers.getContract("DisputeKitClassic")) as DisputeKitClassic; |
| 36 | + if (await newDisputeKit.core().then((core) => core !== klerosCore.address)) { |
| 37 | + await execute("DisputeKitClassic", { from: deployer, log: true }, "changeCore", klerosCore.address); |
| 38 | + } |
| 39 | + |
| 40 | + await execute("KlerosCore", { from: deployer, log: true }, "addNewDisputeKit", newDisputeKit.address, 0); |
| 41 | + |
| 42 | + assert( |
| 43 | + await klerosCore.disputeKitNodes(oldDisputeKitId).then((node) => node.disputeKit === oldDisputeKit.address), |
| 44 | + `wrong dispute kit id ${oldDisputeKitId}` |
| 45 | + ); |
| 46 | + assert( |
| 47 | + await klerosCore.disputeKitNodes(newDisputeKitId).then((node) => node.disputeKit === newDisputeKit.address), |
| 48 | + `wrong dispute kit id ${newDisputeKitId}` |
| 49 | + ); |
| 50 | + |
| 51 | + await execute("KlerosCore", { from: deployer, log: true }, "enableDisputeKits", 1, newDisputeKitId, true); // enable the new dispute kit |
| 52 | + await execute("KlerosCore", { from: deployer, log: true }, "enableDisputeKits", 1, oldDisputeKitId, false); // disable the old dispute kit |
| 53 | +}; |
| 54 | + |
| 55 | +deployArbitration.tags = ["Fix1148"]; |
| 56 | +deployArbitration.skip = async ({ getChainId }) => { |
| 57 | + const chainId = Number(await getChainId()); |
| 58 | + return !HomeChains[chainId]; |
| 59 | +}; |
| 60 | + |
| 61 | +export default deployArbitration; |
0 commit comments