Skip to content

Commit a8f3415

Browse files
committed
chore: deployment script support for RNGWithFallback
1 parent da7eea1 commit a8f3415

10 files changed

+91
-143
lines changed

contracts/deploy/00-ethereum-pnk.ts

Lines changed: 0 additions & 31 deletions
This file was deleted.

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

Lines changed: 15 additions & 7 deletions
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 { ChainlinkRNG, DisputeKitClassic, KlerosCoreNeo } from "../typechain-types";
9+
import { ChainlinkRNG, DisputeKitClassic, KlerosCoreNeo, RNGWithFallback } from "../typechain-types";
1010

1111
const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
1212
const { ethers, deployments, getNamedAccounts, getChainId } = hre;
@@ -44,12 +44,20 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
4444
const devnet = isDevnet(hre.network);
4545
const minStakingTime = devnet ? 180 : 1800;
4646
const maxFreezingTime = devnet ? 600 : 1800;
47-
const rng = (await ethers.getContract("ChainlinkRNG")) as ChainlinkRNG;
47+
const rngWithFallback = await ethers.getContract<RNGWithFallback>("RNGWithFallback");
4848
const maxStakePerJuror = PNK(2_000);
4949
const maxTotalStaked = PNK(2_000_000);
5050
const sortitionModule = await deployUpgradable(deployments, "SortitionModuleNeo", {
5151
from: deployer,
52-
args: [deployer, klerosCoreAddress, minStakingTime, maxFreezingTime, rng.target, maxStakePerJuror, maxTotalStaked],
52+
args: [
53+
deployer,
54+
klerosCoreAddress,
55+
minStakingTime,
56+
maxFreezingTime,
57+
rngWithFallback.target,
58+
maxStakePerJuror,
59+
maxTotalStaked,
60+
],
5361
log: true,
5462
}); // nonce (implementation), nonce+1 (proxy)
5563

@@ -84,11 +92,11 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
8492
await disputeKitContract.changeCore(klerosCore.address);
8593
}
8694

87-
// rng.changeConsumer() only if necessary
88-
const rngConsumer = await rng.consumer();
95+
// rngWithFallback.changeConsumer() only if necessary
96+
const rngConsumer = await rngWithFallback.consumer();
8997
if (rngConsumer !== sortitionModule.address) {
90-
console.log(`rng.changeConsumer(${sortitionModule.address})`);
91-
await rng.changeConsumer(sortitionModule.address);
98+
console.log(`rngWithFallback.changeConsumer(${sortitionModule.address})`);
99+
await rngWithFallback.changeConsumer(sortitionModule.address);
92100
}
93101

94102
const core = (await hre.ethers.getContract("KlerosCoreNeo")) as KlerosCoreNeo;

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { changeCurrencyRate } from "./utils/klerosCoreHelper";
66
import { HomeChains, isSkipped, isDevnet, PNK, ETH, Courts } from "./utils";
77
import { getContractOrDeploy, getContractOrDeployUpgradable } from "./utils/getContractOrDeploy";
88
import { deployERC20AndFaucet } from "./utils/deployTokens";
9-
import { ChainlinkRNG, DisputeKitClassic, KlerosCore } from "../typechain-types";
9+
import { ChainlinkRNG, DisputeKitClassic, KlerosCore, RNGWithFallback } from "../typechain-types";
1010

1111
const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
1212
const { ethers, deployments, getNamedAccounts, getChainId } = hre;
@@ -49,10 +49,10 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
4949
const devnet = isDevnet(hre.network);
5050
const minStakingTime = devnet ? 180 : 1800;
5151
const maxFreezingTime = devnet ? 600 : 1800;
52-
const rng = (await ethers.getContract("ChainlinkRNG")) as ChainlinkRNG;
52+
const rngWithFallback = await ethers.getContract<RNGWithFallback>("RNGWithFallback");
5353
const sortitionModule = await deployUpgradable(deployments, "SortitionModule", {
5454
from: deployer,
55-
args: [deployer, klerosCoreAddress, minStakingTime, maxFreezingTime, rng.target],
55+
args: [deployer, klerosCoreAddress, minStakingTime, maxFreezingTime, rngWithFallback.target],
5656
log: true,
5757
}); // nonce (implementation), nonce+1 (proxy)
5858

@@ -79,18 +79,18 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
7979
}); // nonce+2 (implementation), nonce+3 (proxy)
8080

