-
Notifications
You must be signed in to change notification settings - Fork 8
/
schema.graphql
335 lines (302 loc) · 9.44 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
type Pool @entity {
id: ID!
loans: [Loan!]! # TODO: maybe transform into a reverse lookup? https://thegraph.com/docs/define-a-subgraph#writing-mappings
totalDebt: BigInt!
totalBorrowsCount: Int!
totalBorrowsAggregatedAmount: BigInt!
totalRepaysCount: Int!
totalRepaysAggregatedAmount: BigInt!
weightedInterestRate: BigInt!
seniorDebt: BigInt!
seniorInterestRate: BigInt!
minJuniorRatio: BigInt!
maxJuniorRatio: BigInt!
currentJuniorRatio: BigInt!
maxReserve: BigInt!
seniorTokenPrice: BigInt! # assessor
juniorTokenPrice: BigInt! # assessor
juniorYield30Days: BigInt
seniorYield30Days: BigInt
juniorYield90Days: BigInt
seniorYield90Days: BigInt
reserve: BigInt!
assetValue: BigInt!
shortName: String!
version: BigInt!
addresses: PoolAddresses!
}
type PoolAddresses @entity {
id: ID!
coordinator: ID!
assessor: ID!
shelf: ID!
pile: ID!
feed: ID!
reserve: ID!
seniorToken: ID!
juniorToken: ID!
seniorTranche: ID!
juniorTranche: ID!
aoRewardRecipient: ID
makerMgr: ID
}
type PoolRegistry @entity {
id: ID! # address
pools: [Pool!]!
}
type DailyPoolData @entity {
id: ID! # poolId+day
day: Day!
pool: Pool!
reserve: BigInt! # reserve.sol totalBalance()
totalDebt: BigInt! # outstanding Volume (but also is already in the pool)
assetValue: BigInt! # navfeed.sol currentNav()
seniorDebt: BigInt!
seniorTokenPrice: BigInt! # assessor
juniorTokenPrice: BigInt! # assessor
currentJuniorRatio: BigInt!
juniorYield30Days: BigInt
seniorYield30Days: BigInt
juniorYield90Days: BigInt
seniorYield90Days: BigInt
}
type Loan @entity {
id: ID!
pool: Pool!
index: Int!
nftId: String
nftRegistry: Bytes!
owner: Bytes!
opened: Int!
closed: Int! # type Int is non-nullable, so a value of 0 indicates that the loan is still open
debt: BigInt!
interestRatePerSecond: BigInt
ceiling: BigInt
threshold: BigInt
borrowsCount: Int!
borrowsAggregatedAmount: BigInt!
repaysCount: Int!
repaysAggregatedAmount: BigInt!
maturityDate: BigInt
financingDate: BigInt
riskGroup: BigInt
}
type Proxy @entity {
id: ID!
owner: Bytes!
}
type Account @entity {
id: ID! # account address
dailyTokenBalances: [DailyInvestorTokenBalance!] @derivedFrom(field: "account")
# used for reward calculations to determine if an investor has an active investment
rewardCalcBitFlip: Boolean!
}
type ERC20Transfer @entity {
id: ID!
transaction: String! # txhash
token: Token!
from: String!
to: String!
amount: BigInt!
pool: Pool!
}
# used in reward calc
type Token @entity {
id: ID! # token address
symbol: String
owners: [Account!]!
tokenBalances: [TokenBalance!]! @derivedFrom(field: "token")
price: BigInt!
}
# excludes system addresses
type TokenBalance @entity {
id: ID! # account address + token address
owner: Account!
balanceAmount: BigInt!
balanceValue: BigInt!
totalAmount: BigInt! # balanceAmount + supplyAmount
totalValue: BigInt!
token: Token!
# Order Management
# Users can submit supplyOrder or redeemOrder to change their investment in the pool:
# 1) A user can supply DAI which goes into the `pendingSupplyCurrency`
# 2) After each epoch some or all of the pendingSupplyCurrency can be converted to pool shares (DROP/TIN) or some or all of the pendingRedeemToken can be converted to DAI. After each epoch the fulfillment percentage can increase.
# 3) Calling calcDisburse() gives you 4 values:
# - pendingSupplyCurrency: the amount of DAI not converted to tokens yet
# - supplyAmount: the amount of DROP/TIN you will get the next time you call `disburse`
# - pendingRedeemToken: the amount of tokens not redeemed to DAI yet
# - redeemAmount: the amount of DAI you will get next time you call `disburse`
# 4) Calling `disburse` will send all of the above balances to the user (token & currency)
pendingSupplyCurrency: BigInt! # dai not converted into drop/tin yet (remainingSupplyCurrency)
supplyAmount: BigInt! # converted, but not disbursed yet (payoutTokenAmount)
supplyValue: BigInt!
# below two fields are not implemented yet
pendingRedeemToken: BigInt! # amount of tokens the user has pending for redemption
redeemAmount: BigInt! # amount of DAI user gets for a redemption
}
type Day @entity {
id: ID!
reserve: BigInt! # sum for all pools active on this day
totalDebt: BigInt! # sum for all pools active on this day
assetValue: BigInt! # sum for all pools active on this day
seniorDebt: BigInt! # sum for all pools active on this day
dailyPoolData: [DailyPoolData!] @derivedFrom(field: "day")
}
type DailyInvestorTokenBalance @entity {
id: ID! # investorAddress + poolId + day
account: Account!
day: Day!
pool: Pool!
seniorTokenAmount: BigInt! # tb.balanceAmount
seniorTokenValue: BigInt! # pool.seniorTokenPrice
seniorSupplyAmount: BigInt! # tb.supplyAmount
seniorPendingSupplyCurrency: BigInt! # tb.pendingSupplyAmount
juniorTokenAmount: BigInt! # tb.balanceAmount
juniorTokenValue: BigInt! # pool.juniorTokenPrice
juniorSupplyAmount: BigInt! # tb.supplyAmount
juniorPendingSupplyCurrency: BigInt! # tb.pendingSupplyAmount
}
type PoolInvestor @entity {
id: ID! # poolId
accounts: [String!]! # account addresses in pool
}
type GlobalAccountId @entity {
id: ID! # systemwide '1'
accounts: [String!]! # account addresses in system
numInvestors: BigInt # number of investors
}
# system wide by day
type RewardDayTotal @entity {
id: ID! # date
todayValue: BigInt!
toDateAggregateValue: BigInt!
dropRewardRate: BigDecimal!
tinRewardRate: BigDecimal!
aoRewardRate: BigDecimal!
todayReward: BigDecimal!
todayAOReward: BigDecimal!
toDateRewardAggregateValue: BigDecimal!
toDateAORewardAggregateValue: BigDecimal!
}
"""
Rewards accumulated by an account on Ethereum and links Centrifuge Chain accounts that can claim those rewards
"""
type RewardBalance @entity {
"""
Etherum account that earned rewards
"""
id: ID!
"""
Links to Centrifuge Chain accounts with rewards that are currently claimable
"""
links: [RewardLink!]!
"""
Rewards that can be linked or claimed in the future. Rewards only become claimable after an Ethereum account has any
investment for at least 60 consecutive days. Until that is the case, rewards will accumulate in linkableRewards. After
the 60 days are over, rewards will automatically go to the last RewardLink in links. If there is no RewardLink in
links, rewards will stay in linkableRewards until a RewardLink is created.
"""
linkableRewards: BigDecimal!
"""
Sum of all rewards across links and linkableRewards
"""
totalRewards: BigDecimal!
"""
Timestamp (in seconds) since which the Ethereum account had a non-zero investment. Will be set to null when the
investment balance becomes zero on a day. If null and an investment is in the system, will be set to the timestamp of
that day.
"""
nonZeroBalanceSince: BigInt
}
"""
Rewards accumulated by an Asset Originator's (AO's) account on Ethereum and links Centrifuge Chain accounts that can
claim those rewards
"""
type AORewardBalance @entity {
"""
Pool root address (lowercase), note that this is different from investor rewards
"""
id: ID!
"""
Links to Centrifuge Chain accounts with rewards that are currently claimable
"""
links: [RewardLink!]!
"""
Rewards that can be linked or claimed in the future. If the links list is not empty, rewards will automatically go
to the last RewardLink in links. If there is no RewardLink in links, rewards will stay in linkableRewards until a
RewardLink is created.
"""
linkableRewards: BigDecimal!
"""
Sum of all rewards across links and linkableRewards
"""
totalRewards: BigDecimal!
}
"""
Find pools by AO reward recipient Ethereum address
"""
type PoolsByAORewardRecipient @entity {
"""
Lowercased Ethereum address of the recipient of the rewards, which is a dedicated address set in the pool config
retrieved from IPFS.
"""
id: ID!
pools: [Pool!]!
}
# this is a historical value and will not be responsible
# for keeping track of claims made on cent chain
# rewards earned from token investment
type RewardByToken @entity {
id: ID! # investorAddress + token address
token: String!
account: String!
rewards: BigDecimal!
}
"""
A link between an Ethereum account and an account on Centrifuge Chain. Any balance that are accumulated on that account
are claimable on Centrifuge Chain
"""
type RewardLink @entity {
id: ID! #eth address + cent address
"""
Ethereum address that has earned the rewards
"""
ethAddress: String!
"""
Hex encoded public key of an account on Centrifuge Chain that will receive rewards
"""
centAddress: String!
"""
Rewards that are claimable by the Centrifuge Chain account
"""
rewardsAccumulated: BigDecimal!
}
type InvestorTransaction @entity {
id: ID! #TX hash + owner address + tranche + transaction type enum
transaction: String! # txhash
owner: Account!
pool: Pool!
symbol: String!
timestamp: BigInt!
type: TransactionType!
tokenAmount: BigInt!
currencyAmount: BigInt!
newBalance: BigInt!
newBalanceValue: BigInt!
tokenPrice: BigInt!
gasPrice: BigInt!
gasUsed: BigInt!
}
enum TransactionType {
INVEST_ORDER
REDEEM_ORDER
INVEST_CANCEL
REDEEM_CANCEL
INVEST_EXECUTION
REDEEM_EXECUTION
}
type PrevInvestorTransactionByToken @entity {
id: ID! #owner address + token address
prevTransaction: InvestorTransaction
pendingExecution: Boolean # Indicates whether the transaction was not fully executed and thus a follow-up execution should be expected
}