-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandler.js
More file actions
67 lines (54 loc) · 2.03 KB
/
handler.js
File metadata and controls
67 lines (54 loc) · 2.03 KB
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
const { prepareFinalLiquidationData } = require("./contractCalls.js");
const { fetchLiquidationDataFromGraph } = require("./graph.js");
const config = require("./config.js");
const indexLiquidations = async () => {
console.log("####### Starting Liquidation Extraction ##########");
// chose protocol index to prepare liquidation data
let currentProtocolIndex = 0; //e.g aave v2 is selected
console.log(
`######### Indexing Protocol ${config.protocols[currentProtocolIndex].name} Chain: ${config.protocols[currentProtocolIndex].chainId} ###############`
);
// Run next active protocol if current protocol is disabled in config
while (true) {
if (!config.protocols[currentProtocolIndex].active) {
console.log(
`Inactive Protocol ${config.protocols[currentProtocolIndex].name} skipping `
);
currentProtocolIndex = (currentProtocolIndex + 1) % 14;
console.log(
`######### Starting Protocol ${config.protocols[currentProtocolIndex].name} Chain: ${config.protocols[currentProtocolIndex].chainId} ###############`
);
} else {
break;
}
}
const startTime =
new Date(config.protocols[currentProtocolIndex].startDate).getTime() / 1000;
const lastGraphDocId = null; //await getLastUpdateStatus(currentProtocolIndex);
const { liquidations, nextLastDocId } = await fetchLiquidationDataFromGraph(
startTime,
lastGraphDocId,
currentProtocolIndex
);
console.log({ liquidationCount: liquidations.length, nextLastDocId });
if (liquidations.length === 0) {
return {
statusCode: 200,
body: { message: "Liquidations already up to date" },
};
}
const finalLiquidationData = await prepareFinalLiquidationData(
liquidations,
currentProtocolIndex
);
console.log(
`######### Prepared ${finalLiquidationData.length} liquidations `
);
console.log(finalLiquidationData);
console.log("########### Done ##############");
return {
statusCode: 200,
body: { message: "Liquidation data updated" },
};
};
indexLiquidations();