Skip to content

Commit 0e2264a

Browse files
committed
chore: deploy scripts now use the chainlink rng
1 parent 555f04a commit 0e2264a

5 files changed

+54
-55
lines changed

contracts/deploy/00-chainlink-rng.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { DeployFunction } from "hardhat-deploy/types";
33
import { HomeChains, isSkipped } from "./utils";
44
import { getContractOrDeploy } from "./utils/getContractOrDeploy";
55

6-
const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
6+
const deployRng: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
77
const { deployments, getNamedAccounts, getChainId } = hre;
88
const { deploy } = deployments;
99

@@ -57,7 +57,7 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
5757
from: deployer,
5858
args: [
5959
deployer,
60-
deployer, // For testing only, it should be the SortitionModule
60+
deployer, // The consumer is configured as the SortitionModule later
6161
ChainlinkVRFCoordinator.target,
6262
keyHash,
6363
subscriptionId,
@@ -68,9 +68,9 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
6868
});
6969
};
7070

71-
deployArbitration.tags = ["ChainlinkRNG"];
72-
deployArbitration.skip = async ({ network }) => {
71+
deployRng.tags = ["ChainlinkRNG"];
72+
deployRng.skip = async ({ network }) => {
7373
return isSkipped(network, !HomeChains[network.config.chainId ?? 0]);
7474
};
7575

76-
export default deployArbitration;
76+
export default deployRng;

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

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { HardhatRuntimeEnvironment } from "hardhat/types";
22
import { DeployFunction } from "hardhat-deploy/types";
3-
import disputeTemplate from "../test/fixtures/DisputeTemplate.simple.json";
43
import { HomeChains, isSkipped } from "./utils";
54
import { deployUpgradable } from "./utils/deployUpgradable";
65

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

+7-19
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { changeCurrencyRate } from "./utils/klerosCoreHelper";
66
import { HomeChains, isSkipped, isDevnet, PNK, ETH } from "./utils";
77
import { getContractOrDeploy, getContractOrDeployUpgradable } from "./utils/getContractOrDeploy";
88
import { deployERC20AndFaucet, deployERC721 } from "./utils/deployTokens";
9-
import { DisputeKitClassic, KlerosCoreNeo, RandomizerRNG } from "../typechain-types";
9+
import { ChainlinkRNG, DisputeKitClassic, KlerosCoreNeo, RandomizerRNG } from "../typechain-types";
1010

1111
const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
1212
const { ethers, deployments, getNamedAccounts, getChainId } = hre;
@@ -29,19 +29,6 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
2929

3030
await deployUpgradable(deployments, "EvidenceModule", { from: deployer, args: [deployer], log: true });
3131

32-
const randomizerOracle = await getContractOrDeploy(hre, "RandomizerOracle", {
33-
from: deployer,
34-
contract: "RandomizerMock",
35-
args: [],
36-
log: true,
37-
});
38-
39-
const rng = await deploy("RandomizerRNG", {
40-
from: deployer,
41-
args: [deployer, ZeroAddress, randomizerOracle.target], // The SortitionModule is configured later
42-
log: true,
43-
});
44-
4532
const disputeKit = await deployUpgradable(deployments, "DisputeKitClassicNeo", {
4633
from: deployer,
4734
contract: "DisputeKitClassic",
@@ -58,6 +45,7 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
5845
const devnet = isDevnet(hre.network);
5946
const minStakingTime = devnet ? 180 : 1800;
6047
const maxFreezingTime = devnet ? 600 : 1800;
48+
const rng = (await ethers.getContract("ChainlinkRNG")) as ChainlinkRNG;
6149
const maxStakePerJuror = PNK(2_000);
6250
const maxTotalStaked = PNK(2_000_000);
6351
const sortitionModule = await deployUpgradable(deployments, "SortitionModuleNeo", {
@@ -67,7 +55,7 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
6755
klerosCoreAddress,
6856
minStakingTime,
6957
maxFreezingTime,
70-
rng.address,
58+
rng.target,
7159
RNG_LOOKAHEAD,
7260
maxStakePerJuror,
7361
maxTotalStaked,
@@ -106,11 +94,10 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
10694
}
10795

10896
// rng.changeSortitionModule() only if necessary
109-
const rngContract = (await ethers.getContract("RandomizerRNG")) as RandomizerRNG;
110-
const currentSortitionModule = await rngContract.sortitionModule();
111-
if (currentSortitionModule !== sortitionModule.address) {
97+
const rngSortitionModule = await rng.sortitionModule();
98+
if (rngSortitionModule !== sortitionModule.address) {
11299
console.log(`rng.changeSortitionModule(${sortitionModule.address})`);
113-
await rngContract.changeSortitionModule(sortitionModule.address);
100+
await rng.changeSortitionModule(sortitionModule.address);
114101
}
115102

116103
const core = (await hre.ethers.getContract("KlerosCoreNeo")) as KlerosCoreNeo;
@@ -138,6 +125,7 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
138125
};
139126

140127
deployArbitration.tags = ["ArbitrationNeo"];
128+
deployArbitration.dependencies = ["ChainlinkRNG"];
141129
deployArbitration.skip = async ({ network }) => {
142130
return isSkipped(network, !HomeChains[network.config.chainId ?? 0]);
143131
};

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

+7-30
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import { DeployFunction } from "hardhat-deploy/types";
33
import { getContractAddress } from "./utils/getContractAddress";
44
import { deployUpgradable } from "./utils/deployUpgradable";
55
import { changeCurrencyRate } from "./utils/klerosCoreHelper";
6-
import { HomeChains, isSkipped, isDevnet, isMainnet, PNK, ETH } from "./utils";
6+
import { HomeChains, isSkipped, isDevnet, PNK, ETH } from "./utils";
77
import { getContractOrDeploy, getContractOrDeployUpgradable } from "./utils/getContractOrDeploy";
88
import { deployERC20AndFaucet } from "./utils/deployTokens";
9-
import { DisputeKitClassic, KlerosCore, RandomizerRNG } from "../typechain-types";
9+
import { ChainlinkRNG, DisputeKitClassic, KlerosCore } from "../typechain-types";
1010

1111
const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
1212
const { ethers, deployments, getNamedAccounts, getChainId } = hre;
@@ -28,30 +28,6 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
2828

2929
await getContractOrDeployUpgradable(hre, "EvidenceModule", { from: deployer, args: [deployer], log: true });
3030

31-
// Randomizer.ai: https://randomizer.ai/docs#addresses
32-
const randomizerOracle = await getContractOrDeploy(hre, "RandomizerOracle", {
33-
from: deployer,
34-
contract: "RandomizerMock", // The mock is deployed only on the Hardhat network
35-
args: [],
36-
log: true,
37-
});
38-
39-
const randomizerRng = await getContractOrDeploy(hre, "RandomizerRNG", {
40-
from: deployer,
41-
args: [deployer, ZeroAddress, randomizerOracle.target], // The SortitionModule is configured later
42-
log: true,
43-
});
44-
45-
const blockhashRng = await getContractOrDeploy(hre, "BlockHashRNG", {
46-
from: deployer,
47-
args: [],
48-
log: true,
49-
});
50-
51-
// RNG fallback on Arbitrum Sepolia because the Randomizer.ai oracle contract is unverified and not officially supported.
52-
const rng = isMainnet(hre.network) ? randomizerRng : blockhashRng;
53-
console.log(isMainnet(hre.network) ? "using RandomizerRNG on mainnet" : "using BlockHashRNG on testnet/devnet");
54-
5531
const disputeKit = await deployUpgradable(deployments, "DisputeKitClassic", {
5632
from: deployer,
5733
args: [deployer, ZeroAddress],
@@ -67,6 +43,7 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
6743
const devnet = isDevnet(hre.network);
6844
const minStakingTime = devnet ? 180 : 1800;
6945
const maxFreezingTime = devnet ? 600 : 1800;
46+
const rng = (await ethers.getContract("ChainlinkRNG")) as ChainlinkRNG;
7047
const sortitionModule = await deployUpgradable(deployments, "SortitionModule", {
7148
from: deployer,
7249
args: [deployer, klerosCoreAddress, minStakingTime, maxFreezingTime, rng.target, RNG_LOOKAHEAD],
@@ -103,11 +80,10 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
10380
}
10481

10582
// rng.changeSortitionModule() only if necessary
106-
const rngContract = (await ethers.getContract("RandomizerRNG")) as RandomizerRNG;
107-
const currentSortitionModule = await rngContract.sortitionModule();
108-
if (currentSortitionModule !== sortitionModule.address) {
83+
const rngSortitionModule = await rng.sortitionModule();
84+
if (rngSortitionModule !== sortitionModule.address) {
10985
console.log(`rng.changeSortitionModule(${sortitionModule.address})`);
110-
await rngContract.changeSortitionModule(sortitionModule.address);
86+
await rng.changeSortitionModule(sortitionModule.address);
11187
}
11288

11389
const core = (await hre.ethers.getContract("KlerosCore")) as KlerosCore;
@@ -121,6 +97,7 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
12197
};
12298

12399
deployArbitration.tags = ["Arbitration"];
100+
deployArbitration.dependencies = ["ChainlinkRNG"];
124101
deployArbitration.skip = async ({ network }) => {
125102
return isSkipped(network, !HomeChains[network.config.chainId ?? 0]);
126103
};

contracts/deploy/00-randomizer-rng.ts

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { HardhatRuntimeEnvironment } from "hardhat/types";
2+
import { DeployFunction } from "hardhat-deploy/types";
3+
import { HomeChains, isSkipped } from "./utils";
4+
import { getContractOrDeploy } from "./utils/getContractOrDeploy";
5+
6+
const deployRng: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
7+
const { deployments, getNamedAccounts, getChainId } = hre;
8+
const { deploy } = deployments;
9+
10+
// fallback to hardhat node signers on local network
11+
const deployer = (await getNamedAccounts()).deployer ?? (await hre.ethers.getSigners())[0].address;
12+
const chainId = Number(await getChainId()) as unknown as HomeChains; // Checked at runtime by skip()
13+
console.log("deploying to %s with deployer %s", HomeChains[chainId], deployer);
14+
15+
// Randomizer.ai: https://randomizer.ai/docs#addresses
16+
const randomizerOracle = await getContractOrDeploy(hre, "RandomizerOracle", {
17+
from: deployer,
18+
contract: "RandomizerMock", // The mock is deployed only on the Hardhat network
19+
args: [],
20+
log: true,
21+
});
22+
23+
await getContractOrDeploy(hre, "RandomizerRNG", {
24+
from: deployer,
25+
args: [deployer, deployer, randomizerOracle.target], // The consumer is configured as the SortitionModule later
26+
log: true,
27+
});
28+
};
29+
30+
deployRng.tags = ["RandomizerRNG"];
31+
deployRng.skip = async ({ network }) => {
32+
return isSkipped(network, !HomeChains[network.config.chainId ?? 0]);
33+
};
34+
35+
export default deployRng;

0 commit comments

Comments
 (0)