-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.old
248 lines (213 loc) · 7.24 KB
/
index.old
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
import fs from "fs";
// import { AptosClient } from "aptos";
// import { Aptos } from "@aptos-labs/ts-sdk";
const url = "https://rpc.0l.fyi/v1";
const urlAlt = "https://rpc.openlibra.space:8080/";
let aptos = new Aptos();
console.log(aptos.getChainId())
// const logUpdate = (message) => console.log(message);
// const logError = (message) => console.error(message);
// // Simple progress bar implementation
// const updateProgressBar = (progress, total) => {
// const percentage = Math.round((progress / total) * 100);
// const barLength = 20;
// const filledLength = Math.round((percentage / 100) * barLength);
// const bar = "█".repeat(filledLength) + "-".repeat(barLength - filledLength);
// logUpdate(`[${bar}] ${percentage}%`);
// };
// const checkConnection = async () => {
// const id = await aptos.getChainId();
// if (!id) logError("not connected");
// process.exit(1);
// };
// const fetchDataFromBlockchain = async (resourcePath) => {
// try {
// const res = await aptos.getAccountResource("0x1", resourcePath);
// return res.data ? res.data : res;
// } catch (err) {
// logError(`Error fetching data from blockchain: ${err}`);
// return null;
// }
// };
// const getTotalSupply = async () => {
// logUpdate("Fetching total supply...");
// const resourcePath = [
// "0x1",
// "0x1::coin::CoinInfo<0x1::libra_coin::LibraCoin>",
// ];
// const coinInfo = await fetchDataFromBlockchain(resourcePath);
// logError(coinInfo);
// const aggregatorData = coinInfo.supply.vec[0].aggregator.vec[0];
// const tableItemRequest = {
// key_type: "address",
// value_type: "u128",
// key: aggregatorData.key,
// };
// const totalSupplyStr = await aptos.getTableItem(
// aggregatorData.handle,
// tableItemRequest,
// );
// logUpdate(`Total supply fetched: ${parseInt(totalSupplyStr, 10) / 1e6}`);
// return parseInt(totalSupplyStr, 10) / 1e6;
// };
// // const getTotalSupply = async (): Promise<number> => {
// // aptos.
// // return 0
// // }
// const fetchSlowWalletsList = async () => {
// const resourcePath = ["0x1", "0x1::slow_wallet::SlowWalletList"];
// const slowWalletList = await fetchDataFromBlockchain(resourcePath);
// if (!slowWalletList || !slowWalletList.list) {
// logError("Failed to fetch slow wallet list or invalid response format.");
// return [];
// }
// return slowWalletList.list;
// };
// const fetchCommunityWalletsList = async () => {
// const resourcePath = ["0x1", "0x1::donor_voice::Registry"];
// const communityWalletList = await fetchDataFromBlockchain(resourcePath);
// if (!communityWalletList || !communityWalletList.list) {
// logError(
// "Failed to fetch community wallets list or invalid response format.",
// );
// return [];
// }
// return communityWalletList.list;
// };
// const fetchWalletData = async (addresses, resourcePath, progressMessage) => {
// const balances = [];
// logUpdate(`Fetching ${progressMessage}...`);
// for (const [index, address] of addresses.entries()) {
// const data = await fetchDataFromBlockchain([address, resourcePath]);
// if (data) {
// const balance = parseInt(data.coin.value, 10) / 1e6;
// balances.push(balance);
// logUpdate(`${progressMessage} for ${address}: ${balance}`);
// }
// updateProgressBar(index + 1, addresses.length);
// }
// return balances;
// };
// async function fetchSlowWalletLockedAndPledges() {
// console.log("Fetching slow wallet data and validator pledges...");
// const slowWalletAddresses = await fetchSlowWalletsList();
// const slowWalletBalances = [];
// let totalPledge = 0;
// let fullyUnlockedWalletsCount = 0;
// let stillLockedWalletsCount = 0;
// const coinStoreResourcePath =
// "0x1::coin::CoinStore<0x1::libra_coin::LibraCoin>";
// const slowWalletResourcePath = "0x1::slow_wallet::SlowWallet";
// for (const [index, address] of slowWalletAddresses.entries()) {
// const coinStoreData = await fetchDataFromBlockchain([
// address,
// coinStoreResourcePath,
// ]);
// const slowWalletData = await fetchDataFromBlockchain([
// address,
// slowWalletResourcePath,
// ]);
// if (coinStoreData && slowWalletData) {
// const totalBalance = parseInt(coinStoreData.coin.value, 10) / 1e6;
// const unlockedBalance = parseInt(slowWalletData.unlocked, 10) / 1e6;
// const lockedBalance = totalBalance - unlockedBalance;
// slowWalletBalances.push(lockedBalance);
// console.log(`Locked balance for ${address}: ${lockedBalance}`);
// if (lockedBalance === 0) {
// fullyUnlockedWalletsCount++;
// } else {
// stillLockedWalletsCount++;
// }
// }
// try {
// const pledgeRes = await fetchDataFromBlockchain([
// address,
// "0x1::pledge_accounts::MyPledges",
// ]);
// const pledge = pledgeRes.list.find(
// (it) => it.address_of_beneficiary === "0x0",
// );
// if (pledge) {
// const pledgeValue = parseInt(pledge.pledge.value, 10) / 1e6;
// console.log(`Pledge value for ${address}: ${pledgeValue}`);
// totalPledge += pledgeValue;
// }
// } catch (err) {
// if (err.errorCode !== "resource_not_found") {
// console.error(`Error fetching pledge data for ${address}: ${err}`);
// }
// }
// updateProgressBar(index + 1, slowWalletAddresses.length);
// }
// return {
// slowWalletBalances,
// totalPledge,
// fullyUnlockedWalletsCount,
// stillLockedWalletsCount,
// };
// }
// async function fetchCommunityWalletBalances(cwAddresses) {
// logUpdate("Fetching community wallet balances...");
// const resourcePath = "0x1::coin::CoinStore<0x1::libra_coin::LibraCoin>";
// return await fetchWalletData(
// cwAddresses,
// resourcePath,
// "Community wallet balance",
// );
// }
// function calculateCirculatingSupply(
// totalSupply,
// totalLockedInSlowWallets,
// totalValidatorPledges,
// totalCWBalances,
// ) {
// const circulatingSupply =
// totalSupply -
// (totalLockedInSlowWallets + totalValidatorPledges + totalCWBalances);
// return circulatingSupply;
// }
// async function main() {
// checkConnection();
// const totalSupply = await getTotalSupply();
// const {
// slowWalletBalances,
// totalPledge,
// fullyUnlockedWalletsCount,
// stillLockedWalletsCount,
// } = await fetchSlowWalletLockedAndPledges();
// const cwAddresses = await fetchCommunityWalletsList();
// const communityWalletBalances =
// await fetchCommunityWalletBalances(cwAddresses);
// const totalLockedInSlowWallets = slowWalletBalances.reduce(
// (acc, curr) => acc + curr,
// 0,
// );
// const totalCommunityWalletBalances = communityWalletBalances.reduce(
// (acc, curr) => acc + curr,
// 0,
// );
// const circulatingSupply = calculateCirculatingSupply(
// totalSupply,
// totalLockedInSlowWallets,
// totalPledge,
// totalCommunityWalletBalances,
// );
// const balances = {
// totalSupply,
// slowWalletsLocked: totalLockedInSlowWallets,
// validatorPledges: totalPledge,
// communityWallets: totalCommunityWalletBalances,
// circulatingSupply,
// fullyUnlockedWalletsCount,
// stillLockedWalletsCount,
// };
// console.log(balances);
// fs.writeFile("balances.json", JSON.stringify(balances, null, 2), (err) => {
// if (err) {
// console.error("Error writing to file", err);
// } else {
// console.log("Output written to balances.json");
// }
// });
// }
// main();