forked from raznorabochiy/evm-checker
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.ts
More file actions
61 lines (49 loc) · 1.69 KB
/
Copy pathindex.ts
File metadata and controls
61 lines (49 loc) · 1.69 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
import cli from "cli";
import { CONFIG } from "./config";
import { WALLETS_FILENAME } from "./constants";
import { chooseNetwork } from "./modules/choice";
import Cvs from "./modules/csv";
import { getErc20Balance } from "./modules/erc20";
import { getNativeBalance } from "./modules/native";
import { Network } from "./types";
import { getAddressFromWallet, loadFormFile } from "./utils";
const wallets = await loadFormFile(WALLETS_FILENAME);
const addresses = wallets.map(getAddressFromWallet);
const isWalletsContainPrivateKeys = wallets.some((wallet) =>
wallet.length > 42
);
const networkArg = process.argv[2] as Network;
let network = networkArg;
if (!network) {
network = await chooseNetwork();
}
console.time("Время");
cli.spinner(`Загружаю данные, ${addresses.length} адресов`);
const columns = CONFIG[network].COLUMNS;
const csv = new Cvs(network);
const data = await Promise.all(
columns.map((token) => {
if (token === "native") {
return getNativeBalance(network, addresses);
}
return getErc20Balance(network, addresses, token);
}),
);
const walletColumns = isWalletsContainPrivateKeys
? ["Address", "PrivateKey"]
: ["Address"];
const csvHeader = [...walletColumns, ...data.map((item) => item.header)];
csv.write(csvHeader);
for (let i = 0; i < wallets.length; i++) {
const wallet = wallets[i];
const address = addresses[i];
const privateKey = wallet !== address ? wallet : "";
const walletColumns = isWalletsContainPrivateKeys
? [address, privateKey]
: [address];
const row = [...walletColumns, ...data.map((item) => item.balances[i])];
csv.write(row);
}
csv.close();
cli.spinner("Готово", true);
console.timeEnd("Время");