Skip to content

Commit 487fc5b

Browse files
committed
feat: made the DisputeKits and RandomizerRNG upgradable, refactored the deploy scripts
1 parent 76cb13d commit 487fc5b

24 files changed

+312
-450
lines changed

contracts/deploy/00-ethereum-pnk.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { HardhatRuntimeEnvironment } from "hardhat/types";
22
import { DeployFunction } from "hardhat-deploy/types";
33
import disputeTemplate from "../test/fixtures/DisputeTemplate.simple.json";
4+
import { isSkipped } from "./utils";
45

56
enum Chains {
67
GOERLI = 5,
@@ -24,9 +25,8 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
2425
};
2526

2627
deployArbitration.tags = ["Pinakion"];
27-
deployArbitration.skip = async ({ getChainId }) => {
28-
const chainId = Number(await getChainId());
29-
return !Chains[chainId];
28+
deployArbitration.skip = async ({ network }) => {
29+
return isSkipped(network, !Chains[network.config.chainId ?? 0]);
3030
};
3131

3232
export default deployArbitration;

contracts/deploy/00-home-chain-arbitrable.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
import { HardhatRuntimeEnvironment } from "hardhat/types";
22
import { DeployFunction } from "hardhat-deploy/types";
33
import disputeTemplate from "../test/fixtures/DisputeTemplate.simple.json";
4-
5-
enum HomeChains {
6-
ARBITRUM_ONE = 42161,
7-
ARBITRUM_GOERLI = 421613,
8-
HARDHAT = 31337,
9-
}
4+
import { HomeChains, isSkipped } from "./utils";
105

116
const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
127
const { deployments, getNamedAccounts, getChainId } = hre;
@@ -50,9 +45,8 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
5045

5146
deployArbitration.tags = ["HomeArbitrable"];
5247
deployArbitration.dependencies = ["Arbitration"];
53-
deployArbitration.skip = async ({ getChainId }) => {
54-
const chainId = Number(await getChainId());
55-
return !HomeChains[chainId];
48+
deployArbitration.skip = async ({ network }) => {
49+
return isSkipped(network, !HomeChains[network.config.chainId ?? 0]);
5650
};
5751

5852
export default deployArbitration;

contracts/deploy/00-home-chain-arbitration.ts

Lines changed: 31 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
import { HardhatRuntimeEnvironment } from "hardhat/types";
22
import { DeployFunction } from "hardhat-deploy/types";
33
import { BigNumber } from "ethers";
4-
import getContractAddress from "../deploy-helpers/getContractAddress";
5-
6-
enum HomeChains {
7-
ARBITRUM_ONE = 42161,
8-
ARBITRUM_GOERLI = 421613,
9-
HARDHAT = 31337,
10-
}
4+
import getContractAddress from "./utils/getContractAddress";
5+
import { deployUpgradable } from "./utils/deployUpgradable";
6+
import { HomeChains, isSkipped } from "./utils";
117

128
const pnkByChain = new Map<HomeChains, string>([
139
[HomeChains.ARBITRUM_ONE, "0x330bD769382cFc6d50175903434CCC8D206DCAE5"],
@@ -63,89 +59,43 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
6359
});
6460

6561
const randomizer = randomizerByChain.get(Number(await getChainId())) ?? AddressZero;
66-
const rng = await deploy("RandomizerRNG", {
67-
skipIfAlreadyDeployed: true,
68-
from: deployer,
69-
args: [randomizer, deployer],
70-
log: true,
71-
});
72-
73-
const disputeKit = await deploy("DisputeKitClassic", {
74-
from: deployer,
75-
args: [deployer, AddressZero],
76-
log: true,
77-
});
62+
const rng = await deployUpgradable(hre, deployer, "RandomizerRNG", [randomizer, deployer]);
7863

79-
let nonce;
80-
let KlerosCoreAddress;
64+
const disputeKit = await deployUpgradable(hre, deployer, "DisputeKitClassic", [deployer, AddressZero]);
8165

82-
const klerosCoreDeployment = await deployments.getOrNull("KlerosCore");
83-
if (!klerosCoreDeployment) {
84-
nonce = await ethers.provider.getTransactionCount(deployer);
85-
KlerosCoreAddress = getContractAddress(deployer, nonce + 3); // Deploying an upgradeable version of SortionModule requires 2 transactions instead of 1 (implementation then proxy)
86-
console.log("calculated future KlerosCore address for nonce %d: %s", nonce, KlerosCoreAddress);
87-
} else {
88-
KlerosCoreAddress = klerosCoreDeployment.address;
66+
let klerosCoreAddress = await deployments.getOrNull("KlerosCore").then((deployment) => deployment?.address);
67+
if (!klerosCoreAddress) {
68+
const nonce = await ethers.provider.getTransactionCount(deployer);
69+
klerosCoreAddress = getContractAddress(deployer, nonce + 3); // Deploying an upgradeable version of SortitionModule requires 2 transactions instead of 1 (implementation then proxy)
70+
console.log("calculated future KlerosCore address for nonce %d: %s", nonce, klerosCoreAddress);
8971
}
9072

91-
const sortitionModule = await deploy("SortitionModule", {
92-
from: deployer,
93-
proxy: {
94-
proxyContract: "UUPSProxy",
95-
proxyArgs: ["{implementation}", "{data}"],
96-
checkProxyAdmin: false,
97-
checkABIConflict: false,
98-
execute: {
99-
init: {
100-
methodName: "initialize",
101-
args: [deployer, KlerosCoreAddress, 1800, 1800, rng.address, RNG_LOOKAHEAD], // minStakingTime, maxFreezingTime
102-
},
103-
onUpgrade: {
104-
methodName: "governor",
105-
args: [],
106-
},
107-
},
108-
},
109-
log: true,
110-
});
73+
const sortitionModule = await deployUpgradable(hre, deployer, "SortitionModule", [
74+
deployer,
75+
klerosCoreAddress,
76+
1800, // minStakingTime
77+
1800, // maxFreezingTime
78+
rng.address,
79+
RNG_LOOKAHEAD,
80+
]);
11181

11282
const pnk = pnkByChain.get(chainId) ?? AddressZero;
11383
const dai = daiByChain.get(chainId) ?? AddressZero;
11484
const weth = wethByChain.get(chainId) ?? AddressZero;
11585
const minStake = BigNumber.from(10).pow(20).mul(2);
11686
const alpha = 10000;
11787
const feeForJuror = BigNumber.from(10).pow(17);
118-
const klerosCore = await deploy("KlerosCore", {
119-
from: deployer,
120-
proxy: {
121-
proxyContract: "UUPSProxy",
122-
proxyArgs: ["{implementation}", "{data}"],
123-
checkProxyAdmin: false,
124-
checkABIConflict: false,
125-
execute: {
126-
init: {
127-
methodName: "initialize",
128-
args: [
129-
deployer,
130-
pnk,
131-
AddressZero,
132-
disputeKit.address,
133-
false,
134-
[minStake, alpha, feeForJuror, 256], // minStake, alpha, feeForJuror, jurorsForCourtJump
135-
[0, 0, 0, 10], // evidencePeriod, commitPeriod, votePeriod, appealPeriod
136-
ethers.utils.hexlify(5), // Extra data for sortition module will return the default value of K
137-
sortitionModule.address,
138-
],
139-
},
140-
onUpgrade: {
141-
methodName: "governor",
142-
args: [],
143-
},
144-
},
145-
},
146-
args: [],
147-
log: true,
148-
});
88+
const klerosCore = await deployUpgradable(hre, deployer, "KlerosCore", [
89+
deployer,
90+
pnk,
91+
AddressZero,
92+
disputeKit.address,
93+
false,
94+
[minStake, alpha, feeForJuror, 256], // minStake, alpha, feeForJuror, jurorsForCourtJump
95+
[0, 0, 0, 10], // evidencePeriod, commitPeriod, votePeriod, appealPeriod
96+
ethers.utils.hexlify(5), // Extra data for sortition module will return the default value of K
97+
sortitionModule.address,
98+
]);
14999

150100
// execute DisputeKitClassic.changeCore() only if necessary
151101
const currentCore = await hre.ethers.getContractAt("DisputeKitClassic", disputeKit.address).then((dk) => dk.core());
@@ -163,9 +113,8 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
163113
};
164114

165115
deployArbitration.tags = ["Arbitration"];
166-
deployArbitration.skip = async ({ getChainId }) => {
167-
const chainId = Number(await getChainId());
168-
return !HomeChains[chainId];
116+
deployArbitration.skip = async ({ network }) => {
117+
return isSkipped(network, !HomeChains[network.config.chainId ?? 0]);
169118
};
170119

171120
const deployERC20AndFaucet = async (

contracts/deploy/00-home-chain-pnk-faucet.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
import { HardhatRuntimeEnvironment } from "hardhat/types";
22
import { DeployFunction } from "hardhat-deploy/types";
3-
4-
enum HomeChains {
5-
ARBITRUM_ONE = 42161,
6-
ARBITRUM_GOERLI = 421613,
7-
HARDHAT = 31337,
8-
}
3+
import { HomeChains, isSkipped } from "./utils";
94

105
const pnkByChain = new Map<HomeChains, string>([
116
[HomeChains.ARBITRUM_ONE, "0x330bD769382cFc6d50175903434CCC8D206DCAE5"],
@@ -39,9 +34,8 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
3934
};
4035

4136
deployArbitration.tags = ["PnkFaucet"];
42-
deployArbitration.skip = async ({ getChainId }) => {
43-
const chainId = Number(await getChainId());
44-
return !HomeChains[chainId];
37+
deployArbitration.skip = async ({ network }) => {
38+
return isSkipped(network, !HomeChains[network.config.chainId ?? 0]);
4539
};
4640

4741
export default deployArbitration;

contracts/deploy/00-rng.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
import { HardhatRuntimeEnvironment } from "hardhat/types";
22
import { DeployFunction } from "hardhat-deploy/types";
33
import { SortitionModule, RandomizerRNG } from "../typechain-types";
4-
5-
enum HomeChains {
6-
ARBITRUM_ONE = 42161,
7-
ARBITRUM_GOERLI = 421613,
8-
HARDHAT = 31337,
9-
}
4+
import { HomeChains, isSkipped } from "./utils";
105

116
const pnkByChain = new Map<HomeChains, string>([
127
[HomeChains.ARBITRUM_ONE, "0x330bD769382cFc6d50175903434CCC8D206DCAE5"],
@@ -63,9 +58,8 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
6358
};
6459

6560
deployArbitration.tags = ["RNG"];
66-
deployArbitration.skip = async ({ getChainId }) => {
67-
const chainId = Number(await getChainId());
68-
return !HomeChains[chainId];
61+
deployArbitration.skip = async ({ network }) => {
62+
return isSkipped(network, !HomeChains[network.config.chainId ?? 0]);
6963
};
7064

7165
export default deployArbitration;

contracts/deploy/01-foreign-gateway-on-ethereum.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
import { HardhatRuntimeEnvironment } from "hardhat/types";
22
import { DeployFunction } from "hardhat-deploy/types";
3-
import getContractAddress from "../deploy-helpers/getContractAddress";
3+
import getContractAddress from "./utils/getContractAddress";
44
import { KlerosCore__factory } from "../typechain-types";
5-
6-
enum ForeignChains {
7-
ETHEREUM_MAINNET = 1,
8-
ETHEREUM_GOERLI = 5,
9-
}
5+
import { ForeignChains, HardhatChain, isSkipped } from "./utils";
106

117
const deployForeignGateway: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
128
const { ethers, deployments, getNamedAccounts, getChainId, config } = hre;
@@ -56,9 +52,8 @@ const deployForeignGateway: DeployFunction = async (hre: HardhatRuntimeEnvironme
5652
};
5753

5854
deployForeignGateway.tags = ["ForeignGatewayOnEthereum"];
59-
deployForeignGateway.skip = async ({ getChainId }) => {
60-
const chainId = Number(await getChainId());
61-
return !ForeignChains[chainId];
55+
deployForeignGateway.skip = async ({ network }) => {
56+
return isSkipped(network, !ForeignChains[network.config.chainId ?? 0]);
6257
};
6358

6459
export default deployForeignGateway;

contracts/deploy/01-foreign-gateway-on-gnosis.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
import { parseUnits } from "ethers/lib/utils";
22
import { HardhatRuntimeEnvironment } from "hardhat/types";
33
import { DeployFunction } from "hardhat-deploy/types";
4-
import getContractAddress from "../deploy-helpers/getContractAddress";
4+
import getContractAddress from "./utils/getContractAddress";
55
import { KlerosCore__factory } from "../typechain-types";
6-
7-
enum ForeignChains {
8-
GNOSIS_MAINNET = 100,
9-
GNOSIS_CHIADO = 10200,
10-
HARDHAT = 31337,
11-
}
6+
import { ForeignChains, isSkipped } from "./utils";
127

138
const ONE_GWEI = parseUnits("1", "gwei");
149

@@ -62,9 +57,8 @@ const deployForeignGateway: DeployFunction = async (hre: HardhatRuntimeEnvironme
6257
};
6358

6459
deployForeignGateway.tags = ["ForeignGatewayOnGnosis"];
65-
deployForeignGateway.skip = async ({ getChainId }) => {
66-
const chainId = Number(await getChainId());
67-
return !ForeignChains[chainId];
60+
deployForeignGateway.skip = async ({ network }) => {
61+
return isSkipped(network, !ForeignChains[network.config.chainId ?? 0]);
6862
};
6963

7064
export default deployForeignGateway;

contracts/deploy/02-home-gateway-to-ethereum.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
import { HardhatRuntimeEnvironment } from "hardhat/types";
22
import { DeployFunction } from "hardhat-deploy/types";
33
import { ethers } from "hardhat";
4-
5-
enum HomeChains {
6-
ARBITRUM_ONE = 42161,
7-
ARBITRUM_GOERLI = 421613,
8-
}
4+
import { HardhatChain, HomeChains, isSkipped } from "./utils";
95

106
// TODO: use deterministic deployments
117

@@ -42,9 +38,9 @@ const deployHomeGateway: DeployFunction = async (hre: HardhatRuntimeEnvironment)
4238
};
4339

4440
deployHomeGateway.tags = ["HomeGatewayToEthereum"];
45-
deployHomeGateway.skip = async ({ getChainId }) => {
46-
const chainId = Number(await getChainId());
47-
return !HomeChains[chainId];
41+
deployHomeGateway.skip = async ({ network }) => {
42+
const chainId = network.config.chainId ?? 0;
43+
return isSkipped(network, !HomeChains[chainId] || HardhatChain[chainId] !== undefined);
4844
};
4945

5046
export default deployHomeGateway;

contracts/deploy/02-home-gateway-to-gnosis.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
import { HardhatRuntimeEnvironment } from "hardhat/types";
22
import { DeployFunction } from "hardhat-deploy/types";
3-
4-
enum HomeChains {
5-
ARBITRUM_ONE = 42161,
6-
ARBITRUM_GOERLI = 421613,
7-
}
3+
import { HardhatChain, HomeChains, isSkipped } from "./utils";
84

95
// TODO: use deterministic deployments
106

@@ -35,9 +31,9 @@ const deployHomeGateway: DeployFunction = async (hre: HardhatRuntimeEnvironment)
3531
};
3632

3733
deployHomeGateway.tags = ["HomeGatewayToGnosis"];
38-
deployHomeGateway.skip = async ({ getChainId }) => {
39-
const chainId = Number(await getChainId());
40-
return !HomeChains[chainId];
34+
deployHomeGateway.skip = async ({ network }) => {
35+
const chainId = network.config.chainId ?? 0;
36+
return isSkipped(network, !HomeChains[chainId] || HardhatChain[chainId] !== undefined);
4137
};
4238

4339
export default deployHomeGateway;

contracts/deploy/03-vea-mock.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import { HardhatRuntimeEnvironment } from "hardhat/types";
22
import { DeployFunction } from "hardhat-deploy/types";
3-
import getContractAddress from "../deploy-helpers/getContractAddress";
3+
import getContractAddress from "./utils/getContractAddress";
44
import { KlerosCore__factory } from "../typechain-types";
55
import disputeTemplate from "../test/fixtures/DisputeTemplate.simple.json";
6-
7-
const HARDHAT_NETWORK = 31337;
6+
import { HardhatChain, isSkipped } from "./utils";
87

98
// TODO: use deterministic deployments
109

@@ -15,7 +14,7 @@ const deployHomeGateway: DeployFunction = async (hre: HardhatRuntimeEnvironment)
1514

1615
// fallback to hardhat node signers on local network
1716
const deployer = (await getNamedAccounts()).deployer ?? (await hre.ethers.getSigners())[0].address;
18-
console.log("Deploying to chainId %s with deployer %s", HARDHAT_NETWORK, deployer);
17+
console.log("Deploying to chainId %s with deployer %s", HardhatChain.HARDHAT, deployer);
1918

2019
const klerosCore = await deployments.get("KlerosCore");
2120

@@ -28,7 +27,7 @@ const deployHomeGateway: DeployFunction = async (hre: HardhatRuntimeEnvironment)
2827
const homeGatewayAddress = getContractAddress(deployer, nonce + 1);
2928
console.log("Calculated future HomeGatewayToEthereum address for nonce %d: %s", nonce, homeGatewayAddress);
3029

31-
const homeChainIdAsBytes32 = hexZeroPad(hexlify(HARDHAT_NETWORK), 32);
30+
const homeChainIdAsBytes32 = hexZeroPad(hexlify(HardhatChain.HARDHAT), 32);
3231
const foreignGateway = await deploy("ForeignGatewayOnEthereum", {
3332
from: deployer,
3433
contract: "ForeignGateway",
@@ -44,7 +43,7 @@ const deployHomeGateway: DeployFunction = async (hre: HardhatRuntimeEnvironment)
4443
deployer,
4544
klerosCore.address,
4645
vea.address,
47-
HARDHAT_NETWORK,
46+
HardhatChain.HARDHAT,
4847
foreignGateway.address,
4948
ethers.constants.AddressZero, // feeToken
5049
],
@@ -86,6 +85,8 @@ const deployHomeGateway: DeployFunction = async (hre: HardhatRuntimeEnvironment)
8685
};
8786

8887
deployHomeGateway.tags = ["VeaMock"];
89-
deployHomeGateway.skip = async ({ getChainId }) => HARDHAT_NETWORK !== Number(await getChainId());
88+
deployHomeGateway.skip = async ({ network }) => {
89+
return isSkipped(network, HardhatChain[network.config.chainId ?? 0] === undefined);
90+
};
9091

9192
export default deployHomeGateway;

0 commit comments

Comments
 (0)