-
Notifications
You must be signed in to change notification settings - Fork 237
/
schema-dex-agg.graphql
622 lines (444 loc) · 19.2 KB
/
schema-dex-agg.graphql
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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
# Subgraph Schema: DEX AGG
# Version: 1.0.2
# See https://github.com/messari/subgraphs/blob/master/docs/SCHEMA.md for details
enum Network {
ARBITRUM_ONE
ARWEAVE_MAINNET
AURORA
AVALANCHE
BOBA
BSC # aka BNB Chain
CELO
COSMOS
CRONOS
MAINNET # Ethereum Mainnet
FANTOM
FUSE
HARMONY
JUNO
MOONBEAM
MOONRIVER
NEAR_MAINNET
OPTIMISM
OSMOSIS
MATIC # aka Polygon
GNOSIS
}
enum ProtocolType {
EXCHANGE
LENDING
YIELD
BRIDGE
GENERIC
DEX_AGG
# Will add more
}
enum TokenType {
MULTIPLE
UNKNOWN
ERC20
ERC721
ERC1155
BEP20
BEP721
BEP1155
# Will add more
}
type Token @entity @regularPolling {
" Smart contract address of the token "
id: Bytes!
" Name of the token, mirrored from the smart contract "
name: String!
" Symbol of the token, mirrored from the smart contract "
symbol: String!
" The number of decimal places this token uses, default to 18 "
decimals: Int!
" Optional field to track the price of a token, mostly for caching purposes "
lastPriceUSD: BigDecimal
" Optional field to track the block number of the last token price "
lastPriceBlockNumber: BigInt
" Field to track the cumulative volume of the token in native amounts - Only counts volume from the token being swapped with (tokenIn) "
cumulativeVolume: BigInt!
" Field to track the cumulative volume of the token in USD - Only counts volume from the token being swapped with (tokenIn) "
cumulativeVolumeUSD: BigDecimal!
" The type of token the protocol creates for positions "
type: TokenType
" Day ID of the most recent daily snapshot "
lastSnapshotDayID: Int!
" Timestamp of the last time this entity was updated "
lastUpdateTimestamp: BigInt!
" Block number of the last time this entity was updated "
lastUpdateBlockNumber: BigInt!
" All deposit (add liquidity) events occurred in this pool "
tokenDailySnapshots: [TokenDailySnapshot!]! @derivedFrom(field: "token")
}
type TokenDailySnapshot @entity @dailySnapshot {
" { Smart contract address of the token }-{ # of days since Unix epoch time } "
id: ID!
" Token address "
token: Token!
" Optional field to track the price of a token, mostly for caching purposes "
priceUSD: BigDecimal
" Field to track the daily volume of the token in native amounts "
dailyVolume: BigInt!
" Field to track the cumulative volume of the token in native amounts "
cumulativeVolume: BigInt!
" Field to track the daily volume of the token in USD "
dailyVolumeUSD: BigDecimal!
" Field to track the cumulative volume of the token in USD "
cumulativeVolumeUSD: BigDecimal!
" Timestamp of when this snapshot was taken/last modified (May be taken after interval has passed) "
timestamp: BigInt!
" Block number of when this snapshot was taken/last modified (May be taken after interval has passed) "
blockNumber: BigInt!
}
enum RewardTokenType {
" For reward tokens awarded to LPs/lenders "
DEPOSIT
" For reward tokens awarded to borrowers "
BORROW
}
type RewardToken @entity(immutable: true) @regularPolling {
" { Reward token type }-{ Smart contract address of the reward token } "
id: Bytes!
" Reference to the actual token "
token: Token!
" The type of the reward token "
type: RewardTokenType!
}
enum FeeType {
" Protocol collects positive slippage that occurs as a result of a swap "
POSITIVE_SLIPPAGE
}
#############################
##### Protocol Metadata #####
#############################
interface Protocol {
" Smart contract address of the protocol's main contract (Factory, Registry, etc) "
id: Bytes!
" Name of the protocol, including version. e.g. Uniswap v3 "
name: String!
" Slug of protocol, including version. e.g. uniswap-v3 "
slug: String!
" Version of the subgraph schema, in SemVer format (e.g. 1.0.0) "
schemaVersion: String!
" Version of the subgraph implementation, in SemVer format (e.g. 1.0.0) "
subgraphVersion: String!
" Version of the methodology used to compute metrics, loosely based on SemVer format (e.g. 1.0.0) "
methodologyVersion: String!
" The blockchain network this subgraph is indexing on "
network: Network!
" The type of protocol (e.g. DEX, Lending, Yield, etc) "
type: ProtocolType!
##### Quantitative Data #####
" Current PCV (Protocol Controlled Value). Only relevant for protocols with PCV. "
protocolControlledValueUSD: BigDecimal
" Revenue claimed by suppliers to the protocol. LPs on DEXs (e.g. 0.25% of the swap fee in Sushiswap). Depositors on Lending Protocols. NFT sellers on OpenSea. "
cumulativeSupplySideRevenueUSD: BigDecimal!
" Gross revenue for the protocol (revenue claimed by protocol). Examples: AMM protocol fee (Sushi’s 0.05%). OpenSea 10% sell fee. "
cumulativeProtocolSideRevenueUSD: BigDecimal!
" All revenue generated by the protocol. e.g. 0.30% of swap fee in Sushiswap, all yield generated by Yearn. "
cumulativeTotalRevenueUSD: BigDecimal!
" Number of cumulative unique users "
cumulativeUniqueUsers: Int!
##### Snapshots #####
" Daily usage metrics for this protocol "
dailyUsageMetrics: [UsageMetricsDailySnapshot!]!
@derivedFrom(field: "protocol")
" Hourly usage metrics for this protocol "
hourlyUsageMetrics: [UsageMetricsHourlySnapshot!]!
@derivedFrom(field: "protocol")
" Daily financial metrics for this protocol "
financialMetrics: [FinancialsDailySnapshot!]! @derivedFrom(field: "protocol")
}
type DexAggProtocol implements Protocol @entity @regularPolling {
" Smart contract address of the protocol's main contract (Factory, Registry, etc) "
id: Bytes!
" Name of the protocol, including version. e.g. Uniswap v3 "
name: String!
" Slug of protocol, including version. e.g. uniswap-v3 "
slug: String!
" Version of the subgraph schema, in SemVer format (e.g. 1.0.0) "
schemaVersion: String!
" Version of the subgraph implementation, in SemVer format (e.g. 1.0.0) "
subgraphVersion: String!
" Version of the methodology used to compute metrics, loosely based on SemVer format (e.g. 1.0.0) "
methodologyVersion: String!
" The blockchain network this subgraph is indexing on "
network: Network!
" The type of protocol (e.g. DEX, Lending, Yield, etc) "
type: ProtocolType!
" The fee type for this protocol "
feeType: FeeType!
##### Quantitative Data #####
" Current PCV (Protocol Controlled Value). Only relevant for protocols with PCV. "
protocolControlledValueUSD: BigDecimal
" Field to track cumulative volume of tokens summed across swapped in USD - Takes preference for inward token volume in USD. Use outward volume in USD if inward price does not exist. "
cumulativeNetVolumeUSD: BigDecimal!
" Revenue claimed by suppliers to the protocol. LPs on DEXs (e.g. 0.25% of the swap fee in Sushiswap). Depositors on Lending Protocols. NFT sellers on OpenSea. "
cumulativeSupplySideRevenueUSD: BigDecimal!
" Gross revenue for the protocol (revenue claimed by protocol). Examples: AMM protocol fee (Sushi’s 0.05%). OpenSea 10% sell fee. "
cumulativeProtocolSideRevenueUSD: BigDecimal!
" All revenue generated by the protocol. e.g. 0.30% of swap fee in Sushiswap, all yield generated by Yearn. "
cumulativeTotalRevenueUSD: BigDecimal!
" Number of cumulative unique users "
cumulativeUniqueUsers: Int!
" Day ID of the most recent daily snapshot "
lastSnapshotDayID: Int!
" Timestamp of the last time this entity was updated "
lastUpdateTimestamp: BigInt!
" Block number of the last time this entity was updated "
lastUpdateBlockNumber: BigInt!
##### Snapshots #####
" Daily usage metrics for this protocol "
dailyUsageMetrics: [UsageMetricsDailySnapshot!]!
@derivedFrom(field: "protocol")
" Hourly usage metrics for this protocol "
hourlyUsageMetrics: [UsageMetricsHourlySnapshot!]!
@derivedFrom(field: "protocol")
" Daily financial metrics for this protocol "
financialMetrics: [FinancialsDailySnapshot!]! @derivedFrom(field: "protocol")
}
#########################
##### Virtual Pools #####
#########################
"""
Virtual Pools represent swapped token groups. DEX Aggs use liquidity pools from other protocols,
so we use virtual pools to track metrics for swaps between specific token groups.
"""
type VirtualPool @entity @regularPolling {
" { `InputTokens: {Sorted token addresses separated by `-`}` + `OutputTokens: {Sorted token addresses separated by `-`}` } "
id: Bytes!
" The protocol this pool belongs to "
protocol: DexAggProtocol!
" Timestamp of the last swap of this type "
timestamp: BigInt!
" Block number of the last swap of this type "
blockNumber: BigInt!
" Input Tokens "
tokensIn: [Token!]!
" Output Tokens "
tokensOut: [Token!]!
" Field to track the cumulative volume of the inward tokens in native amounts "
cumulativeVolumesIn: [BigInt!]!
" Field to track the cumulative volume of the inward tokens in USD "
cumulativeVolumesInUSD: [BigDecimal!]!
" Field to track the cumulative volume of the outward tokens in native amounts "
cumulativeVolumesOut: [BigInt!]!
" Field to track the cumulative volume of the outward tokens in USD "
cumulativeVolumesOutUSD: [BigDecimal!]!
" Field to track cumulative volume of tokens summed across swapped in USD - Takes preference for inward token volume in USD. Use outward volume in USD if inward price does not exist. "
cumulativeNetVolumeUSD: BigDecimal!
### Revenues do not count revenues towards the underlying DEXs used to execute the swap. ###
" All revenue generated by the virtual pool, accrued to the supply side. "
cumulativeSupplySideRevenueUSD: BigDecimal!
" All revenue generated by the virtual pool, accrued to the protocol. "
cumulativeProtocolSideRevenueUSD: BigDecimal!
" All revenue generated by the virtual pool. "
cumulativeTotalRevenueUSD: BigDecimal!
##### Metrics #####
" Number of cumulative unique users "
cumulativeUniqueUsers: Int!
" Day ID of the most recent daily snapshot "
lastSnapshotDayID: Int!
" Timestamp of the last time this entity was updated "
lastUpdateTimestamp: BigInt!
" Block number of the last time this entity was updated "
lastUpdateBlockNumber: BigInt!
##### Snapshots #####
" Virtual pool daily snapshots "
dailySnapshots: [VirtualPoolDailySnapshot!]!
@derivedFrom(field: "virtualPool")
}
###################################
##### Virtual Pool Timeseries #####
###################################
type VirtualPoolDailySnapshot @entity @dailySnapshot {
" { Address of the VirtualPool }-{ # of days since Unix epoch time } "
id: Bytes!
" Number of days since Unix epoch time "
day: Int!
" VirtualPool "
virtualPool: VirtualPool!
" Field to track the daily volume of the inward tokens in native amounts "
dailyVolumesIn: [BigInt!]!
" Field to track the cumulative volume of the inward tokens in native amounts "
cumulativeVolumesIn: [BigInt!]!
" Field to track the daily volume of the inward tokens in USD "
dailyVolumesInUSD: [BigDecimal!]!
" Field to track the cumulative volume of the inward tokens in USD "
cumulativeVolumesInUSD: [BigDecimal!]!
" Field to track the daily volume of the outward tokens in native amounts "
dailyVolumesOut: [BigInt!]!
" Field to track the cumulative volume of the outward tokens in native amounts "
cumulativeVolumesOut: [BigInt!]!
" Field to track the daily volume of the outward tokens in USD "
dailyVolumesOutUSD: [BigDecimal!]!
" Field to track the cumulative volume of the outward tokens in USD "
cumulativeVolumesOutUSD: [BigDecimal!]!
" Field to track daily volume of tokens summed across all tokens in USD - Takes preference for inward token volume in USD. Use outward volume in USD if inward price does not exist. "
dailyNetVolumeUSD: BigDecimal!
" Field to track cumulative volume of tokens summed across swapped in USD - Takes preference for inward token volume in USD. Use outward volume in USD if inward price does not exist. "
cumulativeNetVolumeUSD: BigDecimal!
" Daily revenue generated by the virtual pool, accrued to the supply side. "
dailySupplySideRevenueUSD: BigDecimal!
" All revenue generated by the virtual pool, accrued to the supply side. "
cumulativeSupplySideRevenueUSD: BigDecimal!
" Daily revenue generated by the virtual pool, accrued to the protocol. "
dailyProtocolSideRevenueUSD: BigDecimal!
" All revenue generated by the virtual pool, accrued to the protocol. "
cumulativeProtocolSideRevenueUSD: BigDecimal!
" Daily revenue generated by the virtual pool. "
dailyTotalRevenueUSD: BigDecimal!
" All revenue generated by the virtual pool. "
cumulativeTotalRevenueUSD: BigDecimal!
##### Metrics #####
" Number of cumulative unique users "
cumulativeUniqueUsers: Int!
" Number of unique daily active users "
dailyActiveUsers: Int!
" Timestamp of when this snapshot was taken/last modified (May be taken after interval has passed) "
timestamp: BigInt!
" Block number of when this snapshot was taken/last modified (May be taken after interval has passed) "
blockNumber: BigInt!
}
###############################
##### Protocol Timeseries #####
###############################
type UsageMetricsDailySnapshot @entity @dailySnapshot {
" ID is # of days since Unix epoch time "
id: Bytes!
" Number of days since Unix epoch time "
day: Int!
" Protocol this snapshot is associated with "
protocol: DexAggProtocol!
" Number of unique daily active users "
dailyActiveUsers: Int!
" Number of cumulative unique users "
cumulativeUniqueUsers: Int!
" Total number of transactions occurred in a day. Transactions include all entities that implement the Event interface. "
dailyTransactionCount: Int!
" Total number of trades (swaps) in an hour "
dailySwapCount: Int!
" Timestamp of when this snapshot was taken/last modified (May be taken after interval has passed) "
timestamp: BigInt!
" Block number of when this snapshot was taken/last modified (May be taken after interval has passed) "
blockNumber: BigInt!
}
type UsageMetricsHourlySnapshot @entity @hourlySnapshot {
" { # of hours since Unix epoch time } "
id: Bytes!
" Number of hours since Unix epoch time "
hour: Int!
" Protocol this snapshot is associated with "
protocol: DexAggProtocol!
" Number of unique hourly active users "
hourlyActiveUsers: Int!
" Number of cumulative unique users "
cumulativeUniqueUsers: Int!
" Total number of transactions occurred in an hour. Transactions include all entities that implement the Event interface. "
hourlyTransactionCount: Int!
" Total number of trades (swaps) in an hour "
hourlySwapCount: Int!
" Timestamp of when this snapshot was taken/last modified (May be taken after interval has passed) "
timestamp: BigInt!
" Block number of when this snapshot was taken/last modified (May be taken after interval has passed) "
blockNumber: BigInt!
}
type FinancialsDailySnapshot @entity @dailySnapshot {
" ID is # of days since Unix epoch time "
id: Bytes!
" Number of days since Unix epoch time "
day: Int!
" Protocol this snapshot is associated with "
protocol: DexAggProtocol!
" Current PCV (Protocol Controlled Value). Only relevant for protocols with PCV. "
protocolControlledValueUSD: BigDecimal
" All trade volume occurred in a given day, in USD "
dailyVolumeUSD: BigDecimal!
" Field to track cumulative volume of tokens summed across swapped in USD - Takes preference for inward token volume in USD. Use outward volume in USD if inward price does not exist. "
cumulativeNetVolumeUSD: BigDecimal!
" Revenue claimed by suppliers to the protocol. LPs on DEXs (e.g. 0.25% of the swap fee in Sushiswap). Depositors on Lending Protocols. NFT sellers on OpenSea. "
dailySupplySideRevenueUSD: BigDecimal!
" Revenue claimed by suppliers to the protocol. LPs on DEXs (e.g. 0.25% of the swap fee in Sushiswap). Depositors on Lending Protocols. NFT sellers on OpenSea. "
cumulativeSupplySideRevenueUSD: BigDecimal!
" Gross revenue for the protocol (revenue claimed by protocol). Examples: AMM protocol fee (Sushi’s 0.05%). OpenSea 10% sell fee. "
dailyProtocolSideRevenueUSD: BigDecimal!
" Gross revenue for the protocol (revenue claimed by protocol). Examples: AMM protocol fee (Sushi’s 0.05%). OpenSea 10% sell fee. "
cumulativeProtocolSideRevenueUSD: BigDecimal!
" All revenue generated by the protocol. e.g. 0.30% of swap fee in Sushiswap, all yield generated by Yearn. "
dailyTotalRevenueUSD: BigDecimal!
" All revenue generated by the protocol. e.g. 0.30% of swap fee in Sushiswap, all yield generated by Yearn. "
cumulativeTotalRevenueUSD: BigDecimal!
" Timestamp of when this snapshot was taken/last modified (May be taken after interval has passed) "
timestamp: BigInt!
" Block number of when this snapshot was taken/last modified (May be taken after interval has passed) "
blockNumber: BigInt!
}
##############################
##### Account-Level Data #####
##############################
type Account @entity @regularPolling {
" { Account address } "
id: Bytes!
" All historical trade volume in USD "
cumulativeVolumeUSD: BigDecimal!
" Number of times this account has traded/swapped"
swapCount: Int!
" All swap events of this account "
swaps: [Swap!]! @derivedFrom(field: "account")
}
############################
##### Event-Level Data #####
############################
"""
An event is any user action that occurs in a protocol. Generally, they are Ethereum events
emitted by a function in the smart contracts, stored in transaction receipts as event logs.
However, some user actions of interest are function calls that don't emit events. For example,
the deposit and withdraw functions in Yearn do not emit any events. In our subgraphs, we still
store them as events, although they are not technically Ethereum events emitted by smart
contracts.
"""
type Swap @entity(immutable: true) @transaction {
" { Transaction hash }-{ Log index } "
id: Bytes!
" Transaction hash of the transaction that emitted this event "
hash: Bytes!
" Nonce of the transaction that emitted this event "
nonce: BigInt!
" Event log index. For transactions that don't emit event, create arbitrary index starting from 0 "
logIndex: Int!
" Gas used in this transaction. (Optional because not every chain will support this) "
gasUsed: BigInt
" Gas limit of the transaction that emitted this event "
gasLimit: BigInt
" Gas price of the transaction that emitted this event "
gasPrice: BigInt
" The protocol this transaction belongs to "
protocol: DexAggProtocol!
" Account that emitted this event "
account: Account!
" Block number of this event "
blockNumber: BigInt!
" Timestamp of this event "
timestamp: BigInt!
" Virtual Pool this swap occurred in "
virtualPool: VirtualPool!
" Tokens deposited into pool "
tokensIn: [Token!]!
" Amount of tokens deposited into pool in native units "
amountsIn: [BigInt!]!
" Amount of tokens deposited into pool in USD "
amountsInUSD: [BigDecimal!]!
" Tokens withdrawn from pool "
tokensOut: [Token!]!
" Amount of tokens withdrawn from pool in native units "
amountsOut: [BigInt!]!
" Amount of tokens withdrawn from pool in USD "
amountsOutUSD: [BigDecimal!]!
}
# Helper entity for calculating daily/hourly active users
type ActiveAccount @entity(immutable: true) {
" { daily/hourly }-{ Address of the account }-{ Days/hours since Unix epoch } "
id: Bytes!
}