-
Notifications
You must be signed in to change notification settings - Fork 10
/
schema.graphql
264 lines (210 loc) · 6.11 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
# See Types in: https://thegraph.com/docs/define-a-subgraph
# - Bytes: Byte array, represented as a hexadecimal string. Commonly used for Ethereum hashes and addresses
# - ID: Stored as a string
# - string: Scalar for string values
# - boolean: Scalar for boolean values
# - Int The GraphQL spec defines Int to have size of 32 bytes
# - BigInt Arbitrarily large integers. Used for Ethereum's uint32, int64, uint64, ..., uint256 types. Note: Everything below uint32, such as int32, uint24 or int8 is represented as i32.
# - BigDecimal BigDecimal is used to represent arbitrary precision decimals
type Token @entity {
"Registered token"
id: ID! # tokenId
address: Bytes!
fromBatchId: BigInt!
# token details (optional)
symbol: String
decimals: BigInt # Used BigInt instead of Int because it doesn't allow an optional u32
name: String
# Balances and Deposits
# balances: [Balance!]! @derivedFrom(field: "token") // TODO: Pending mapping
# deposits: [Deposit!]! @derivedFrom(field: "token") // TODO: Disabled for now, until we sort out how to relate it better
"Cumulative sell volume"
sellVolume: BigInt!
# Audit Dates
createEpoch: BigInt!
# Transaction
txHash: Bytes!
}
type Price @entity {
"Price for a token and batchId"
id: ID! # tokenId + batchId
token: Token!
batchId: BigInt!
# Price and volume
priceInOwlNumerator: BigInt!
priceInOwlDenominator: BigInt!
volume: BigInt!
# Audit Dates
createEpoch: BigInt!
# Transaction
txHash: Bytes!
}
type User @entity {
"User of the protocol. Any ethereum account that deposited tokens or traded"
id: ID! # address
fromBatchId: BigInt!
# Balances, deposits, orders
orders: [Order!]! @derivedFrom(field: "owner")
deposits: [Deposit!]! @derivedFrom(field: "user")
withdrawRequests: [WithdrawRequest!]! @derivedFrom(field: "user")
withdrawals: [Withdraw!]! @derivedFrom(field: "user")
# balances: [Balance!]! @derivedFrom(field: "user") # TODO: Pending implementation
# Audit Dates
createEpoch: BigInt!
# Transaction
txHash: Bytes!
}
# TODO: Pending implementation
#
# type Balance @entity {
# "User's balance for a token"
# id: ID! # user-token
# user: User!
# token: Token!
# balance: BigInt! # TODO: Model also the Fluxs
# # Audit Dates
# createEpoch: BigInt!
# updateEpoch: BigInt!
# }
type Deposit @entity {
"Deposit of an user"
id: ID! # user-token
user: User!
tokenAddress: Bytes!
# token: Token # TODO: Review how can I add the token relationship here considering
amount: BigInt!
batchId: BigInt!
# Audit Dates
createEpoch: BigInt!
# Transaction
txHash: Bytes!
}
type WithdrawRequest @entity {
"Withdraw request of an user"
id: ID! # txHash + id
user: User!
tokenAddress: Bytes!
# token: Token # TODO: Review how can I add the token relationship here considering
amount: BigInt!
withdrawableFromBatchId: BigInt!
# Audit Dates
createEpoch: BigInt!
createBatchId: BigInt!
# Transaction
txHash: Bytes!
}
type Withdraw @entity {
"Withdraw of an user"
id: ID! # txHash + id
user: User!
tokenAddress: Bytes!
# token: Token # TODO: Review how can I add the token relationship here considering
amount: BigInt!
# Audit Dates
createEpoch: BigInt!
createBatchId: BigInt!
# Transaction
txHash: Bytes!
}
type Order @entity {
"Order submitted by an user. It has a validity (dates) so they can only be executed from/until some given batches. Partial executions of this trades must respect the limit price."
id: ID! # ownerAddress + orderId
owner: User! # address - TODO: User
orderId: Int! # uint16
# Validity
fromBatchId: BigInt! # uint32
fromEpoch: BigInt!
untilBatchId: BigInt! # uint32
untilEpoch: BigInt!
# Tokens
buyToken: Token!
sellToken: Token!
# Price
priceNumerator: BigInt! # uint128
priceDenominator: BigInt! # uint128
# Traded amounts
maxSellAmount: BigInt!
minReceiveAmount: BigInt!
soldVolume: BigInt!
boughtVolume: BigInt!
trades: [Trade!]! @derivedFrom(field: "order")
# Audit Dates
createEpoch: BigInt!
cancelEpoch: BigInt
deleteEpoch: BigInt
# Transaction
txHash: Bytes!
txLogIndex: BigInt!
}
type Trade @entity {
"Trade for a single user, as part of a ring trade. It's part of the solution submitted by a solver for a given batch"
id: ID! # txHash + logIndex
order: Order!
# Trade details
owner: User!
sellVolume: BigInt!
buyVolume: BigInt!
tradeBatchId: BigInt!
tradeEpoch: BigInt!
# Tokens
buyToken: Token!
sellToken: Token!
# Audit Dates
# Note that "createEpoch" is different from "tradeEpoch", since "tradeEpoch" is the end of the batch, and the
# "createEpoch" is the date where the transaction was mined
createEpoch: BigInt!
revertEpoch: BigInt
# Transaction
txHash: Bytes!
txLogIndex: BigInt!
}
type Batch @entity {
"Batch executed. Every batch will contain at least solution with the a set of trades that are executed in it"
id: ID! # batchId
# batch details
startEpoch: BigInt!
endEpoch: BigInt
solution: Solution!
solutions: [Solution!]! @derivedFrom(field: "batch")
# Audit Dates
firstSolutionEpoch: BigInt!
lastRevertEpoch: BigInt
# Transaction
txHash: Bytes!
}
type Solution @entity {
id: ID! # txHash + id
batch: Batch!
# Optional for 2 reasons:
# - Events are handled before calls, so the Trade event will be indexed before the submitSolution
solver: User!
feeReward: BigInt!
objectiveValue: BigInt!
utility: BigInt!
# Trades
trades: [Trade!]!
# Audit Dates
createEpoch: BigInt!
revertEpoch: BigInt
# Transaction
txHash: Bytes!
txLogIndex: BigInt!
}
"""
A type collecting global stats about this instance of Gnosis Protocol
"""
type Stats @entity {
id: ID!
"The total volume denominated in OWL (all sell amounts combined)"
volumeInOwl: BigInt!
"The total trader surplus in OWL"
utilityInOwl: BigInt!
"The total amount of OWL burnt (equivalent to fees rewarded to solvers)"
owlBurnt: BigInt!
"The total number of settled batches"
settledBatchCount: Int!
"The total number of settled trades"
settledTradeCount: Int!
"The number of listed tokens"
listedTokens: Int!
}