Skip to content

Commit 026fe83

Browse files
committed
feat(bot): keeper bot support gated and gated shutter dk
1 parent 2166ee0 commit 026fe83

File tree

2 files changed

+45
-19
lines changed

2 files changed

+45
-19
lines changed

contracts/scripts/keeperBot.ts

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import hre from "hardhat";
22
import { toBigInt, BigNumberish, getNumber, BytesLike } from "ethers";
3-
import { DisputeKitClassic, DisputeKitShutter, SortitionModule, SortitionModuleNeo } from "../typechain-types";
3+
import {
4+
DisputeKitClassic,
5+
DisputeKitGated,
6+
DisputeKitGatedShutter,
7+
DisputeKitShutter,
8+
SortitionModule,
9+
SortitionModuleNeo,
10+
} from "../typechain-types";
411
import env from "./utils/env";
512
import loggerFactory from "./utils/logger";
613
import { Cores, getContracts as getContractsForCoreType } from "./utils/contracts";
@@ -92,14 +99,14 @@ const getDisputeKit = async (
9299
coreDisputeId: string,
93100
coreRoundId: string
94101
): Promise<{
95-
disputeKit: DisputeKitClassic | DisputeKitShutter;
102+
disputeKit: DisputeKitClassic | DisputeKitShutter | DisputeKitGated | DisputeKitGatedShutter;
96103
localDisputeId: bigint;
97104
localRoundId: bigint;
98105
}> => {
99-
const { core, disputeKitClassic, disputeKitShutter } = await getContracts();
106+
const { core, disputeKitClassic, disputeKitShutter, disputeKitGated, disputeKitGatedShutter } = await getContracts();
100107
const round = await core.getRoundInfo(coreDisputeId, coreRoundId);
101108
const disputeKitAddress = await core.disputeKits(round.disputeKitID);
102-
let disputeKit: DisputeKitClassic | DisputeKitShutter;
109+
let disputeKit: DisputeKitClassic | DisputeKitShutter | DisputeKitGated | DisputeKitGatedShutter;
103110
switch (disputeKitAddress) {
104111
case disputeKitClassic.target:
105112
disputeKit = disputeKitClassic;
@@ -108,6 +115,14 @@ const getDisputeKit = async (
108115
if (!disputeKitShutter) throw new Error(`DisputeKitShutter not deployed`);
109116
disputeKit = disputeKitShutter;
110117
break;
118+
case disputeKitGated?.target:
119+
if (!disputeKitGated) throw new Error(`DisputeKitGated not deployed`);
120+
disputeKit = disputeKitGated;
121+
break;
122+
case disputeKitGatedShutter?.target:
123+
if (!disputeKitGatedShutter) throw new Error(`DisputeKitGatedShutter not deployed`);
124+
disputeKit = disputeKitGatedShutter;
125+
break;
111126
default:
112127
throw new Error(`Unknown dispute kit: ${disputeKitAddress}`);
113128
}
@@ -527,7 +542,7 @@ const shutdown = async () => {
527542
};
528543

529544
async function main() {
530-
const { core, sortition, disputeKitShutter } = await getContracts();
545+
const { core, sortition, disputeKitShutter, disputeKitGatedShutter } = await getContracts();
531546

532547
const getBlockTime = async () => {
533548
return await ethers.provider.getBlock("latest").then((block) => {
@@ -604,6 +619,7 @@ async function main() {
604619
await passPeriod(dispute);
605620
}
606621
await shutterAutoReveal(disputeKitShutter, DISPUTES_TO_SKIP);
622+
await shutterAutoReveal(disputeKitGatedShutter, DISPUTES_TO_SKIP);
607623
if (SHUTTER_AUTO_REVEAL_ONLY) {
608624
logger.debug("Shutter auto-reveal only, skipping other actions");
609625
await shutdown();

contracts/scripts/keeperBotShutter.ts

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
import hre from "hardhat";
22
import { getBytes } from "ethers";
3-
import { DisputeKitShutter, SortitionModule, SortitionModuleNeo } from "../typechain-types";
3+
import { DisputeKitGatedShutter, DisputeKitShutter, SortitionModule, SortitionModuleNeo } from "../typechain-types";
44
import { decrypt } from "./shutter";
55
import env from "./utils/env";
66
import loggerFactory from "./utils/logger";
77
import { Cores, getContracts as getContractsForCoreType } from "./utils/contracts";
88

99
const SUBGRAPH_URL = env.require("SUBGRAPH_URL");
1010
const CORE_TYPE = env.optional("CORE_TYPE", "base");
11+
const DISPUTES_TO_SKIP = env
12+
.optional("DISPUTES_TO_SKIP", "")
13+
.split(",")
14+
.map((s) => s.trim());
1115

1216
const loggerOptions = env.optionalNoDefault("LOGTAIL_TOKEN_KEEPER_BOT")
1317
? {
@@ -23,15 +27,6 @@ const loggerOptions = env.optionalNoDefault("LOGTAIL_TOKEN_KEEPER_BOT")
2327
};
2428
const logger = loggerFactory.createLogger(loggerOptions);
2529

26-
const getContracts = async () => {
27-
const coreType = Cores[CORE_TYPE.toUpperCase() as keyof typeof Cores];
28-
if (coreType === Cores.UNIVERSITY) {
29-
throw new Error("University is not supported yet");
30-
}
31-
const contracts = await getContractsForCoreType(hre, coreType);
32-
return { ...contracts, sortition: contracts.sortition as SortitionModule | SortitionModuleNeo };
33-
};
34-
3530
/**
3631
* Decodes a message string into its component parts
3732
* @param message The message to decode
@@ -77,7 +72,9 @@ type DisputeVotes = {
7772
};
7873
};
7974

80-
const getShutterDisputesToReveal = async (disputeKitShutter: DisputeKitShutter): Promise<DisputeVotes[]> => {
75+
const getShutterDisputesToReveal = async (
76+
disputeKitShutter: DisputeKitShutter | DisputeKitGatedShutter
77+
): Promise<DisputeVotes[]> => {
8178
const { gql, request } = await import("graphql-request"); // workaround for ESM import
8279
const query = gql`
8380
query DisputeToAutoReveal($shutterDisputeKit: Bytes) {
@@ -191,7 +188,10 @@ const getShutterDisputesToReveal = async (disputeKitShutter: DisputeKitShutter):
191188
return filteredDisputeVotes;
192189
};
193190

194-
export const shutterAutoReveal = async (disputeKitShutter: DisputeKitShutter | null, disputesToSkip: string[]) => {
191+
export const shutterAutoReveal = async (
192+
disputeKitShutter: DisputeKitShutter | DisputeKitGatedShutter | null,
193+
disputesToSkip: string[]
194+
) => {
195195
if (!disputeKitShutter) {
196196
logger.debug("No Shutter dispute kit found, skipping auto-reveal");
197197
return [];
@@ -307,10 +307,20 @@ export const shutterAutoReveal = async (disputeKitShutter: DisputeKitShutter | n
307307
}
308308
};
309309

310+
const getContracts = async () => {
311+
const coreType = Cores[CORE_TYPE.toUpperCase() as keyof typeof Cores];
312+
if (coreType === Cores.UNIVERSITY) {
313+
throw new Error("University is not supported yet");
314+
}
315+
const contracts = await getContractsForCoreType(hre, coreType);
316+
return { ...contracts, sortition: contracts.sortition as SortitionModule | SortitionModuleNeo };
317+
};
318+
310319
async function main() {
311320
logger.debug("Starting...");
312-
const { disputeKitShutter } = await getContracts();
313-
await shutterAutoReveal(disputeKitShutter, ["44", "45", "51", "54"]);
321+
const { disputeKitShutter, disputeKitGatedShutter } = await getContracts();
322+
await shutterAutoReveal(disputeKitShutter, DISPUTES_TO_SKIP);
323+
await shutterAutoReveal(disputeKitGatedShutter, DISPUTES_TO_SKIP);
314324
}
315325

316326
if (require.main === module) {

0 commit comments

Comments
 (0)