-
Notifications
You must be signed in to change notification settings - Fork 4
/
listener.js
79 lines (72 loc) · 2.89 KB
/
listener.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
72
73
74
75
76
77
78
// const { CONTRACTS, ADDRESS, PROVIDERS } = require("./constants/index.js")
const { ADDRESS } = require("./constants/address")
const {WS_PROVIDERS, PROVIDERS } = require("./constants/providers")
const { CONTRACTS } = require("./constants/contracts")
const { CONFIG } = require("./constants/config")
const { PrizeWinsToDb } = require("./functions/prizeWinsToDb.js")
//const LiquidateNow = require("./liquidator.js")
const { AddClaim } = require("./functions/dbDonkey.js")
const ethers = require("ethers")
const { DiscordNotifyClaimPrize } = require("./functions/discordAlert.js")
const { DailyReport } = require("./functions/dailyReport")
const chain = CONFIG.CHAINNAME
const chainId = CONFIG.CHAINID
const prizepool = CONFIG.PRIZEPOOL
const FILTERS = {
// draw awarded
DRAWAWARDED: {
address: ADDRESS[chain].PRIZEPOOL,
topics: ["0x60785c409db91938793d3f74013b06843f82ea0588265495b262b016fe5323ae"]
},
/*
DRAWCLOSED: {
address: ADDRESS[chain].PRIZEPOOL,
topics: ["0x330a72bcfcfc5c9a30ef8bdce22a7499068847d7e5ad7330f3a81fdd1e6e996d"]
},
// old for sepolia
/* CLAIMEDPRIZE: {
address: ADDRESS[chain].PRIZEPOOL,
topics: ["0xc31bc4fb7f1c35cfd7aa34780f09c3f0a97653a70920593b2284de94a4772957"]
},*/
CLAIMEDPRIZE: {
address: ADDRESS[chain].PRIZEPOOL,
topics: ["0x81d4e3306aa30f56dc9c3949abd8c27539b445f9ef380425f39f3f7114888e4f"]
},
}
async function listen() {
console.log("listening for complete award and claim events")
PROVIDERS[chain].on(FILTERS.DRAWAWARDED, (drawCompletedEvent) => {
console.log("draw completed event", drawCompletedEvent)
try{DailyReport()}catch(e){console.log(e)}
try {
PrizeWinsToDb(chainId,ADDRESS[chain].PRIZEPOOL.toLowerCase(),drawCompletedEvent.blockNumber).then((finished)=>{console.log("db updated")})
}catch(error){console.log(error)}
//try{LiquidateNow()}catch(e){console.log(e)}
})
//console.log(WS_PROVIDERS[chain])
PROVIDERS[chain].on(FILTERS.CLAIMEDPRIZE, (claimEvent) => {
try {
// console.log("prize claimed event ", claimEvent)
const decodedLog =
CONTRACTS.PRIZEPOOL[chain].interface.parseLog(claimEvent);
//console.log("claim event",decodedLog)
const args = decodedLog.args
const claim = {
network: chainId,
drawId: args.drawId,
vault: args.vault.toLowerCase(),
winner: args.winner.toLowerCase(),
tier: args.tier,
index: args.prizeIndex,
payout: args.payout,
fee: args.fee,
miner: args.feeRecipient.toLowerCase(),
hash: claimEvent.transactionHash.toLowerCase(),
block: claimEvent.blockNumber
};
AddClaim(chainId,prizepool,claim).then((finished)=>{})
DiscordNotifyClaimPrize(claim).then((finished)=>{})
}catch(error){console.log(error)}
})
}
listen()