forked from ChaosLabsInc/subgraph-benqi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
schema.graphql
651 lines (598 loc) · 20 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
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
"""
The Comptroller type has protocol level variables stored
"""
type Comptroller @entity {
"ID is set to 1"
id: ID!
"Address of price oracle the comptroller uses"
priceOracle: Bytes
"Factor used to determine repayAmount for liquidating"
closeFactor: BigInt
"The percent bonus liquidators get for liquidating"
liquidationIncentive: BigInt
"Comptroller address"
address: Bytes!
}
interface MarketInfo {
#Fields that match compounds API
"The protocol utilization rate with 18 decimal places"
utilizationRate: BigDecimal!
"Borrow interest rate for the current timestamp based on utilization rate"
borrowRatePerTimestamp: BigInt!
"Yearly borrow rate. With 31536000 seconds per year"
borrowRateAPY: BigDecimal!
"The cToken contract balance of ERC20 or ETH"
cash: BigDecimal!
"Collateral factor determining how much one can borrow"
collateralFactor: BigDecimal!
"Exchange rate of tokens / cTokens"
exchangeRate: BigDecimal!
"Address of the interest rate model"
interestRateModelAddress: Bytes
"Reserves stored in the contract"
reserves: BigDecimal
"Supply interest rate for the current timestamp based on utilization rate"
supplyRatePerTimestamp: BigInt!
"Yearly supply rate. With 2104400 blocks per year"
supplyRateAPY: BigDecimal
"Borrows in the market"
totalBorrows: BigDecimal!
"CToken supply. CTokens have 8 decimals"
totalSupply: BigDecimal!
"Number of users holding market tokens"
suppliersCount: Int!
"Number of users with pending borrows"
borrowersCount: Int!
"Underlying price of token in ETH (ex. 0.007 DAI)"
underlyingPrice: BigDecimal!
# Fields that are not in compounds api
"Block timestamp the market is updated to"
accrualBlockTimestamp: BigInt
"Timestamp the market was most recently updated"
blockTimestamp: BigInt!
"The history of the markets borrow index return (Think S&P 500)"
borrowIndex: BigDecimal!
"The factor determining interest that goes to reserves"
reserveFactor: BigDecimal!
"Underlying token price in USD"
underlyingPriceUSD: BigDecimal!
}
"""
Market stores all high level variables for a cToken market
"""
type Market implements MarketInfo @entity {
"CToken address"
id: ID!
### INTERFACE FIELDS
#Fields that match compounds API
"The protocol utilization rate with 18 decimal places"
utilizationRate: BigDecimal!
"Borrow interest rate for the current timestamp based on utilization rate"
borrowRatePerTimestamp: BigInt!
"Yearly borrow rate. With 31536000 seconds per year"
borrowRateAPY: BigDecimal!
"The cToken contract balance of ERC20 or ETH"
cash: BigDecimal!
"Collateral factor determining how much one can borrow"
collateralFactor: BigDecimal!
"Exchange rate of tokens / cTokens"
exchangeRate: BigDecimal!
"Address of the interest rate model"
interestRateModelAddress: Bytes
"Reserves stored in the contract"
reserves: BigDecimal
"Supply interest rate for the current timestamp based on utilization rate"
supplyRatePerTimestamp: BigInt!
"Yearly supply rate. With 2104400 blocks per year"
supplyRateAPY: BigDecimal
"Borrows in the market"
totalBorrows: BigDecimal!
"CToken supply. CTokens have 8 decimals"
totalSupply: BigDecimal!
"Number of users holding market tokens"
suppliersCount: Int!
"Number of users with pending borrows"
borrowersCount: Int!
"Underlying price of token in ETH (ex. 0.007 DAI)"
underlyingPrice: BigDecimal!
# Fields that are not in compounds api
"Block the market is updated to"
accrualBlockTimestamp: BigInt
"Timestamp the market was most recently updated"
blockTimestamp: BigInt!
"The history of the markets borrow index return (Think S&P 500)"
borrowIndex: BigDecimal!
"The factor determining interest that goes to reserves"
reserveFactor: BigDecimal!
"Underlying token price in USD"
underlyingPriceUSD: BigDecimal!
### END OF INTERFACE FIELDS
#Fields that match compounds API
"Name of the cToken"
name: String!
"CToken symbol"
symbol: String!
"Underlying token name"
underlyingName: String!
"Underlying token symbol"
underlyingSymbol: String!
# Fields that are not in compounds api
"Underlying token decimal length"
underlyingDecimals: Int!
"Accounts that have interacted with this market"
accounts: [AccountCToken!]! @derivedFrom(field: "market")
marketEvents: [AccountCTokenEvent!]! @derivedFrom(field: "market")
# @yhayun - added specifically for benqi:
"Underlying token"
denomination: Token
hourlySnapshots: [MarketHourlySnapshot!]! @derivedFrom(field: "market")
dailySnapshots: [MarketDailySnapshot!]! @derivedFrom(field: "market")
}
"""
Saves the historical values in the Market over time for every beginning of hour in UTC.
Basically a copy of the market values in that particular moment
"""
type MarketHourlySnapshot implements MarketInfo @entity {
"The id is marketId-timestamp"
id: ID!
market: Market!
"UTC timestamp for the beginning of the hour (ex.: timestamp for 01:00:00, 14:00:00, ...)"
timestamp: BigInt!
lastBlockNumber: BigInt!
lastBlockHash: Bytes!
### INTERFACE FIELDS
#Fields that match compounds API
"The protocol utilization rate with 18 decimal places"
utilizationRate: BigDecimal!
"Borrow interest rate for the current timestamp based on utilization rate"
borrowRatePerTimestamp: BigInt!
"Yearly borrow rate. With 31536000 seconds per year"
borrowRateAPY: BigDecimal!
"The cToken contract balance of ERC20 or ETH"
cash: BigDecimal!
"Collateral factor determining how much one can borrow"
collateralFactor: BigDecimal!
"Exchange rate of tokens / cTokens"
exchangeRate: BigDecimal!
"Address of the interest rate model"
interestRateModelAddress: Bytes
"Reserves stored in the contract"
reserves: BigDecimal
"Supply interest rate for the current timestamp based on utilization rate"
supplyRatePerTimestamp: BigInt!
"Yearly supply rate. With 2104400 blocks per year"
supplyRateAPY: BigDecimal
"Borrows in the market"
totalBorrows: BigDecimal!
"CToken supply. CTokens have 8 decimals"
totalSupply: BigDecimal!
"Number of users holding market tokens"
suppliersCount: Int!
"Number of users with pending borrows"
borrowersCount: Int!
"Underlying price of token in ETH (ex. 0.007 DAI)"
underlyingPrice: BigDecimal!
# Fields that are not in compounds api
"Block the market is updated to"
accrualBlockTimestamp: BigInt
"Timestamp the market was most recently updated"
blockTimestamp: BigInt!
"The history of the markets borrow index return (Think S&P 500)"
borrowIndex: BigDecimal!
"The factor determining interest that goes to reserves"
reserveFactor: BigDecimal!
"Underlying token price in USD"
underlyingPriceUSD: BigDecimal!
### END OF INTERFACE FIELDS
}
"""
Saves the historical values in the Market over time for every beginning of a day in UTC.
Basically a copy of the market values in that particular moment
"""
type MarketDailySnapshot implements MarketInfo @entity {
"The id is marketId-timestamp"
id: ID!
market: Market!
"UTC timestamp for the beginning of the day (ex.: timestamp for Day 1 00:00:00, Day 2 00:00:00, ...)"
timestamp: BigInt!
lastBlockNumber: BigInt!
lastBlockHash: Bytes!
### INTERFACE FIELDS
#Fields that match compounds API
"The protocol utilization rate with 18 decimal places"
utilizationRate: BigDecimal!
"Borrow interest rate for the current timestamp based on utilization rate"
borrowRatePerTimestamp: BigInt!
"Yearly borrow rate. With 31536000 seconds per year"
borrowRateAPY: BigDecimal!
"The cToken contract balance of ERC20 or ETH"
cash: BigDecimal!
"Collateral factor determining how much one can borrow"
collateralFactor: BigDecimal!
"Exchange rate of tokens / cTokens"
exchangeRate: BigDecimal!
"Address of the interest rate model"
interestRateModelAddress: Bytes
"Reserves stored in the contract"
reserves: BigDecimal
"Supply interest rate for the current timestamp based on utilization rate"
supplyRatePerTimestamp: BigInt!
"Yearly supply rate. With 2104400 blocks per year"
supplyRateAPY: BigDecimal
"Borrows in the market"
totalBorrows: BigDecimal!
"CToken supply. CTokens have 8 decimals"
totalSupply: BigDecimal!
"Number of users holding market tokens"
suppliersCount: Int!
"Number of users with pending borrows"
borrowersCount: Int!
"Underlying price of token in ETH (ex. 0.007 DAI)"
underlyingPrice: BigDecimal!
# Fields that are not in compounds api
"Block the market is updated to"
accrualBlockTimestamp: BigInt
"Timestamp the market was most recently updated"
blockTimestamp: BigInt!
"The history of the markets borrow index return (Think S&P 500)"
borrowIndex: BigDecimal!
"The factor determining interest that goes to reserves"
reserveFactor: BigDecimal!
"Underlying token price in USD"
underlyingPriceUSD: BigDecimal!
### END OF INTERFACE FIELDS
}
type AccountMarketSnapshot @entity {
"AccountId-MarketId"
id: ID!
accountMarket: AccountCToken!
accrualBlockTimestamp: BigInt
blockNumber: BigInt!
timestamp: BigInt!
totalSupplyAmount: BigDecimal!
storedBorrowBalance: BigDecimal!
borrowBalanceWithInterest: BigDecimal!
marketBorrowIndex: BigDecimal!
accountBorrowIndex: BigDecimal!
exchangeRate: BigDecimal!
}
"""
Account is an ETH address, with a list of all cToken markets the account has
participated in, along with liquidation information.
"""
type Account @entity {
"User ETH address"
id: ID!
"Array of CTokens user is in"
tokens: [AccountCToken!]! @derivedFrom(field: "account")
"Count user has been liquidated"
countLiquidated: Int!
"Count user has liquidated others"
countLiquidator: Int!
"True if user has ever borrowed"
hasBorrowed: Boolean!
accountEvents: [AccountCTokenEvent!]! @derivedFrom(field: "account")
# The following values are added by the JS Wrapper, and must be calculated with the most up
# to date values based on the block delta for market.exchangeRate and market.borrowIndex
# They do not need to be in the schema, but they will show up in the explorer playground
# "If less than 1, the account can be liquidated
# health: BigDecimal!
# "Total assets supplied by user"
# totalBorrowValueInEth: BigDecimal!
# "Total assets borrowed from user"
# totalCollateralValueInEth: BigDecimal!
}
"""
AccountCToken is a single account within a single cToken market, with data such
as interest earned or paid
"""
type AccountCToken @entity {
"Concatenation of CToken address and user address"
id: ID!
"Relation to market"
market: Market!
"Symbol of the cToken"
symbol: String!
"Relation to user"
account: Account!
"Block number this asset was updated at in the contract"
accrualBlockTimestamp: BigInt!
"True if user is entered, false if they are exited"
enteredMarket: Boolean!
"CToken balance of the user"
cTokenBalance: BigDecimal!
"Total amount of underlying supplied"
totalUnderlyingSupplied: BigDecimal!
"Total amount of underling redeemed"
totalUnderlyingRedeemed: BigDecimal!
"The value of the borrow index upon users last interaction"
accountBorrowIndex: BigDecimal!
"Total amount underlying borrowed, exclusive of interest"
totalUnderlyingBorrowed: BigDecimal!
"Total amount underlying repaid"
totalUnderlyingRepaid: BigDecimal!
"Current borrow balance stored in contract (exclusive of interest since accrualBlockTimestamp)"
storedBorrowBalance: BigDecimal!
"Historical snapshots for this Account-Market association"
snapshots: [AccountMarketSnapshot!]! @derivedFrom(field: "accountMarket")
tokenEvents: [AccountCTokenEvent!]! @derivedFrom(field: "accountCToken")
# The following values are added by the JS Wrapper, and must be calculated with the most up
# to date values based on the block delta for market.exchangeRate and market.borrowIndex
# They do not need to be in the schema, but they will show up in the explorer playground
# NOTE: this a custom feature that The Graph implemented for our subgraph. It's not yet
# available to the public.
# supplyBalanceUnderlying: BigDecimal!
# FORMULA: supplyBalanceUnderlying = cTokenBalance * market.exchangeRate
# lifetimeSupplyInterestAccrued: BigDecimal!
# FORMULA: lifetimeSupplyInterestAccrued = supplyBalanceUnderlying - totalUnderlyingSupplied + totalUnderlyingRedeemed
# borrowBalanceUnderlying: BigDecimal!
# FORMULA: borrowBalanceUnderlying = storedBorrowBalance * market.borrowIndex / accountBorrowIndex
# lifetimeBorrowInterestAccrued: BigDecimal!
# FORMULA: lifetimeBorrowInterestAccrued = borrowBalanceUnderlying - totalUnderlyingBorrowed + totalUnderlyingRepaid
}
"""
Relationship entity to map between events with Account and Market entities
"""
type AccountCTokenEvent @entity(immutable: true) {
"AccountCToken id concatenated with event id"
id: ID!
account: Account!
market: Market!
event: CTokenEvent!
"This is redundant with the other two, but allows us to add a relation in the AccountCToken entity as well"
accountCToken: AccountCToken!
}
"""
Types of CTokenEvents
"""
enum CTokenEventType {
Transfer
Mint
Redeem
Borrow
RepayBorrow
Liquidation
MarketEntered
MarketExited
}
"""
An interface for an event of any cToken. TransferEvent, MintEvent,
RedeemEvent, BorrowEvent, RepayEvent, MarketEnteredEvent, MarketExitedEvent and LiquidationEvent all use this interface
"""
interface CTokenEvent {
"Transaction hash concatenated with log index"
id: ID!
"Type of the specific transfer"
type: CTokenEventType!
"The tx_hash that contains this event"
tx_hash: Bytes!
"The index of the associated log inside the transaction that corresponds to this event"
logIndex: BigInt!
"Block number"
blockNumber: BigInt!
"Block time"
blockTime: BigInt!
}
"""
TransferEvent will be stored for every mint, redeem, liquidation, and any normal
transfer between two accounts.
"""
type TransferEvent implements CTokenEvent @entity(immutable: true) {
"Transaction hash concatenated with log index"
id: ID!
"Type of the specific transfer"
type: CTokenEventType!
"The tx_hash that contains this event"
tx_hash: Bytes!
"The index of the associated log inside the transaction that corresponds to this event"
logIndex: BigInt!
"The cToken transferred"
market: Market!
"Account that received tokens"
to: Account
"Account that sent tokens"
from: Account
"cTokens transferred"
amount: BigDecimal!
"Block number"
blockNumber: BigInt!
"Block time"
blockTime: BigInt!
}
"""
MintEvent stores information for mints. From address will always be a cToken
market address
"""
type MintEvent implements CTokenEvent @entity(immutable: true) {
"Transaction hash concatenated with log index"
id: ID!
"Type of the specific transfer"
type: CTokenEventType!
"The tx_hash that contains this event"
tx_hash: Bytes!
"The index of the associated log inside the transaction that corresponds to this event"
logIndex: BigInt!
"The cToken transferred"
market: Market!
"Account that received tokens (minter)"
user: Account!
"cTokens transferred"
amount: BigDecimal!
"Underlying token amount transferred"
underlyingAmount: BigDecimal
"Block number"
blockNumber: BigInt!
"Block time"
blockTime: BigInt!
}
"""
RedeemEvent stores information for redeems. To address will always be a
cToken market address
"""
type RedeemEvent implements CTokenEvent @entity(immutable: true) {
"Transaction hash concatenated with log index"
id: ID!
"Type of the specific transfer"
type: CTokenEventType!
"The tx_hash that contains this event"
tx_hash: Bytes!
"The index of the associated log inside the transaction that corresponds to this event"
logIndex: BigInt!
"The cToken transferred"
market: Market!
"Account that sent tokens (redeemer)"
user: Account!
"cTokens transferred"
amount: BigDecimal!
"Underlying token amount transferred"
underlyingAmount: BigDecimal
"Block number"
blockNumber: BigInt!
"Block time"
blockTime: BigInt!
}
"""
LiquidationEvent stores information for liquidations. The event is emitted from
the cToken market address.
"""
type LiquidationEvent implements CTokenEvent @entity(immutable: true) {
"Transaction hash concatenated with log index"
id: ID!
"Type of the specific transfer"
type: CTokenEventType!
"The tx_hash that contains this event"
tx_hash: Bytes!
"The index of the associated log inside the transaction that corresponds to this event"
logIndex: BigInt!
"cToken that was seized as collateral"
seizedMarket: Market!
"The cToken that was repaid during this liquidation"
repayMarket: Market!
"Liquidator receiving tokens"
liquidator: Account!
"Account being liquidated (borrower)"
borrower: Account!
"cTokens seized"
seizedTokens: BigDecimal!
"Symbol of the underlying asset repaid through liquidation"
underlyingSymbol: String!
"Underlying cToken amount that was repaid by liquidator"
underlyingRepayAmount: BigDecimal!
"Block number"
blockNumber: BigInt!
"Block time"
blockTime: BigInt!
}
"""
BorrowEvent stores information for borrows
"""
type BorrowEvent implements CTokenEvent @entity(immutable: true) {
"Transaction hash concatenated with log index"
id: ID!
"Specific type of the implementation"
type: CTokenEventType!
"The tx_hash that contains this event"
tx_hash: Bytes!
"The index of the associated log inside the transaction that corresponds to this event"
logIndex: BigInt!
"Market from which the token is being borrowed"
market: Market!
"Account that borrowed the tokens"
borrower: Account!
"Amount of underlying borrowed"
amount: BigDecimal!
"Total borrows of this asset the account has"
accountBorrows: BigDecimal!
"Symbol of the borrowed underlying asset"
underlyingSymbol: String!
"Block number"
blockNumber: BigInt!
"Block time"
blockTime: BigInt!
}
"""
RepayEvent stores information for repays. Payer is not always the same as
borrower, such as in the event of a Liquidation
"""
type RepayEvent implements CTokenEvent @entity(immutable: true) {
"Transaction hash concatenated with log index"
id: ID!
"Specific type of the implementation"
type: CTokenEventType!
"The tx_hash that contains this event"
tx_hash: Bytes!
"The index of the associated log inside the transaction that corresponds to this event"
logIndex: BigInt!
"Market to which the token is being repaid"
market: Market!
"Account that borrowed the tokens"
borrower: Account!
"Payer of the borrow funds"
payer: Account!
"Amount of underlying repaid"
amount: BigDecimal!
"Total borrows of this asset the account has"
accountBorrows: BigDecimal!
"Symbol of the borrowed underlying asset"
underlyingSymbol: String!
"Block number"
blockNumber: BigInt!
"Block time"
blockTime: BigInt!
}
"""
MarketEnteredEvent stores information for markets activated as collateral.
"""
type MarketEnteredEvent implements CTokenEvent @entity(immutable: true) {
"Transaction hash concatenated with log index"
id: ID!
"Specific type of the implementation"
type: CTokenEventType!
"The tx_hash that contains this event"
tx_hash: Bytes!
"The index of the associated log inside the transaction that corresponds to this event"
logIndex: BigInt!
"Market to which the token is being repaid"
market: Market!
"Account that borrowed the tokens"
account: Account!
"Block number"
blockNumber: BigInt!
"Block time"
blockTime: BigInt!
}
"""
MarketExitedEvent stores information for markets deactivated as collateral.
"""
type MarketExitedEvent implements CTokenEvent @entity(immutable: true) {
"Transaction hash concatenated with log index"
id: ID!
"Specific type of the implementation"
type: CTokenEventType!
"The tx_hash that contains this event"
tx_hash: Bytes!
"The index of the associated log inside the transaction that corresponds to this event"
logIndex: BigInt!
"Market to which the token is being repaid"
market: Market!
"Account that borrowed the tokens"
account: Account!
"Block number"
blockNumber: BigInt!
"Block time"
blockTime: BigInt!
}
type Token @entity(immutable: true) {
"Token address"
id: ID!
"Token address"
address: Bytes!
"Token name"
name: String
"Token symbol"
symbol: String
"Token decimals"
decimals: Int
"Token's total supply"
totalSupply: BigInt
}