-
Notifications
You must be signed in to change notification settings - Fork 4
/
seize_event.js
75 lines (61 loc) · 2.64 KB
/
seize_event.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
const ethers = require('ethers');
const TokenStaking = require("@keep-network/keep-core/artifacts/TokenStaking.json");
const KeepRandomBeaconOperator = require("@keep-network/keep-core/artifacts/KeepRandomBeaconOperator.json");
const config = require('./config')
const infura = config.infura_secret || process.env.INFURA_API;
const network = config.network || 'homestead'
if (process.argv.length < 3 || !process.argv[2]) {
console.error('node seize_event.js [address]');
process.exit(1);
}
async function main() {
let wallet
try {
const ip = new ethers.providers.InfuraProvider(network, infura);
let addr
try {
addr = ethers.utils.getAddress(process.argv[2])
} catch (err) {
console.error(`Invalid address supplied: ${err}`)
process.exit(1)
}
const stakingContract = new ethers.Contract(TokenStaking.networks["1"].address, TokenStaking.abi, ip);
const randomOpContract = new ethers.Contract(KeepRandomBeaconOperator.networks["1"].address, KeepRandomBeaconOperator.abi, ip);
console.log(ethers.utils.parseUnits('1000').toString());
const seizeEvents = await stakingContract.queryFilter(stakingContract.filters.TokensSeized(addr));
const timeoutEvents = await randomOpContract.queryFilter(randomOpContract.filters.RelayEntryTimeoutReported(null));
const seizeEventBlocks = seizeEvents.map(x => x.blockNumber);
const timeoutEventBlocks = new Set(timeoutEvents.map(x => x.blockNumber));
//const seizeEventSizes = seizeEvents.filter(x => !x.args[1].eq(ethers.utils.parseUnits('1000')));
console.log(seizeEventBlocks);
console.log(timeoutEventBlocks);
let events = new Map();
for (event of timeoutEvents) {
let idx = event.args[0];
//console.log(`group index: ${idx}`);
let pk = await randomOpContract.getGroupPublicKey(idx);
////console.log(`group pk: ${pk}`);
let members = await randomOpContract.getGroupMembers(pk);
let occurences = members.filter(x => x.toLowerCase() === addr.toLowerCase())
console.log(`[#${event.blockNumber}] ${addr} is in this group ${occurences} times`);
let mset = new Set(members);
if (!seizeEventBlocks.includes(event.blockNumber) && occurences > 0) {
console.log(`timeout event but no seize event`);
console.log(`tx hash: ${event.transactionHash}`);
}
for (member of mset) {
if (events.has(member)) { events.set(member, events.get(member) + 1); }
else { events.set(member, 1); }
}
//console.log(`members.length ${members.length} vs mset.size ${mset.size}`);
}
//console.log(events);
//console.log(slashEvents.size);
} catch(err) {
console.error(`Could not authorize: ${err.message}`)
process.exit(1)
}
}
main().catch(err => {
console.error(err);
})