Skip to content

Commit 555f04a

Browse files
committed
feat: added support for the chainlink rng in the keeper bot
1 parent 3f2baa0 commit 555f04a

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

contracts/scripts/keeperBot.ts

+17-5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
KlerosCoreNeo,
88
SortitionModuleNeo,
99
DisputeKitClassic,
10+
ChainlinkRNG,
1011
} from "../typechain-types";
1112
import request from "graphql-request";
1213
import env from "./utils/env";
@@ -61,10 +62,11 @@ const getContracts = async () => {
6162
default:
6263
throw new Error("Invalid core type, must be one of base, neo");
6364
}
65+
const chainlinkRng = await ethers.getContractOrNull<ChainlinkRNG>("ChainlinkRNG");
6466
const randomizerRng = await ethers.getContractOrNull<RandomizerRNG>("RandomizerRNG");
6567
const blockHashRNG = await ethers.getContractOrNull<BlockHashRNG>("BlockHashRNG");
6668
const pnk = (await ethers.getContract("PNK")) as PNK;
67-
return { core, sortition, randomizerRng, blockHashRNG, disputeKitClassic, pnk };
69+
return { core, sortition, chainlinkRng, randomizerRng, blockHashRNG, disputeKitClassic, pnk };
6870
};
6971

7072
type Contribution = {
@@ -181,11 +183,21 @@ const handleError = (e: any) => {
181183
};
182184

183185
const isRngReady = async () => {
184-
const { randomizerRng, blockHashRNG, sortition } = await getContracts();
186+
const { chainlinkRng, randomizerRng, blockHashRNG, sortition } = await getContracts();
185187
const currentRng = await sortition.rng();
186-
if (currentRng === randomizerRng?.target) {
187-
const requesterID = await randomizerRng.requesterToID(sortition.target);
188-
const n = await randomizerRng.randomNumbers(requesterID);
188+
if (currentRng === chainlinkRng?.target) {
189+
const requestID = await chainlinkRng.lastRequestId();
190+
const n = await chainlinkRng.randomNumbers(requestID);
191+
if (Number(n) === 0) {
192+
logger.info("ChainlinkRNG is NOT ready yet");
193+
return false;
194+
} else {
195+
logger.info(`ChainlinkRNG is ready: ${n.toString()}`);
196+
return true;
197+
}
198+
} else if (currentRng === randomizerRng?.target) {
199+
const requestID = await randomizerRng.lastRequestId();
200+
const n = await randomizerRng.randomNumbers(requestID);
189201
if (Number(n) === 0) {
190202
logger.info("RandomizerRNG is NOT ready yet");
191203
return false;

contracts/src/rng/RandomizerRNG.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ contract RandomizerRNG is RNG {
1616
address public sortitionModule; // The address of the SortitionModule.
1717
IRandomizer public randomizer; // Randomizer address.
1818
uint256 public callbackGasLimit; // Gas limit for the Randomizer.ai callback.
19-
uint256 lastRequestId; // The last request ID.
19+
uint256 public lastRequestId; // The last request ID.
2020
mapping(uint256 requestId => uint256 number) public randomNumbers; // randomNumbers[requestID] is the random number for this request id, 0 otherwise.
2121

2222
// ************************************* //

0 commit comments

Comments
 (0)