-
Notifications
You must be signed in to change notification settings - Fork 173
/
index.ts
80 lines (71 loc) · 2.65 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
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
79
80
import { delay } from "@uma/financial-templates-lib";
import { BotModes, initMonitoringParams, Logger, startupLogLevel, waitNextBlockRange } from "./common";
import {
monitorProposalDeleted,
monitorProposalExecuted,
monitorSetCollateralAndBond,
monitorSetEscalationManager,
monitorSetIdentifier,
monitorSetLiveness,
monitorSetRules,
monitorTransactionsExecuted,
monitorTransactionsProposed,
} from "./MonitorEvents";
const logger = Logger;
async function main() {
const params = await initMonitoringParams(process.env);
logger[startupLogLevel(params)]({
at: "OOv3Monitor",
message: "Optimistic Oracle V3 Monitor started 🔭",
botModes: params.botModes,
});
const cmds = {
transactionsProposedEnabled: monitorTransactionsProposed,
transactionsExecutedEnabled: monitorTransactionsExecuted,
proposalExecutedEnabled: monitorProposalExecuted,
proposalDeletedEnabled: monitorProposalDeleted,
setCollateralAndBondEnabled: monitorSetCollateralAndBond,
setRulesEnabled: monitorSetRules,
setLivenessEnabled: monitorSetLiveness,
setIdentifierEnabled: monitorSetIdentifier,
setEscalationManagerEnabled: monitorSetEscalationManager,
};
for (;;) {
// In case of non-zero polling delay waitNextBlockRange at the end of the loop could have returned the starting block
// to be greater than the ending block if there were no new blocks in the last polling delay. In this case we should
// wait for the next block range before running the commands.
if (params.blockRange.start > params.blockRange.end) {
// In serverless it is possible for start block to be larger than end block if no new blocks were mined since last run.
if (params.pollingDelay === 0) {
await delay(5); // Set a delay to let the transports flush fully.
break;
}
params.blockRange = await waitNextBlockRange(params);
continue;
}
const runCmds = Object.entries(cmds)
.filter(([mode]) => params.botModes[mode as keyof BotModes])
.map(([, cmd]) => cmd(logger, params));
await Promise.all(runCmds);
// If polling delay is 0 then we are running in serverless mode and should exit after one iteration.
if (params.pollingDelay === 0) {
await delay(5); // Set a delay to let the transports flush fully.
break;
}
params.blockRange = await waitNextBlockRange(params);
}
}
main().then(
() => {
process.exit(0);
},
async (error) => {
logger.error({
at: "OOv3Monitor",
message: "Optimistic Oracle V3 Monitor execution error🚨",
error,
});
await delay(5); // Wait 5 seconds to allow logger to flush.
process.exit(1);
}
);