1
- import {
2
- PNK ,
3
- RandomizerRNG ,
4
- BlockHashRNG ,
5
- SortitionModule ,
6
- KlerosCore ,
7
- KlerosCoreNeo ,
8
- SortitionModuleNeo ,
9
- DisputeKitClassic ,
10
- ChainlinkRNG ,
11
- } from "../typechain-types" ;
1
+ import hre from "hardhat" ;
2
+ import { toBigInt , BigNumberish , getNumber , BytesLike } from "ethers" ;
3
+ import { SortitionModule , SortitionModuleNeo } from "../typechain-types" ;
12
4
import env from "./utils/env" ;
13
5
import loggerFactory from "./utils/logger" ;
14
- import { toBigInt , BigNumberish , getNumber } from "ethers" ;
15
- import hre = require( "hardhat" ) ;
6
+ import { Cores , getContracts as getContractsForCoreType } from "./utils/contracts" ;
16
7
17
8
let request : < T > ( url : string , query : string ) => Promise < T > ; // Workaround graphql-request ESM import
18
9
const { ethers } = hre ;
@@ -44,29 +35,12 @@ const loggerOptions = env.optionalNoDefault("LOGTAIL_TOKEN_KEEPER_BOT")
44
35
const logger = loggerFactory . createLogger ( loggerOptions ) ;
45
36
46
37
const getContracts = async ( ) => {
47
- let core : KlerosCore | KlerosCoreNeo ;
48
- let sortition : SortitionModule | SortitionModuleNeo ;
49
- let disputeKitClassic : DisputeKitClassic ;
50
38
const coreType = Cores [ CORE_TYPE . toUpperCase ( ) as keyof typeof Cores ] ;
51
- switch ( coreType ) {
52
- case Cores . NEO :
53
- core = ( await ethers . getContract ( "KlerosCoreNeo" ) ) as KlerosCoreNeo ;
54
- sortition = ( await ethers . getContract ( "SortitionModuleNeo" ) ) as SortitionModuleNeo ;
55
- disputeKitClassic = ( await ethers . getContract ( "DisputeKitClassicNeo" ) ) as DisputeKitClassic ;
56
- break ;
57
- case Cores . BASE :
58
- core = ( await ethers . getContract ( "KlerosCore" ) ) as KlerosCore ;
59
- sortition = ( await ethers . getContract ( "SortitionModule" ) ) as SortitionModule ;
60
- disputeKitClassic = ( await ethers . getContract ( "DisputeKitClassic" ) ) as DisputeKitClassic ;
61
- break ;
62
- default :
63
- throw new Error ( "Invalid core type, must be one of base, neo" ) ;
39
+ if ( coreType === Cores . UNIVERSITY ) {
40
+ throw new Error ( "University is not supported yet" ) ;
64
41
}
65
- const chainlinkRng = await ethers . getContractOrNull < ChainlinkRNG > ( "ChainlinkRNG" ) ;
66
- const randomizerRng = await ethers . getContractOrNull < RandomizerRNG > ( "RandomizerRNG" ) ;
67
- const blockHashRNG = await ethers . getContractOrNull < BlockHashRNG > ( "BlockHashRNG" ) ;
68
- const pnk = ( await ethers . getContract ( "PNK" ) ) as PNK ;
69
- return { core, sortition, chainlinkRng, randomizerRng, blockHashRNG, disputeKitClassic, pnk } ;
42
+ const contracts = await getContractsForCoreType ( hre , coreType ) ;
43
+ return { ...contracts , sortition : contracts . sortition as SortitionModule | SortitionModuleNeo } ;
70
44
} ;
71
45
72
46
type Contribution = {
@@ -87,18 +61,14 @@ type Dispute = {
87
61
} ;
88
62
89
63
type CustomError = {
64
+ data : BytesLike ;
90
65
reason : string ;
91
66
code : string ;
92
67
errorArgs : any [ ] ;
93
68
errorName : string ;
94
69
errorSignature : string ;
95
70
} ;
96
71
97
- enum Cores {
98
- BASE ,
99
- NEO ,
100
- }
101
-
102
72
enum Phase {
103
73
STAKING = "staking" ,
104
74
GENERATING = "generating" ,
@@ -185,7 +155,7 @@ const handleError = (e: any) => {
185
155
const isRngReady = async ( ) => {
186
156
const { chainlinkRng, randomizerRng, blockHashRNG, sortition } = await getContracts ( ) ;
187
157
const currentRng = await sortition . rng ( ) ;
188
- if ( currentRng === chainlinkRng ?. target ) {
158
+ if ( currentRng === chainlinkRng ?. target && chainlinkRng !== null ) {
189
159
const requestID = await chainlinkRng . lastRequestId ( ) ;
190
160
const n = await chainlinkRng . randomNumbers ( requestID ) ;
191
161
if ( Number ( n ) === 0 ) {
@@ -195,7 +165,7 @@ const isRngReady = async () => {
195
165
logger . info ( `ChainlinkRNG is ready: ${ n . toString ( ) } ` ) ;
196
166
return true ;
197
167
}
198
- } else if ( currentRng === randomizerRng ?. target ) {
168
+ } else if ( currentRng === randomizerRng ?. target && randomizerRng !== null ) {
199
169
const requestID = await randomizerRng . lastRequestId ( ) ;
200
170
const n = await randomizerRng . randomNumbers ( requestID ) ;
201
171
if ( Number ( n ) === 0 ) {
@@ -205,7 +175,7 @@ const isRngReady = async () => {
205
175
logger . info ( `RandomizerRNG is ready: ${ n . toString ( ) } ` ) ;
206
176
return true ;
207
177
}
208
- } else if ( currentRng === blockHashRNG ?. target ) {
178
+ } else if ( currentRng === blockHashRNG ?. target && blockHashRNG !== null ) {
209
179
const requestBlock = await sortition . randomNumberRequestBlock ( ) ;
210
180
const lookahead = await sortition . rngLookahead ( ) ;
211
181
const n = await blockHashRNG . receiveRandomness . staticCall ( requestBlock + lookahead ) ;
@@ -229,7 +199,8 @@ const passPhase = async () => {
229
199
await sortition . passPhase . staticCall ( ) ;
230
200
} catch ( e ) {
231
201
const error = e as CustomError ;
232
- logger . info ( `passPhase: not ready yet because of ${ error ?. reason ?? error ?. errorName ?? error ?. code } ` ) ;
202
+ const errorDescription = sortition . interface . parseError ( error . data ) ?. signature ;
203
+ logger . info ( `passPhase: not ready yet because of ${ errorDescription } ` ) ;
233
204
return success ;
234
205
}
235
206
const before = getNumber ( await sortition . phase ( ) ) ;
@@ -254,11 +225,8 @@ const passPeriod = async (dispute: { id: string }) => {
254
225
await core . passPeriod . staticCall ( dispute . id ) ;
255
226
} catch ( e ) {
256
227
const error = e as CustomError ;
257
- logger . info (
258
- `passPeriod: not ready yet for dispute ${ dispute . id } because of error ${
259
- error ?. reason ?? error ?. errorName ?? error ?. code
260
- } `
261
- ) ;
228
+ const errorDescription = core . interface . parseError ( error . data ) ?. signature ;
229
+ logger . info ( `passPeriod: not ready yet for dispute ${ dispute . id } because of error ${ errorDescription } ` ) ;
262
230
return success ;
263
231
}
264
232
const before = ( await core . disputes ( dispute . id ) ) . period ;
@@ -567,7 +535,7 @@ async function main() {
567
535
}
568
536
if ( await isPhaseDrawing ( ) ) {
569
537
let maxDrawingTimePassed = await hasMaxDrawingTimePassed ( ) ;
570
- for ( dispute of disputesWithoutJurors ) {
538
+ for ( const dispute of disputesWithoutJurors ) {
571
539
if ( maxDrawingTimePassed ) {
572
540
logger . info ( "Max drawing time passed" ) ;
573
541
break ;
0 commit comments