Skip to content

Commit fdadbec

Browse files
authored
Merge pull request #25 from kleros/fix/execution-registered-items
fix: add a check to avoid calling execute in a item not in pending
2 parents 37d6645 + daab3ea commit fdadbec

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

src/light-gtcr-execution.ts

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
import "colors";
2+
import delay from "delay";
13
import { ethers } from "ethers";
24
import fetch from "node-fetch";
3-
import delay from "delay";
4-
import "colors";
55

66
import _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

Comments
 (0)