-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnetLost.js
62 lines (51 loc) · 1.71 KB
/
netLost.js
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
const { PrismaClient } = require("@prisma/client");
const prisma = new PrismaClient();
const { top10Token_ETHEREUM, top10Token_POLYGON } = require("./constant");
const fs = require("fs");
async function main(top10Tokens) {
const tokens = "USDT,BNB,USDC,BUSD,MATIC,WBTC,AVAX,SHIB,DAI,UNI";
const response = await fetch(
`https://min-api.cryptocompare.com/data/pricemulti?fsyms=${tokens}&tsyms=USD`
);
const price = await response.json();
const result = [];
const contractAddresses = await prisma.contractAddresses.findMany({
where: {
network: "POLYGON_MAINNET",
},
});
for (const contract of contractAddresses) {
const tokenValue = JSON.parse(contract.tokenValue);
if (Object.keys(tokenValue).length === 0) {
continue;
}
var diffSum = 0;
var initialSum = 0;
diffSum = (tokenValue["ETH"]["diffvalue"] * price["MATIC"]["USD"]) / 1e18;
initialSum =
(tokenValue["ETH"]["initialValue"] * price["MATIC"]["USD"]) / 1e18;
top10Tokens.forEach((top10Token) => {
diffSum +=
(tokenValue[top10Token.name]["diffvalue"] *
price[top10Token.name]["USD"]) /
10 ** top10Token.decimals;
initialSum +=
(tokenValue[top10Token.name]["initialValue"] *
price[top10Token.name]["USD"]) /
10 ** top10Token.decimals;
});
var netChange = (diffSum / initialSum) * 100;
if (netChange < -5) {
result.push({
address: contract.address,
total_initial_USD_value: initialSum,
total_diff_USD_value: diffSum,
netChange: netChange,
});
}
}
// console.log(result);
// write result to a file
fs.writeFileSync("netLost.json", JSON.stringify(result));
}
main(top10Token_POLYGON);