Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
89 lines (74 loc) · 2.03 KB
/
Copy pathindex.js
File metadata and controls
89 lines (74 loc) · 2.03 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
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
import { request, gql } from "graphql-request";
import json2csv from "json2csv";
const subgraphUrl = {
ethereum: "https://api.thegraph.com/subgraphs/name/enzymefinance/enzyme-core",
polygon: "https://api.thegraph.com/subgraphs/name/enzymefinance/enzyme-core-polygon",
};
const blockNumber = {
ethereum: 16307890,
polygon: 37518609,
};
const OwnersQuery = gql`
query OwnersQuery($block: Int!, $last: String!) {
accounts(
block: { number: $block }
where: { id_gt: $last, isOwner: true }
first: 1000
orderBy: id
orderDirection: asc
) {
id
}
}
`;
const DepositorsQuery = gql`
query DepositorsQuery($block: Int!, $last: String!) {
accounts(
block: { number: $block }
where: { id_gt: $last, isDepositor: true }
first: 1000
orderBy: id
orderDirection: asc
) {
id
}
}
`;
async function fetchAccounts(network, query) {
let output = new Set();
let last = "";
while (true) {
const { accounts } = await request(subgraphUrl[network], query, {
last,
block: blockNumber[network],
});
const addresses = accounts.map((account) => account.id);
output = new Set([...output, ...addresses]);
// If we have less than 1000 accounts, we've reached the end.
if (addresses.length !== 1000) {
break;
}
last = addresses[addresses.length - 1];
}
return output;
}
async function fetchOwnersAndDepositors() {
const [ethereumOwners, ethereumDepositors, polygonOwners, polygonDepositors] =
await Promise.all([
fetchAccounts("ethereum", OwnersQuery),
fetchAccounts("ethereum", DepositorsQuery),
fetchAccounts("polygon", OwnersQuery),
fetchAccounts("polygon", DepositorsQuery),
]);
const addresses = new Set([
...ethereumOwners,
...ethereumDepositors,
...polygonOwners,
...polygonDepositors,
]);
return addresses;
}
fetchOwnersAndDepositors().then((addresses) => {
const csv = json2csv.parse(Array.from(addresses).map((id) => ({ id })));
process.stdout.write(csv);
});