-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.ts
40 lines (36 loc) · 1.18 KB
/
example.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
import { EvmBatchProcessor } from '@subsquid/evm-processor'
import { createProcessor } from '..'
import * as erc20 from '../../abi/erc20'
import { notifyForEvent } from '../../notify/event'
import { Block, Context, Log } from '../../types'
import { OGN_ADDRESS } from '../../utils/addresses'
import { logFilter } from '../../utils/logFilter'
// This filter will listen to all ERC20 events on the OGN contract.
const filter = logFilter({
address: [OGN_ADDRESS],
topic0: Object.values(erc20.events).map((e) => e.topic),
})
createProcessor({
name: 'OGN ERC20 Events',
topic: 'OGN',
chainId: 1,
setup: (processor: EvmBatchProcessor) => {
processor.addLog(filter.value)
},
process: async (ctx: Context) => {
for (const block of ctx.blocks) {
for (const log of block.logs) {
if (filter.matches(log)) {
await processLog(ctx, block, log)
}
}
}
},
})
const processLog = async (ctx: Context, block: Block, log: Log) => {
const entry = Object.entries(erc20.events).find(([n, e]) => e.topic === log.topics[0])
if (entry) {
const [name, event] = entry
await notifyForEvent({ ctx, block, log, topic: 'OGN', eventName: name, event })
}
}