1
- import { ethers } from "hardhat" ;
1
+ import env from "./utils/env" ;
2
+ import loggerFactory from "./utils/logger" ;
3
+ import { BigNumber } from "ethers" ;
2
4
import hre = require( "hardhat" ) ;
3
5
import {
4
6
KlerosCore ,
@@ -11,6 +13,20 @@ import { DisputeRequestEventObject } from "../typechain-types/src/arbitration/in
11
13
import { HttpNetworkConfig } from "hardhat/types" ;
12
14
import { DeploymentsExtension } from "hardhat-deploy/types" ;
13
15
16
+ const { ethers } = hre ;
17
+ const HEARTBEAT_URL = env . optionalNoDefault ( "HEARTBEAT_URL_RELAYER_BOT" ) ;
18
+
19
+ const loggerOptions = env . optionalNoDefault ( "LOGTAIL_TOKEN_RELAYER_BOT" )
20
+ ? {
21
+ transportTargetOptions : {
22
+ target : "@logtail/pino" ,
23
+ options : { sourceToken : env . require ( "LOGTAIL_TOKEN_RELAYER_BOT" ) } ,
24
+ level : env . optional ( "LOG_LEVEL" , "info" ) ,
25
+ } ,
26
+ level : env . optional ( "LOG_LEVEL" , "info" ) , // for pino-pretty
27
+ }
28
+ : { } ;
29
+
14
30
export default async function main (
15
31
foreignNetwork : HttpNetworkConfig ,
16
32
foreignDeployments : DeploymentsExtension ,
@@ -28,21 +44,26 @@ export default async function main(
28
44
const foreignChainId = await foreignChainProvider . getNetwork ( ) . then ( ( network ) => network . chainId ) ;
29
45
const arbitrableInterface = IArbitrableV2__factory . createInterface ( ) ;
30
46
47
+ const logger = loggerFactory . createLogger ( loggerOptions ) . child ( { foreignChainId : foreignChainId } ) ;
48
+ logger . info ( `Listening for events from ${ foreignGatewayArtifact } ...` ) ;
49
+
50
+ if ( HEARTBEAT_URL ) {
51
+ logger . debug ( "Sending heartbeat" ) ;
52
+ fetch ( HEARTBEAT_URL ) ;
53
+ } else {
54
+ logger . debug ( "Heartbeat not set up, skipping" ) ;
55
+ }
56
+
31
57
// Event subscription
32
58
// WARNING: The callback might run more than once if the script is restarted in the same block
33
59
// type Listener = [ eventArg1, ...eventArgN, transactionReceipt ]
34
60
foreignGateway . on (
35
61
"CrossChainDisputeOutgoing" ,
36
62
async ( foreignBlockHash , foreignArbitrable , foreignDisputeID , choices , extraData , txReceipt ) => {
37
- console . log (
38
- "CrossChainDisputeOutgoing: %s %s %s %s %s" ,
39
- foreignBlockHash ,
40
- foreignArbitrable ,
41
- foreignDisputeID ,
42
- choices ,
43
- extraData
63
+ logger . info (
64
+ `CrossChainDisputeOutgoing: ${ foreignBlockHash } ${ foreignArbitrable } ${ foreignDisputeID } ${ choices } ${ extraData } `
44
65
) ;
45
- // console.log(" tx receipt: %O", txReceipt);
66
+ // logger.info(` tx receipt: ${JSON.stringify( txReceipt)}` );
46
67
47
68
// txReceipt is missing the full logs for this tx so we need to request it here
48
69
const fullTxReceipt = await foreignChainProvider . getTransactionReceipt ( txReceipt . transactionHash ) ;
@@ -51,7 +72,7 @@ export default async function main(
51
72
const disputeRequest = fullTxReceipt . logs
52
73
. filter ( ( log ) => log . topics [ 0 ] === arbitrableInterface . getEventTopic ( "DisputeRequest" ) )
53
74
. map ( ( log ) => arbitrableInterface . parseLog ( log ) . args as unknown as DisputeRequestEventObject ) [ 0 ] ;
54
- console . log ( " tx events DisputeRequest: %O" , disputeRequest ) ;
75
+ logger . info ( ` tx events DisputeRequest: ${ JSON . stringify ( disputeRequest ) } ` ) ;
55
76
// TODO: log a warning if there are multiple DisputeRequest events
56
77
57
78
const relayCreateDisputeParams = {
@@ -65,7 +86,7 @@ export default async function main(
65
86
choices : choices ,
66
87
extraData : extraData ,
67
88
} ;
68
- console . log ( " Relaying dispute to home chain... %O" , relayCreateDisputeParams ) ;
89
+ logger . info ( ` Relaying dispute to home chain... ${ JSON . stringify ( relayCreateDisputeParams ) } ` ) ;
69
90
70
91
let tx ;
71
92
if ( feeToken === undefined ) {
@@ -83,11 +104,10 @@ export default async function main(
83
104
] ( relayCreateDisputeParams , cost ) ;
84
105
}
85
106
tx = tx . wait ( ) ;
86
- console . log ( " relayCreateDispute txId: %O" , tx . transactionHash ) ;
107
+ logger . info ( ` relayCreateDispute txId: ${ tx . transactionHash } ` ) ;
87
108
}
88
109
) ;
89
110
90
- console . log ( "Listening for events..." ) ;
91
111
const delay = ( ms ) => new Promise ( ( x ) => setTimeout ( x , ms ) ) ;
92
- await delay ( 24 * 60 * 60 * 1000 ) ; // 24 hours
112
+ await delay ( 60 * 60 * 1000 ) ; // 1 hour
93
113
}
0 commit comments