1+ import "colors" ;
2+ import delay from "delay" ;
13import { ethers } from "ethers" ;
24import fetch from "node-fetch" ;
3- import delay from "delay" ;
4- import "colors" ;
55
66import _LightGeneralizedTCR from "./assets/LightGeneralizedTCR.json" ;
77
@@ -10,7 +10,7 @@ async function run(signer: ethers.Wallet) {
1010 const subgraphQuery = {
1111 query : `
1212 {
13- lrequests(where: { resolved: false, disputed: false }) {
13+ lrequests(where: { resolved: false, disputed: false }, first: 1000 ) {
1414 submissionTime
1515 item {
1616 itemID
@@ -45,12 +45,28 @@ async function run(signer: ethers.Wallet) {
4545 console . info ( `Pending requests: ${ lrequests . length } ` . green ) ;
4646
4747 for ( let request of lrequests ) {
48+ console . info (
49+ `Executing request for item ID ${ request . item . itemID } @ ${ request . registry . id } `
50+ . green
51+ ) ;
52+
4853 let challengePeriodDuration ;
4954 const tcr = new ethers . Contract (
5055 request . registry . id ,
5156 _LightGeneralizedTCR ,
5257 signer
5358 ) ;
59+
60+ // double check against the contract if the item is still in pending state.
61+ const itemInfo = await tcr . callStatic . getItemInfo ( request . item . itemID ) ;
62+ if ( itemInfo . status === 1 || itemInfo . status === 0 ) {
63+ console . warn (
64+ `The item ${ request . item . itemID } is not in pending state. Current status: ${ itemInfo . status } . Skipping entry`
65+ . yellow
66+ ) ;
67+ continue ;
68+ }
69+
5470 let nonce ;
5571 try {
5672 nonce = await signer . getTransactionCount ( ) ;
@@ -71,27 +87,27 @@ async function run(signer: ethers.Wallet) {
7187 const challengePeriodEnd =
7288 Number ( request . submissionTime ) + challengePeriodDuration ;
7389 if ( Date . now ( ) / 1000 < challengePeriodEnd ) {
90+ console . debug ( "Challenge period not yet over. Skipping entry" . green ) ;
7491 continue ;
7592 }
7693
7794 try {
78- console . info (
79- `Executing request for item ID ${ request . item . itemID } ` . green
80- ) ;
8195 // pass gas requirement manually for arbitrum rinkeby compatibility
82- await tcr . executeRequest ( request . item . itemID , {
96+ const tx = await tcr . executeRequest ( request . item . itemID , {
8397 nonce,
8498 gasLimit : 2_100_000 ,
8599 } ) ;
86100 await delay ( 120 * 1000 ) ; // Wait 2 minutes to give time for the chain to sync/nonce handling.
101+ console . info ( `ExecuteRequest sent. Transaction hash: ${ tx . hash } ` . green ) ;
87102 } catch ( error ) {
88103 console . error (
89- `Failed to execute request for light curate item ${ request . item . itemID } `
104+ `Failed to execute request for light curate item ${ request . item . itemID } @ ${ request . registry . id } `
90105 . green
91106 ) ;
92107 console . error ( error ) ;
93108 }
94109 }
110+ console . log ( `All the items unregistered have been controlled` . green ) ;
95111}
96112
97113// Start bot.
0 commit comments