-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.ts
79 lines (64 loc) · 2.35 KB
/
main.ts
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
import { ethers } from "ethers"
import { isCow } from "./cow"
import { sendDiscordMessage } from "./discord"
import { sendTwitterMessage } from "./twitter"
import config from './config.json'
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms))
}
(async () => {
try {
console.log("start")
const provider = new ethers.providers.JsonRpcProvider(config.main.providerUrl)
const contractAddress = "0x9008d19f58aabd9ed0d60971565aa8510560ab41"
let endBlock = await provider.getBlockNumber()
let startBlock = endBlock
while(1) {
console.log("====================")
console.log('s:', startBlock)
console.log('e:', endBlock)
const filt = {
address: contractAddress,
fromBlock: startBlock, //13332639
toBlock: endBlock //13349144
}
const logs = await provider.getLogs(filt)
// group tx
let transactions = new Array()
for (const log of logs) {
const txHash = log.transactionHash
if (!transactions.includes(txHash)) {
transactions.push(txHash)
}
}
for (const txHash of transactions) {
const txReceipt = await provider.getTransactionReceipt(txHash)
const txLogs = txReceipt.logs
const result = isCow(txLogs)
console.log(txHash)
console.log(result)
if (result) {
// count trades in transaction
let total_trade = 0
for (const entry of txLogs) {
if (entry.topics[0] == "0xa07a543ab8a018198e99ca0184c93fe9050a79400a0a723441f84de1d972cc17") {
total_trade = total_trade + 1
}
}
const text = "We found a CoW, included " + total_trade + " trades. Transaction detail: https://etherscan.io/tx/" + txHash
console.log(text)
sendDiscordMessage(text, config.discord.webHookUrl)
sendDiscordMessage(text, config.discord.webHookUrl1)
sendTwitterMessage(text)
}
}
// wait to fetch data every minutes
await sleep(60000)
startBlock = endBlock + 1
endBlock = await provider.getBlockNumber()
}
} catch (e) {
console.log("errer:")
console.log(e)
}
})()