-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
54 lines (47 loc) · 1.69 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
require("dotenv").config();
import handler from "./api/liquidate";
import tokens from "./src/lib/tokens";
import ON_DEATH from "death";
import express from "express";
console.info("*** dotenv config loaded ***");
const app = express();
const main = async () => {
try {
console.info("*** STARTING LIQUIDATOR INTERVAL" + "***");
console.log("RPC_URL: " + process.env.RPC_URL);
console.log(
"TESTABLE_VM_ADDRESS ADDRESS: " + process.env.TESTABLE_VM_ADDRESS
);
console.log("LIQUIDATOR_ADDRESS: " + process.env.LIQUIDATOR_ADDRESS);
console.log(
"EXCHANGE_DIAMOND_ADDRESS: " + process.env.EXCHANGE_DIAMOND_ADDRESS
);
console.log(JSON.stringify({ tokens }));
const intervalPeriod = process.env.INTERVAL_PERIOD || 1000 * 60 * 5; // 5 minutes
console.log({ intervalPeriod });
// First invoke the handler
await handler();
const liquidatorTimer = setInterval(async () => {
await handler();
}, Number(intervalPeriod));
// TODO: Change for production :))
ON_DEATH({
uncaughtException: true,
})((signal, deathErr) => {
console.error(`*** SIGNAL: ${signal} ***`);
console.error(`*** deathErr: ${deathErr} ***`);
clearInterval(liquidatorTimer);
process.exit(0);
});
} catch (err) {
console.error("Error occured in index.ts:main");
console.error(err);
}
};
app.get("/", function (_req, res) {
res.send("Hello World!");
});
app.listen(process.env.PORT, async () => {
console.info("*** Server started on port " + process.env.PORT + " ***");
await main();
});