-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
49 lines (43 loc) · 1.4 KB
/
index.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
/**
* Run commands like `BLOCK_FROM=18102886 PROCESSOR=Trace yarn process` to filter down what processors will be run.
*/
import fs from 'node:fs'
import { Processor, traceFilter } from '@originprotocol/squid-utils'
import { NotifyTarget, Severity, Topic } from '../notify/const'
export interface NotificationProcessor extends Processor {
chainId: number
topic: Topic
events?: {
address?: string[]
eventName?: string[]
topic1?: string[]
topic2?: string[]
topic3?: string[]
severity?: Severity
notifyTarget?: NotifyTarget
}[]
traces?: {
traceParams: Parameters<typeof traceFilter>[0][]
topic: Topic
severity?: Severity
notifyTarget?: NotifyTarget
}[]
}
const processors: NotificationProcessor[] = []
export const createProcessor = (processor: NotificationProcessor) => {
if (!process.env.PROCESSOR || processor.name?.includes(process.env.PROCESSOR)) {
processors.push(processor)
}
}
export const load = async () => {
const processorList = fs.readdirSync(`${__dirname}`)
for (const processor of processorList) {
if (processor === 'examples') continue
if (processor === 'templates') continue
if (processor === 'index.js') continue
if (!processor.endsWith('.js') && !processor.endsWith('.ts') && processor.includes('.')) continue
console.log(`Loading processor: ${processor}`)
await import(`./${processor}`)
}
return processors
}