8181
// disputeKit.changeCore() only if necessary
82-
const disputeKitContract = (await ethers.getContract("DisputeKitClassic")) as DisputeKitClassic;
82+
const disputeKitContract = await ethers.getContract<DisputeKitClassic>("DisputeKitClassic");
8383
const currentCore = await disputeKitContract.core();
8484
if (currentCore !== klerosCore.address) {
8585
console.log(`disputeKit.changeCore(${klerosCore.address})`);
8686
await disputeKitContract.changeCore(klerosCore.address);
8787
}
8888

89-
// rng.changeConsumer() only if necessary
90-
const rngConsumer = await rng.consumer();
89+
// rngWithFallback.changeConsumer() only if necessary
90+
const rngConsumer = await rngWithFallback.consumer();
9191
if (rngConsumer !== sortitionModule.address) {
92-
console.log(`rng.changeConsumer(${sortitionModule.address})`);
93-
await rng.changeConsumer(sortitionModule.address);
92+
console.log(`rngWithFallback.changeConsumer(${sortitionModule.address})`);
93+
await rngWithFallback.changeConsumer(sortitionModule.address);
9494
}
9595

9696
const core = (await hre.ethers.getContract("KlerosCore")) as KlerosCore;

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

Lines changed: 0 additions & 36 deletions
This file was deleted.

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

Lines changed: 2 additions & 1 deletion
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 { HomeChains, isSkipped } from "./utils";
4+
import { getContractOrDeploy } from "./utils/getContractOrDeploy";
45

56
const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
67
const { deployments, getNamedAccounts, getChainId } = hre;
@@ -14,7 +15,7 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
1415
const klerosCore = await deployments.get("KlerosCore");
1516
const disputeTemplateRegistry = await deployments.get("DisputeTemplateRegistry");
1617

