-
Notifications
You must be signed in to change notification settings - Fork 3
/
schema.graphql
634 lines (435 loc) · 15.1 KB
/
schema.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
623
624
625
626
627
628
629
630
631
632
633
634
enum Network {
AVALANCHE
AURORA
BSC
CELO
CRONOS
ETHEREUM
FANTOM
HARMONY
MOONBEAM
MOONRIVER
OPTIMISM
POLYGON
XDAI
}
enum ProtocolType {
EXCHANGE
LENDING
YIELD
BRIDGE
GENERIC
# Will add more
}
type Token @entity {
" Smart contract address of the market "
id: ID!
" Mirrored from the smart contract "
name: String!
symbol: String!
decimals: Int!
}
enum RewardTokenType {
DEPOSIT
BORROW
}
type RewardToken @entity {
" Smart contract address of the market "
id: ID!
" Mirrored from the smart contract "
name: String!
symbol: String!
decimals: Int!
type: RewardTokenType
}
#############################
##### Protocol Metadata #####
#############################
type UniqueUsers @entity {
id: ID!
}
interface Protocol {
" UUID "
id: ID!
" Name of the protocol, including version. e.g. Uniswap v3 "
name: String!
" Slug of protocol, including version. e.g. uniswap-v3 "
slug: String!
network: Network!
type: ProtocolType!
usageMetrics: [UsageMetricsDailySnapshot!]! @derivedFrom(field: "protocol")
financialMetrics: [FinancialsDailySnapshot!]! @derivedFrom(field: "protocol")
}
###############################
##### Protocol Timeseries #####
###############################
type UsageMetricsDailySnapshot @entity {
" ID is # of days since Unix epoch time "
id: ID!
protocol: Protocol!
" # of unique daily active users "
activeUsers: Int!
" # of total/cumulative unique users "
totalUniqueUsers: Int!
" Total number of transaction occurred in a day. Transactions include all entities that implement the Event interface. "
dailyTransactionCount: Int!
" Block number of this snapshot "
blockNumber: BigInt!
" Timestamp of this snapshot "
timestamp: BigInt!
}
type FinancialsDailySnapshot @entity {
" ID is # of days since Unix epoch time "
id: ID!
protocol: Protocol!
totalValueLockedUSD: BigDecimal!
" Total volume in USD "
totalVolumeUSD: 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. "
supplySideRevenueUSD: BigDecimal!
" Gross revenue for the protocol (revenue claimed by protocol). Examples: AMM protocol fee (Sushi’s 0.05%). OpenSea 10% sell fee. "
protocolSideRevenueUSD: BigDecimal!
" Fees paid by the users. e.g. 0.30% of swap fee in Sushiswap "
feesUSD: BigDecimal!
" Block number of this snapshot "
blockNumber: BigInt!
" Timestamp of this snapshot "
timestamp: BigInt!
}
###############################
##### Pool-Level Metadata #####
###############################
# A pool can be:
# - A liquidity pool in the case of a DEX AMM
# - A market in the case of a lending protocol
# - A vault in the case of a yield aggregator
interface Pool {
" Smart contract address of the pool "
id: ID!
" The protocol this pool belongs to "
protocol: Protocol!
# Generally protocols accept one or multiple tokens and mint tokens to the depositor to track ownership
# Some protocols reward DAO tokens or other incentivisation tokens to holders of LP tokens
# Some protocols don't mint any tokens to track ownership, in that case outputToken is null
# and inputToken balances are used to calculate returns
" Tokens that need to be deposited to take a position in protocol. e.g. WETH and USDC to deposit into the WETH-USDC pool. Array to account for multi-asset pools like Curve and Balancer "
inputTokens: [Token!]!
" Token that is minted to track ownership of position in protocol "
outputToken: Token
" Aditional tokens that are given as reward for position in a protocol "
rewardTokens: [RewardToken!]
##### Quantitative Data #####
totalValueLockedUSD: BigDecimal!
" Total volume in USD (volume is defined differently according to the protocol category) "
totalVolumeUSD: BigDecimal!
" Amount of input tokens in the pool. The ordering should be the same as the pool's `inputTokens` field. "
inputTokenBalances: [BigDecimal!]!
" Total supply of output token "
outputTokenSupply: BigDecimal!
" Price per share of output token in USD "
outputTokenPriceUSD: BigDecimal!
" Creation timestamp "
createdTimestamp: BigInt!
" Creation block number "
createdBlockNumber: BigInt!
" Pool snapshots "
snapshots: [PoolDailySnapshot!]! @derivedFrom(field: "pool")
}
#################################
##### Pool-Level Timeseries #####
#################################
interface PoolDailySnapshot {
" { Smart contract address of the pool }-{ # of days since Unix epoch time } "
id: ID!
" The protocol this snapshot belongs to "
protocol: Protocol!
" The pool this snapshot belongs to "
pool: Pool!
totalValueLockedUSD: BigDecimal!
" Total volume in USD "
totalVolumeUSD: BigDecimal!
" Amount of input tokens in the pool. The ordering should be the same as the pool's `inputTokens` field. "
inputTokenBalances: BigDecimal!
" Total supply of output token "
outputTokenSupply: BigDecimal!
" Price per share of output token in USD "
outputTokenPriceUSD: BigDecimal!
" Total amount of reward token emissions in a day, in token's native amount "
rewardTokenEmissionsAmount: [BigDecimal!]
" Total amount of reward token emissions in a day, normalized to USD "
rewardTokenEmissionsUSD: [BigDecimal!]
" Block number of this snapshot "
blockNumber: BigInt!
" Timestamp of this snapshot "
timestamp: BigInt!
}
enum LendingType {
" Collateralized Debt Position (CDP) protocols have singular isolated positions created by users. We aggregate them to give a single view of a market "
CDP
" Pooled protocols pool all users assets into a single market "
POOLED
}
enum RiskType {
" Global risk means each users position in a market is combined for one score to determine if they can be liquidated "
GLOBAL
" Isolated risk means each users position in a market or CDP is isolated for risk of liquidation "
ISOLATED
}
type LendingProtocol implements Protocol @entity {
" UUID "
id: ID!
" Name of the protocol, including version. e.g. Aave v2 "
name: String!
" Slug of protocol, including version. e.g. aave-v2 "
slug: String!
network: Network!
type: ProtocolType!
usageMetrics: [UsageMetricsDailySnapshot!]! @derivedFrom(field: "protocol")
financialMetrics: [FinancialsDailySnapshot!]! @derivedFrom(field: "protocol")
##### Lending-Specific #####
" All markets that belong to this protocol "
markets: [Market!]! @derivedFrom(field: "protocol")
lendingType: LendingType
riskType: RiskType
}
type Market @entity {
" Smart contract address of the market "
id: ID!
" The protocol this pool belongs to "
protocol: LendingProtocol!
# Generally protocols accept one or multiple tokens and mint tokens to the depositor to track ownership
# Some protocols reward DAO tokens or other incentivisation tokens to holders of LP tokens
# Some protocols don't mint any tokens to track ownership, in that case outputToken is null
# and inputToken balances are used to calculate returns
" Tokens that need to be deposited to take a position in protocol. e.g. WETH and USDC to deposit into the WETH-USDC pool "
inputTokens: [Token!]!
" Token that is minted to track ownership of position in protocol "
outputToken: Token
" Aditional tokens that are given as reward for position in a protocol "
rewardTokens: [RewardToken!]
##### Quantitative Data #####
totalValueLockedUSD: BigDecimal!
" Total borrow volume in USD (i.e. total loan origination ) "
totalVolumeUSD: BigDecimal!
" Amount of input tokens in the market. The ordering should be the same as the market's `inputTokens` field. "
inputTokenBalances: [BigDecimal!]!
" Total supply of output token "
outputTokenSupply: BigDecimal!
" Price per share of output token in USD "
outputTokenPriceUSD: BigDecimal!
" Creation timestamp "
createdTimestamp: BigInt!
" Creation block number "
createdBlockNumber: BigInt!
" Pool snapshots "
snapshots: [MarketDailySnapshot!]! @derivedFrom(field: "market")
##### Lending-Specific #####
" Name of market "
name: String
isActive: Boolean!
canUseAsCollateral: Boolean!
canBorrowFrom: Boolean!
" Maximum loan-to-value ratio as a percentage value "
maximumLTV: BigDecimal!
" Liquidation threshold as a percentage value "
liquidationThreshold: BigDecimal!
" Liquidation penalty as a percentage value "
liquidationPenalty: BigDecimal!
" Deposit interest rate in percentage "
depositRate: BigDecimal!
" Borrow interest rate in percentage "
stableBorrowRate: BigDecimal!
" Borrow interest rate in percentage "
variableBorrowRate: BigDecimal!
deposits: [Deposit!]! @derivedFrom(field: "market")
withdraws: [Withdraw!]! @derivedFrom(field: "market")
borrows: [Borrow!]! @derivedFrom(field: "market")
repays: [Repay!]! @derivedFrom(field: "market")
liquidations: [Liquidation!]! @derivedFrom(field: "market")
}
type MarketDailySnapshot @entity {
" { Smart contract address of the market }-{ # of days since Unix epoch time } "
id: ID!
" The protocol this snapshot belongs to "
protocol: Protocol!
" The pool this snapshot belongs to "
market: Market!
totalValueLockedUSD: BigDecimal!
" Amount of input tokens in the market. The ordering should be the same as the market's `inputTokens` field. "
inputTokenBalances: BigDecimal!
" Price per share of input token in USD "
inputTokenPricesUSD: [BigDecimal!]!
" Total supply of output token "
outputTokenSupply: BigDecimal!
" Price per share of output token in USD "
outputTokenPriceUSD: BigDecimal!
" Total amount of reward token emissions in a day, in token's native amount "
rewardTokenEmissionsAmount: [BigDecimal!]
" Total amount of reward token emissions in a day, normalized to USD "
rewardTokenEmissionsUSD: [BigDecimal!]
" Block number of this snapshot "
blockNumber: BigInt!
" Timestamp of this snapshot "
timestamp: BigInt!
##### Lending-Specific #####
" Deposit interest rate in percentage "
depositRate: BigDecimal!
" Borrow interest rate in percentage "
stableBorrowRate: BigDecimal!
" Borrow interest rate in percentage "
variableBorrowRate: BigDecimal!
}
##################################
##### Transaction-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.
"""
interface Event {
" { Transaction hash }-{ Log index } "
id: ID!
" Transaction hash of the transaction that emitted this event "
hash: String!
" Event log index. For transactions that don't emit event, create arbitrary index starting from 0 "
logIndex: Int!
" The protocol this transaction belongs to "
protocol: Protocol!
" Address that received tokens "
to: String!
" Address that sent tokens "
from: String!
blockNumber: BigInt!
timestamp: BigInt!
}
type Deposit implements Event @entity {
" { Transaction hash }-{ Log index } "
id: ID!
" Transaction hash of the transaction that emitted this event "
hash: String!
" Event log index. For transactions that don't emit event, create arbitrary index starting from 0 "
logIndex: Int!
" The protocol this transaction belongs to "
protocol: Protocol!
" Market that tokens are deposited into "
to: String!
" Address that deposited tokens "
from: String!
blockNumber: BigInt!
timestamp: BigInt!
##### Lending-Specific #####
" The market this transaction interacted with "
market: Market!
" Token deposited "
asset: Token!
" Amount of token deposited in native units "
amount: BigDecimal!
" Amount of token deposited in USD "
amountUSD: BigDecimal!
}
type Withdraw implements Event @entity {
" { Transaction hash }-{ Log index }"
id: ID!
" Transaction hash of the transaction that emitted this event "
hash: String!
" Event log index. For transactions that don't emit event, create arbitrary index starting from 0 "
logIndex: Int!
" The protocol this transaction belongs to "
protocol: Protocol!
" Address that received tokens "
to: String!
" Market that tokens are withdrawn from "
from: String!
blockNumber: BigInt!
timestamp: BigInt!
##### Lending-Specific #####
" The market this transaction interacted with "
market: Market!
" Token withdrawn "
asset: Token!
" Amount of token withdrawn in native units "
amount: BigDecimal!
" Amount of token withdrawn in USD "
amountUSD: BigDecimal!
}
type Borrow implements Event @entity {
" { Transaction hash }-{ Log index } "
id: ID!
" Transaction hash of the transaction that emitted this event "
hash: String!
" Event log index. For transactions that don't emit event, create arbitrary index starting from 0 "
logIndex: Int!
" The protocol this transaction belongs to "
protocol: Protocol!
" Address that received tokens "
to: String!
" Market that tokens are borrowed from "
from: String!
blockNumber: BigInt!
timestamp: BigInt!
##### Lending-Specific #####
" The market this transaction interacted with "
market: Market!
" Token borrowed "
asset: Token!
" Amount of token borrowed in native units "
amount: BigDecimal!
" Amount of token borrowed in USD "
amountUSD: BigDecimal
}
type Repay implements Event @entity {
" { Transaction hash }-{ Log index } "
id: ID!
" Transaction hash of the transaction that emitted this event "
hash: String!
" Event log index. For transactions that don't emit event, create arbitrary index starting from 0 "
logIndex: Int!
" The protocol this transaction belongs to "
protocol: Protocol!
" Market that tokens are repaid to "
to: String!
" Address that sent tokens "
from: String!
blockNumber: BigInt!
timestamp: BigInt!
##### Lending-Specific #####
" The market this transaction interacted with "
market: Market!
" Token repaid "
asset: Token!
" Amount of token repaid in native units "
amount: BigDecimal!
" Amount of token repaid in USD "
amountUSD: BigDecimal
}
type Liquidation implements Event @entity {
" { Transaction hash }-{ Log index } "
id: ID!
" Transaction hash of the transaction that emitted this event "
hash: String!
" Event log index. For transactions that don't emit event, create arbitrary index starting from 0 "
logIndex: Int!
" The protocol this transaction belongs to "
protocol: Protocol!
" Market that tokens are repaid to "
to: String!
" Address that carried out the liquidation "
from: String!
blockNumber: BigInt!
timestamp: BigInt!
##### Lending-Specific #####
" The market this transaction interacted with "
market: Market!
" Token liquidated "
asset: Token!
" Amount of token liquidated in native units "
amount: BigDecimal!
" Amount of token liquidated in USD "
amountUSD: BigDecimal
" Amount of profit from liquidation in USD "
profitUSD: BigDecimal
}