-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
57 lines (50 loc) · 1.93 KB
/
app.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
const axios = require("axios");
const BigNumber = require("bignumber.js");
const fs = require("fs");
require("dotenv").config();
const jsonexport = require("jsonexport");
const jar = "0xf12bb9dcd40201b5a110e11e38dcddf4d11e6f83";
const lpToken = "0x160532d2536175d65c03b97b0630a9802c274dad";
const strategy = "0xb35C8E85b4866422a135bFfaA46A6AAaB436CF05";
const isSameAddress = (a, b) => {
return a.toLowerCase() === b.toLowerCase();
};
const main = async () => {
const apiURL = `https://api.polygonscan.com/api?module=account&action=tokentx&contractAddress=${lpToken}&address=${jar}&endblock=latest&sort=asc&apikey=${process.env.APIKEY}`;
let depositAmount = {};
const {
data: { result },
} = await axios.get(apiURL);
for (const txn of result) {
const { from, to, value, tokenSymbol } = txn;
if (isSameAddress(to, jar) && tokenSymbol === "UNI-V2") {
if (!isSameAddress(from, strategy)) depositAmount[from] = new BigNumber(depositAmount[from] || 0).plus(value);
} else if (isSameAddress(from, jar) && tokenSymbol === "UNI-V2") {
depositAmount[to] = new BigNumber(depositAmount[to] || 0).minus(value);
}
}
let count = 0;
let output = [];
Object.keys(depositAmount).forEach((key) => {
if (depositAmount[key].isGreaterThan(0)) {
output.push({
address: key,
amount: parseInt(depositAmount[key].multipliedBy(0.995).toFixed(0)) / 1e18,
});
count = new BigNumber(count).plus(parseInt(depositAmount[key].multipliedBy(0.995).toFixed(0)) / 1e18)
}
});
console.log(count.toString());
// //multisender csv
jsonexport(output, { includeHeaders: false }, function (err, csv) {
if (err) return console.error(err);
fs.writeFile("output.csv", csv, "utf8", function (err) {
if (err) {
console.log(`Some error occured - output.csv file either not saved or corrupted file saved.`);
} else {
console.log(`output.csv saved!`);
}
});
});
};
main();