Skip to content

Commit

Permalink
feat: made the DisputeKits and RandomizerRNG upgradable, refactored t…
Browse files Browse the repository at this point in the history
…he deploy scripts
  • Loading branch information
jaybuidl committed Sep 25, 2023
1 parent 24b7f21 commit c69aeb7
Show file tree
Hide file tree
Showing 24 changed files with 312 additions and 450 deletions.
6 changes: 3 additions & 3 deletions contracts/deploy/00-ethereum-pnk.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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;
12 changes: 3 additions & 9 deletions contracts/deploy/00-home-chain-arbitrable.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
113 changes: 31 additions & 82 deletions contracts/deploy/00-home-chain-arbitration.ts
Original file line number Diff line number Diff line change
@@ -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, string>([
[HomeChains.ARBITRUM_ONE, "0x330bD769382cFc6d50175903434CCC8D206DCAE5"],
Expand Down Expand Up @@ -63,89 +59,43 @@ 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;
const weth = wethByChain.get(chainId) ?? AddressZero;
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());
Expand All @@ -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) => {
Expand Down
12 changes: 3 additions & 9 deletions contracts/deploy/00-home-chain-pnk-faucet.ts
Original file line number Diff line number Diff line change
@@ -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, string>([
[HomeChains.ARBITRUM_ONE, "0x330bD769382cFc6d50175903434CCC8D206DCAE5"],
Expand Down Expand Up @@ -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;
12 changes: 3 additions & 9 deletions contracts/deploy/00-rng.ts
Original file line number Diff line number Diff line change
@@ -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, string>([
[HomeChains.ARBITRUM_ONE, "0x330bD769382cFc6d50175903434CCC8D206DCAE5"],
Expand Down Expand Up @@ -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;
13 changes: 4 additions & 9 deletions contracts/deploy/01-foreign-gateway-on-ethereum.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
14 changes: 4 additions & 10 deletions contracts/deploy/01-foreign-gateway-on-gnosis.ts
Original file line number Diff line number Diff line change
@@ -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");

Expand Down Expand Up @@ -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;
12 changes: 4 additions & 8 deletions contracts/deploy/02-home-gateway-to-ethereum.ts
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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;
12 changes: 4 additions & 8 deletions contracts/deploy/02-home-gateway-to-gnosis.ts
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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;
15 changes: 8 additions & 7 deletions contracts/deploy/03-vea-mock.ts
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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");

Expand All @@ -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",
Expand All @@ -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
],
Expand Down Expand Up @@ -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;
Loading

0 comments on commit c69aeb7

Please sign in to comment.