-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcalculateTotalTokens.js
More file actions
45 lines (35 loc) · 1.41 KB
/
calculateTotalTokens.js
File metadata and controls
45 lines (35 loc) · 1.41 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
const fs = require('fs');
const path = require('path');
function readJsonFile(filePath) {
const data = fs.readFileSync(filePath, 'utf8');
return JSON.parse(data);
}
function getProposalFiles() {
const files = fs.readdirSync('.');
return files.filter(file => file.startsWith('proposal') && file.endsWith('.json'));
}
function calculateTotalTokens() {
const proposalFiles = getProposalFiles();
const accountTotals = new Map();
proposalFiles.forEach(file => {
const data = readJsonFile(file);
console.log(`Processing ${file}...`);
data.voters.forEach(voter => {
if (voter.is_eligible) {
const tokenCount = Number(voter.token_count);
const currentTotal = accountTotals.get(voter.account) || 0;
accountTotals.set(voter.account, currentTotal + tokenCount);
}
});
});
const sortedAccounts = Array.from(accountTotals.entries())
.sort((a, b) => b[1] - a[1]);
const totalTokens = sortedAccounts.reduce((sum, [, tokens]) => sum + tokens, 0);
const output = sortedAccounts
.map(([account, tokens]) => `${account}: ${tokens.toLocaleString()}`)
.join('\n');
fs.writeFileSync('total_tokens.txt', output);
console.log('Results written to total_tokens.txt');
console.log(`Total tokens across all accounts: ${totalTokens.toLocaleString()}`);
}
calculateTotalTokens();