forked from graphprotocol/compound-v2-subgraph
-
Notifications
You must be signed in to change notification settings - Fork 0
/
schema.graphql
344 lines (318 loc) · 10.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
"""
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
"Max assets a single user can enter"
maxAssets: BigInt
}
"""
Market stores all high level variables for a cToken market
"""
type Market @entity {
#Fields that match compounds API
"Yearly borrow rate. With 2102400 blocks per year"
borrowRate: 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!
"Name of the cToken"
name: String!
"Reserves stored in the contract"
reserves: BigDecimal!
"Yearly supply rate. With 2104400 blocks per year"
supplyRate: BigDecimal!
"CToken symbol"
symbol: String!
"CToken address"
id: ID!
"Borrows in the market"
totalBorrows: BigDecimal!
"CToken supply. CTokens have 8 decimals"
totalSupply: BigDecimal!
"Underlying token address"
underlyingAddress: Bytes!
"Underlying token name"
underlyingName: String!
"Underlying price of token in ETH (ex. 0.007 DAI)"
underlyingPrice: BigDecimal!
"Underlying token symbol"
underlyingSymbol: String!
# Fields that are not in compounds api
"Block the market is updated to"
accrualBlockNumber: Int!
"Timestamp the market was most recently updated"
blockTimestamp: Int!
"The history of the markets borrow index return (Think S&P 500)"
borrowIndex: BigDecimal!
"The factor determining interest that goes to reserves"
reserveFactor: BigInt!
"Underlying token price in USD"
underlyingPriceUSD: BigDecimal!
"Underlying token decimal length"
underlyingDecimals: Int!
}
"""
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!
# 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!
"Transactions data"
transactions: [AccountCTokenTransaction!]! @derivedFrom(field:"account")
"Block number this asset was updated at in the contract"
accrualBlockNumber: 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 accrualBlockNumber)"
storedBorrowBalance: BigDecimal!
# 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
}
"""
Auxiliary entity for AccountCToken
"""
type AccountCTokenTransaction @entity {
id: ID!
account: AccountCToken!
tx_hash: Bytes!
timestamp: BigInt!
block: BigInt!
logIndex: BigInt!
}
"""
An interface for a transfer of any cToken. TransferEvent, MintEvent,
RedeemEvent, and LiquidationEvent all use this interface
"""
interface CTokenTransfer {
"Transaction hash concatenated with log index"
id: ID!
"cTokens transferred"
amount: BigDecimal!
"Account that received tokens"
to: Bytes!
"Account that sent tokens"
from: Bytes!
"Block number"
blockNumber: Int!
"Block time"
blockTime: Int!
"Symbol of the cToken transferred"
cTokenSymbol: String!
}
"""
TransferEvent will be stored for every mint, redeem, liquidation, and any normal
transfer between two accounts.
"""
type TransferEvent implements CTokenTransfer @entity {
"Transaction hash concatenated with log index"
id: ID!
"cTokens transferred"
amount: BigDecimal!
"Account that received tokens"
to: Bytes!
"Account that sent tokens"
from: Bytes!
"Block number"
blockNumber: Int!
"Block time"
blockTime: Int!
"Symbol of the cToken transferred"
cTokenSymbol: String!
}
"""
MintEvent stores information for mints. From address will always be a cToken
market address
"""
type MintEvent implements CTokenTransfer @entity {
"Transaction hash concatenated with log index"
id: ID!
"cTokens transferred"
amount: BigDecimal!
"Account that received tokens (minter)"
to: Bytes!
"Account that sent tokens (CToken contract)"
from: Bytes!
"Block number"
blockNumber: Int!
"Block time"
blockTime: Int!
"Symbol of the cToken transferred"
cTokenSymbol: String!
"Underlying token amount transferred"
underlyingAmount: BigDecimal
}
"""
RedeemEvent stores information for redeems. To address will always be a
cToken market address
"""
type RedeemEvent implements CTokenTransfer @entity {
"Transaction hash concatenated with log index"
id: ID!
"cTokens transferred"
amount: BigDecimal!
"Account that received tokens (CToken contract)"
to: Bytes!
"Account that sent tokens (redeemer)"
from: Bytes!
"Block number"
blockNumber: Int!
"Block time"
blockTime: Int!
"Symbol of the cToken transferred"
cTokenSymbol: String!
"Underlying token amount transferred"
underlyingAmount: BigDecimal
}
"""
LiquidationEvent stores information for liquidations. The event is emitted from
the cToken market address.
"""
type LiquidationEvent implements CTokenTransfer @entity {
"Transaction hash concatenated with log index"
id: ID!
"cTokens seized"
amount: BigDecimal!
"Liquidator receiving tokens"
to: Bytes!
"Account being liquidated (borrower)"
from: Bytes!
"Block number"
blockNumber: Int!
"Block time"
blockTime: Int!
"cToken that was sezied as collateral"
cTokenSymbol: String!
"Symbol of the underlying asset repaid through liquidation"
underlyingSymbol: String!
"Underlying cToken amount that was repaid by liquidator"
underlyingRepayAmount: BigDecimal!
}
"""
Underlying transfers are transfers of underlying collateral for both borrows
and repays
"""
interface UnderlyingTransfer {
"Transaction hash concatenated with log index"
id: ID!
"Amount of underlying borrowed"
amount: BigDecimal!
"Total borrows of this asset the account has"
accountBorrows: BigDecimal!
"Account that borrowed the tokens"
borrower: Bytes!
"Block number"
blockNumber: Int!
"Block time"
blockTime: Int!
"Symbol of the borrowed underlying asset"
underlyingSymbol: String!
}
"""
BorrowEvent stores information for borrows
"""
type BorrowEvent implements UnderlyingTransfer @entity {
"Transaction hash concatenated with log index"
id: ID!
"Amount of underlying borrowed"
amount: BigDecimal!
"Total borrows of this asset the account has"
accountBorrows: BigDecimal!
"Account that borrowed the tokens"
borrower: Bytes!
"Block number"
blockNumber: Int!
"Block time"
blockTime: Int!
"Symbol of the borrowed underlying asset"
underlyingSymbol: String!
}
"""
RepayEvent stores information for repays. Payer is not always the same as
borrower, such as in the event of a Liquidation
"""
type RepayEvent implements UnderlyingTransfer @entity {
"Transaction hash concatenated with log index"
id: ID!
"Amount of underlying repaid"
amount: BigDecimal!
"Total borrows of this asset the account has"
accountBorrows: BigDecimal!
"Account that borrowed the tokens"
borrower: Bytes!
"Block number"
blockNumber: Int!
"Block time"
blockTime: Int!
"Symbol of the borrowed underlying asset"
underlyingSymbol: String!
"Payer of the borrow funds"
payer: Bytes!
}