-
Notifications
You must be signed in to change notification settings - Fork 239
/
build-protocols.ts
246 lines (214 loc) · 6.73 KB
/
build-protocols.ts
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
import { writeFileSync } from 'node:fs'
import {
ACTIVE_USERS_API,
DIMENISIONS_OVERVIEW_API,
HACKS_API,
LIQUIDITY_API,
NFT_MARKETPLACES_STATS_API,
PROTOCOLS_API,
PROTOCOLS_EXPENSES_API,
PROTOCOLS_TREASURY,
RAISES_API
} from '~/constants'
export const slug = (tokenName = '') => tokenName?.toLowerCase().split(' ').join('-').split("'").join('')
const finalProtocols = {}
const tvlData = await fetch(PROTOCOLS_API).then((res) => res.json())
const nameToId = {}
for (const protocol of tvlData.protocols) {
nameToId[protocol.defillamaId] = protocol.name
finalProtocols[protocol.defillamaId] = {
tvl: protocol.tvl !== null ? true : false,
...(protocol.governanceID ? { governance: true } : {})
}
if (protocol.parentProtocol && protocol.tvl !== null) {
finalProtocols[protocol.parentProtocol] = {
...finalProtocols[protocol.parentProtocol],
tvl: true
}
}
}
for (const protocol of tvlData.parentProtocols) {
nameToId[protocol.id] = protocol.name
finalProtocols[protocol.id] = {
...finalProtocols[protocol.id],
...(protocol.governanceID ? { governance: true } : {})
}
}
const expensesData = await fetch(PROTOCOLS_EXPENSES_API).then((res) => res.json())
for (const protocol of expensesData) {
finalProtocols[protocol.protocolId] = {
...finalProtocols[protocol.protocolId],
expenses: true
}
}
const treasuryData = await fetch(PROTOCOLS_TREASURY).then((res) => res.json())
for (const protocol of treasuryData) {
finalProtocols[protocol.id.split('-')[0]] = {
...finalProtocols[protocol.id.split('-')[0]],
treasury: true
}
}
// todo YIELD_POOLS_API & YIELD_CONFIG_API
const liquidityData = await fetch(LIQUIDITY_API).then((res) => res.json())
for (const protocol of liquidityData) {
finalProtocols[protocol.id] = {
...finalProtocols[protocol.id],
liquidity: true
}
}
// todo forks api
const hacksData = await fetch(HACKS_API).then((res) => res.json())
for (const protocol of hacksData) {
if (protocol.defillamaId) {
finalProtocols[protocol.defillamaId.toString()] = {
...finalProtocols[protocol.defillamaId.toString()],
hacks: true
}
}
}
const nftMarketplacesData = await fetch(NFT_MARKETPLACES_STATS_API).then((res) => res.json())
for (const market of nftMarketplacesData) {
const marketplaceExists = Object.entries(nameToId).find(
(protocol) => slug(market.exchangeName) === slug(protocol[1] as string)
) as [string, string] | undefined
if (marketplaceExists) {
finalProtocols[marketplaceExists[0]] = {
...finalProtocols[marketplaceExists[0]],
nfts: true
}
}
}
const raisesData = await fetch(RAISES_API).then((res) => res.json())
for (const raise of raisesData.raises) {
if (raise.defillamaId && !raise.defillamaId.startsWith('chain')) {
finalProtocols[raise.defillamaId] = {
...finalProtocols[raise.defillamaId],
raises: true
}
}
}
const activeUsersData = await fetch(ACTIVE_USERS_API).then((res) => res.json())
for (const protocol in activeUsersData) {
finalProtocols[protocol] = {
...finalProtocols[protocol],
activeUsers: true
}
}
const feesData = await fetch(
`${DIMENISIONS_OVERVIEW_API}/fees?excludeTotalDataChartBreakdown=true&excludeTotalDataChart=true`
).then((res) => res.json())
for (const protocol of feesData.protocols) {
finalProtocols[protocol.defillamaId] = {
...finalProtocols[protocol.defillamaId],
fees: true
}
if (protocol.parentProtocol) {
finalProtocols[protocol.parentProtocol] = {
...finalProtocols[protocol.parentProtocol],
fees: true
}
}
}
const revenueData = await fetch(
`${DIMENISIONS_OVERVIEW_API}/fees?excludeTotalDataChartBreakdown=true&excludeTotalDataChart=true&dataType=dailyRevenue`
).then((res) => res.json())
for (const protocol of revenueData.protocols) {
finalProtocols[protocol.defillamaId] = {
...finalProtocols[protocol.defillamaId],
revenue: true
}
if (protocol.parentProtocol) {
finalProtocols[protocol.parentProtocol] = {
...finalProtocols[protocol.parentProtocol],
revenue: true
}
}
}
const volumeData = await fetch(
`${DIMENISIONS_OVERVIEW_API}/dexs?excludeTotalDataChartBreakdown=true&excludeTotalDataChart=true`
).then((res) => res.json())
for (const protocol of volumeData.protocols) {
finalProtocols[protocol.defillamaId] = {
...finalProtocols[protocol.defillamaId],
dexs: true
}
if (protocol.parentProtocol) {
finalProtocols[protocol.parentProtocol] = {
...finalProtocols[protocol.parentProtocol],
dexs: true
}
}
}
const derivativesData = await fetch(
`${DIMENISIONS_OVERVIEW_API}/derivatives?excludeTotalDataChartBreakdown=true&excludeTotalDataChart=true`
).then((res) => res.json())
for (const protocol of derivativesData.protocols) {
finalProtocols[protocol.defillamaId] = {
...finalProtocols[protocol.defillamaId],
derivatives: true
}
if (protocol.parentProtocol) {
finalProtocols[protocol.parentProtocol] = {
...finalProtocols[protocol.parentProtocol],
derivatives: true
}
}
}
const aggregatorsData = await fetch(
`${DIMENISIONS_OVERVIEW_API}/aggregators?excludeTotalDataChartBreakdown=true&excludeTotalDataChart=true`
).then((res) => res.json())
for (const protocol of aggregatorsData.protocols) {
finalProtocols[protocol.defillamaId] = {
...finalProtocols[protocol.defillamaId],
aggregator: true
}
if (protocol.parentProtocol) {
finalProtocols[protocol.parentProtocol] = {
...finalProtocols[protocol.parentProtocol],
aggregator: true
}
}
}
const optionsData = await fetch(
`${DIMENISIONS_OVERVIEW_API}/options?excludeTotalDataChartBreakdown=true&excludeTotalDataChart=true`
).then((res) => res.json())
for (const protocol of optionsData.protocols) {
finalProtocols[protocol.defillamaId] = {
...finalProtocols[protocol.defillamaId],
options: true
}
if (protocol.parentProtocol) {
finalProtocols[protocol.parentProtocol] = {
...finalProtocols[protocol.parentProtocol],
options: true
}
}
}
const aggregatorDerivativesData = await fetch(
`${DIMENISIONS_OVERVIEW_API}/aggregator-derivatives?excludeTotalDataChartBreakdown=true&excludeTotalDataChart=true`
).then((res) => res.json())
for (const protocol of aggregatorDerivativesData.protocols) {
finalProtocols[protocol.defillamaId] = {
...finalProtocols[protocol.defillamaId],
aggregatorDerivatives: true
}
if (protocol.parentProtocol) {
finalProtocols[protocol.parentProtocol] = {
...finalProtocols[protocol.parentProtocol],
aggregatorDerivatives: true
}
}
}
const emmissionsData = await fetch(`https://defillama-datasets.llama.fi/emissionsProtocolsList`).then((res) =>
res.json()
)
for (const protocol of Object.entries(nameToId)) {
if (emmissionsData.includes(slug(protocol[1] as string))) {
finalProtocols[protocol[0]] = {
...finalProtocols[protocol[0]],
emissions: true
}
}
}
writeFileSync(`./metadata/protocols.json`, JSON.stringify(finalProtocols, null, 4), 'utf8')
console.log('finished building protocol metadata')