forked from OlympusDAO/erc20-snapshot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
56 lines (48 loc) · 1.77 KB
/
index.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
#!/usr/bin/env node
import "dotenv/config";
import { createBalances } from "./lib/balances.js";
import { getEvents } from "./lib/scan-import-events.js";
import { hasuraWrite } from "./lib/hasura.js";
import { dumpBalancesFile } from "./lib/export.js";
import { addType } from "./lib/address-type.js";
import { checkConfig, getConfig } from "./lib/config.js";
const start = async () => {
const startTime = new Date();
const startTimeStr = startTime.toUTCString();
console.log(`Starting run at ${startTimeStr}`);
// Check if config file (in snapshot.config.json by default) exists. If not, show prompt
// questions to create it.
await checkConfig();
const Config = getConfig();
console.log({ Config });
// Get all the events for the specified contract address
// Format of `events` is [event1, event2, ...]
const eventData = await getEvents();
console.log("Calculating balances of %s (%s)...", eventData.name, eventData.symbol);
// Calculate the current balances
var balances = await createBalances(eventData);
console.log("Found total of", balances.length, "holders.");
if (eventData.loadMode.mode == "INCREMENTAL-LOAD") {
console.log("Found", eventData.newAddresses.size, "addresses to insert/update in the INCREMENTAL LOAD.");
}
if (Config.checkIfContract) {
balances = await addType(balances);
}
// Write data to Hasura
if (Config.writeToHasura) {
await hasuraWrite(eventData, balances, startTimeStr);
}
// Dump balances file locally (always dumps balances of all the addresses, doesn't matter
// if load mode is "INITIAL-LOAD" or "INCREMENTAL-LOAD")
if (Config.writeToLocalFile) {
await dumpBalancesFile(eventData, balances);
}
console.log("\nAll finished!")
};
(async () => {
try {
await start();
} catch (e) {
console.error(e);
}
})();