17-
await deploy("DisputeResolver", {
18+
await getContractOrDeploy(hre, "DisputeResolver", {
1819
from: deployer,
1920
args: [klerosCore.address, disputeTemplateRegistry.address],
2021
log: true,

contracts/deploy/00-chainlink-rng.ts renamed to contracts/deploy/00-rng-chainlink.ts

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import { HardhatRuntimeEnvironment } from "hardhat/types";
22
import { DeployFunction } from "hardhat-deploy/types";
33
import { HomeChains, isSkipped } from "./utils";
44
import { getContractOrDeploy } from "./utils/getContractOrDeploy";
5+
import { RNGWithFallback } from "../typechain-types";
56

67
const deployRng: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
7-
const { deployments, getNamedAccounts, getChainId } = hre;
8-
const { deploy } = deployments;
8+
const { getNamedAccounts, getChainId, ethers } = hre;
99

1010
// fallback to hardhat node signers on local network
1111
const deployer = (await getNamedAccounts()).deployer ?? (await hre.ethers.getSigners())[0].address;
@@ -57,11 +57,16 @@ const deployRng: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
5757
const requestConfirmations = 200; // between 1 and 200 L2 blocks
5858
const callbackGasLimit = 100000;
5959

60-
await deploy("ChainlinkRNG", {
60+
const oldRng = await ethers.getContractOrNull("ChainlinkRNG");
61+
if (!oldRng) {
62+
console.log("Register this Chainlink consumer here: http://vrf.chain.link/");
63+
}
64+
65+
const rng = await getContractOrDeploy(hre, "ChainlinkRNG", {
6166
from: deployer,
6267
args: [
6368
deployer,
64-
deployer, // The consumer is configured as the SortitionModule later
69+
deployer, // The consumer is configured as the RNGWithFallback later
6570
ChainlinkVRFCoordinator.target,
6671
keyHash,
6772
subscriptionId,
@@ -71,7 +76,25 @@ const deployRng: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
7176
log: true,
7277
});
7378

74-
console.log("Register this Chainlink consumer here: http://vrf.chain.link/");
79+
const fallbackTimeoutSeconds = 30 * 60; // 30 minutes
80+
await getContractOrDeploy(hre, "RNGWithFallback", {
81+
from: deployer,
82+
args: [
83+
deployer,
84+
deployer, // The consumer is configured as the SortitionModule later
85+
fallbackTimeoutSeconds,
86+
rng.target,
87+
],
88+
log: true,
89+
});
90+
91+
// rng.changeConsumer() only if necessary
92+
const rngWithFallback = await ethers.getContract<RNGWithFallback>("RNGWithFallback");
93+
const rngConsumer = await rng.consumer();
94+
if (rngConsumer !== rngWithFallback.target) {
95+
console.log(`rng.changeConsumer(${rngWithFallback.target})`);
96+
await rng.changeConsumer(rngWithFallback.target);
97+
}
7598
};
7699

77100
deployRng.tags = ["ChainlinkRNG"];

contracts/deploy/00-randomizer-rng.ts renamed to contracts/deploy/00-rng-randomizer.ts

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import { HardhatRuntimeEnvironment } from "hardhat/types";
22
import { DeployFunction } from "hardhat-deploy/types";
33
import { HomeChains, isSkipped } from "./utils";
44
import { getContractOrDeploy } from "./utils/getContractOrDeploy";
5+
import { RNGWithFallback } from "../typechain-types";
56

67
const deployRng: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
7-
const { deployments, getNamedAccounts, getChainId } = hre;
8-
const { deploy } = deployments;
8+
const { getNamedAccounts, getChainId, ethers } = hre;
99

1010
// fallback to hardhat node signers on local network
1111
const deployer = (await getNamedAccounts()).deployer ?? (await hre.ethers.getSigners())[0].address;
@@ -20,11 +20,35 @@ const deployRng: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
2020
log: true,
2121
});
2222

23-
await getContractOrDeploy(hre, "RandomizerRNG", {
23+
const rng = await getContractOrDeploy(hre, "RandomizerRNG", {
2424
from: deployer,
25-
args: [deployer, deployer, randomizerOracle.target], // The consumer is configured as the SortitionModule later
25+
args: [
26+
deployer,
27+
deployer, // The consumer is configured as the RNGWithFallback later
28+
randomizerOracle.target,
29+
],
2630
log: true,
2731
});
32+
33+
const fallbackTimeoutSeconds = 30 * 60; // 30 minutes
34+
await getContractOrDeploy(hre, "RNGWithFallback", {
35+
from: deployer,
36+
args: [
37+
deployer,
38+
deployer, // The consumer is configured as the SortitionModule later
39+
fallbackTimeoutSeconds,
40+
rng.target,
41+
],
42+
log: true,
43+
});
44+
45+
// rng.changeConsumer() only if necessary
46+
const rngWithFallback = await ethers.getContract<RNGWithFallback>("RNGWithFallback");
47+
const rngConsumer = await rng.consumer();
48+
if (rngConsumer !== rngWithFallback.target) {
49+
console.log(`rng.changeConsumer(${rngWithFallback.target})`);
50+
await rng.changeConsumer(rngWithFallback.target);
51+
}
2852
};
2953

3054
deployRng.tags = ["RandomizerRNG"];

contracts/deploy/00-rng.ts

Lines changed: 0 additions & 50 deletions
This file was deleted.

contracts/test/rng/index.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expect } from "chai";
2-
import { deployments, ethers, network } from "hardhat";
2+
import { deployments, ethers, getNamedAccounts, network } from "hardhat";
33
import {
44
IncrementalNG,
55
BlockHashRNG,
@@ -11,6 +11,7 @@ import {
1111

1212
const initialNg = 424242;
1313
const abiCoder = ethers.AbiCoder.defaultAbiCoder();
14+
let deployer: string;
1415

1516
describe("IncrementalNG", async () => {
1617
let rng: IncrementalNG;
@@ -85,12 +86,16 @@ describe("ChainlinkRNG", async () => {
8586
let vrfCoordinator: ChainlinkVRFCoordinatorV2Mock;
8687

8788
beforeEach("Setup", async () => {
89+
({ deployer } = await getNamedAccounts());
90+
8891
await deployments.fixture(["ChainlinkRNG"], {
8992
fallbackToGlobal: true,
9093
keepExistingDeployments: false,
9194
});
9295
rng = (await ethers.getContract("ChainlinkRNG")) as ChainlinkRNG;
9396
vrfCoordinator = (await ethers.getContract("ChainlinkVRFCoordinator")) as ChainlinkVRFCoordinatorV2Mock;
97+
98+
await rng.changeConsumer(deployer);
9499
});
95100

96101
it("Should return a non-zero random number", async () => {
@@ -144,12 +149,16 @@ describe("RandomizerRNG", async () => {
144149
let randomizer: RandomizerMock;
145150

146151
beforeEach("Setup", async () => {
152+
({ deployer } = await getNamedAccounts());
153+
147154
await deployments.fixture(["RandomizerRNG"], {
148155
fallbackToGlobal: true,
149156
keepExistingDeployments: false,
150157
});
151158
rng = (await ethers.getContract("RandomizerRNG")) as RandomizerRNG;
152159
randomizer = (await ethers.getContract("RandomizerOracle")) as RandomizerMock;
160+
161+
await rng.changeConsumer(deployer);
153162
});
154163

155164
it("Should return a non-zero random number", async () => {

0 commit comments

Comments
 (0)