-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschema.graphql
539 lines (507 loc) · 13.9 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
type Analytics @entity {
# factory address - for uniqueness
id: Bytes!
totalUsers: BigInt!
totalTransactions: BigInt!
totalTokensLocked: BigInt!
totalVolumeBuilds: BigInt!
totalVolumeUnwinds: BigInt!
totalVolumeLiquidations: BigInt!
totalVolume: BigInt!
}
type AnalyticsHourData @entity {
# factory address concatendated with date - for uniqueness
id: Bytes!
# unix timestamp for start of hour
periodStartUnix: Int!
totalUsers: BigInt!
totalTransactions: BigInt!
totalTokensLocked: BigInt!
totalVolumeBuilds: BigInt!
totalVolumeUnwinds: BigInt!
totalVolumeLiquidations: BigInt!
totalVolume: BigInt!
}
type Factory @entity {
# factory address
id: Bytes!
# amount of markets created
marketCount: BigInt!
# amount of transactions all time
txCount: BigInt!
# total volumne all time in OVL
totalVolumeOVL: BigDecimal!
# total fees generated in OVL
totalFeesOVL: BigDecimal!
# total value locked in OVL
totalValueLockedOVL: BigDecimal!
# fee receipient address
feeRecipient: ID!
# owner of factory
owner: ID!
# markets held in factory contract
markets: [Market!]! @derivedFrom(field: "factory")
}
type Market @entity {
# market contract address
id: Bytes!
# feed contract address
feedAddress: String!
# factory contract address
factory: Factory!
# creation timestamp
createdAtTimestamp: BigInt!
# creation block number
createdAtBlockNumber: BigInt!
# funding constant
k: BigInt!
# market impact constant
lmbda: BigInt!
# bid-ask static spread constant
delta: BigInt!
# cap pay-off
capPayoff: BigInt!
# notional cap
capNotional: BigInt!
# leverage cap
capLeverage: BigInt!
# trailing window for circuit breaker
circuitBreakerWindow: BigInt!
# target worst case inflation rate over trailing window
circuitBreakerMintTarget: BigInt!
# maintenance margin constant
maintenanceMarginFraction: BigInt!
# burn rate for maintenance margin constant
maintenanceMarginBurnRate: BigInt!
# liquidation fees
liquidationFeeRate: BigInt!
# trading fees on build/unwind
tradingFeeRate: BigInt!
# minimum collateral to open a position in OVL
minCollateral: BigInt!
# upper limit for price feed changes since last update
priceDriftUpperLimit: BigInt!
# average block time of the respective chain
averageBlockTime: BigInt!
# total current oi long
oiLong: BigInt!
# total current oi short
oiShort: BigInt!
# oi long shares
oiLongShares: BigInt!
# oi short shares
oiShortShares: BigInt!
# if market is shut down
isShutdown: Boolean!
# fees and tx count:
# number of builds/positions
numberOfBuilds: BigInt!
# sum of all build fees
totalBuildFees: BigInt!
# number of unwinds
numberOfUnwinds: BigInt!
# sum of all build fees
totalUnwindFees: BigInt!
# number of liquidates
numberOfLiquidates: BigInt!
# sum of all build fees
totalLiquidateFees: BigInt!
# sum of all fees
totalFees: BigInt!
# sum of volume
totalVolume: BigInt!
# positive means net minting | negative means net burning
totalMint: BigInt!
# used in dataIsValid function
dpUpperLimit: BigInt!
# derived fields
marketHourData: [MarketHourData!]! @derivedFrom(field: "market")
# positions held in market
positions: [Position!]! @derivedFrom(field: "market")
# last state of the market
marketState: MarketState! @derivedFrom(field: "market")
}
type MarketState @entity {
# market address
id: Bytes!
market: Market!
bid: BigInt!
ask: BigInt!
mid: BigInt!
volumeBid: BigInt!
volumeAsk: BigInt!
oiLong: BigInt!
oiShort: BigInt!
capOi: BigInt!
circuitBreakerLevel: BigInt!
fundingRate: BigInt!
}
type Position @entity {
# market contract concat'd with position id
id: ID!
# position id
positionId: String!
# owner of position
owner: Account!
# market contract address related to position
market: Market!
# initial oi when building position
initialOi: BigInt!
# initial debt when building position
initialDebt: BigInt!
# initial collateral at time of building position
initialCollateral: BigInt!
# initial notional at time of building position
initialNotional: BigInt!
# leverage taken on position
leverage: BigDecimal!
# total fraction unwound from inception
fractionUnwound: BigInt!
# long/short
isLong: Boolean!
# entry price when building position
entryPrice: BigInt!
# is position liquidated
isLiquidated: Boolean!
# current oi
currentOi: BigInt!
# current debt
currentDebt: BigInt!
# total ovl minted/burned from transactions
mint: BigInt!
# time stamp of position creation
createdAtTimestamp: BigInt!
# block number of position creation
createdAtBlockNumber: BigInt!
# number of unwinds
numberOfUniwnds: BigInt!
# derived fields
builds: [Build!]! @derivedFrom(field: "position")
liquidates: [Liquidate!]! @derivedFrom(field: "position")
unwinds: [Unwind!]! @derivedFrom(field: "position")
}
type Transaction @entity {
# txn hash
id: Bytes!
# block txn was included in
blockNumber: BigInt!
# timestamp txn was confirmed
timestamp: BigInt!
# gas settings during txn execution
gasLimit: BigInt!
gasPrice: BigInt!
# derived values
builds: [Build!]! @derivedFrom(field: "transaction")
unwinds: [Unwind!]! @derivedFrom(field: "transaction")
liquidates: [Liquidate!]! @derivedFrom(field: "transaction")
tokenTransfers: [TokenTransfer!]! @derivedFrom(field: "transaction")
}
type Build @entity {
# market contract concat'd with position id
id: ID!
# account performing action
owner: Account!
# position entitie
position: Position!
# price at time of build
price: BigInt!
# Fee amount of this build
feeAmount: BigInt!
# timestamp of transaction
timestamp: BigInt!
# transaction the position was built in
transaction: Transaction!
}
type Unwind @entity {
# market contract concat'd with position id concat'd with unwind number
id: ID!
# account performing action
owner: Account!
# position id
position: Position!
# unwind number
unwindNumber: BigInt!
# amount of oi unwound
oiUnwound: BigInt!
# price at time of unwind
price: BigInt!
# fraction of unwind
fraction: BigInt!
# fraction of the original position
fractionOfPosition: BigInt!
# amount of OVL transferred to the owner
transferAmount: BigInt!
# PnL of this unwind
pnl: BigInt!
# Fee amount of this unwind
feeAmount: BigInt!
# funding payment of this unwind
fundingPayment: BigInt!
# fraction of initial collateral of this unwind
size: BigInt!
# volume = transferAmount + (initialDebt * fractionOfPosition)
volume: BigInt!
# total ovl minted/burned in this unwind
mint: BigInt!
# timestamp of transaction
timestamp: BigInt!
# transaction the position was unwinded in
transaction: Transaction!
}
type Liquidate @entity {
# market contract concat'd with position id
id: ID!
# owner of the position
owner: Account!
# address performing the transaction
sender: Account!
# position id
position: Position!
# fraction of the original position
fractionOfPosition: BigInt!
# funding payment of this liquidation
fundingPayment: BigInt!
# liquidate size = initialCollateral * fractionOfPosition
size: BigInt!
# price at time of liquidate
price: BigInt!
# total ovl minted/burned in this transaction
mint: BigInt!
# timestamp of transaction
timestamp: BigInt!
# transaction the position was liquidated in
transaction: Transaction!
# volume = (initialDebt * fractionOfPosition) + liquidationFee + marginRemaining
# TODO add marginToBurn
volume: BigInt!
# amount sent to liquidator (tx sender)
liquidationFee: BigInt!
marginToBurn: BigInt!
transferFeeAmount: BigInt!
}
type Account @entity {
# account address
id: Bytes!
# totalRealizedPnl
realizedPnl: BigInt!
# numberOfUnwinds of the account
numberOfUnwinds: BigInt!
# numberOfLiquidatedPositions
numberOfLiquidatedPositions: BigInt!
# numberOfOpenPositions
numberOfOpenPositions: BigInt!
planckCatBalance: BigInt! # number of PlanckCat NFTs owned
ovlVolumeTraded: BigInt! # total OVL volume traded historically
# derived account info
positions: [Position!]! @derivedFrom(field: "owner")
builds: [Build!]! @derivedFrom(field: "owner")
unwinds: [Unwind!]! @derivedFrom(field: "owner")
liquidates: [Liquidate!]! @derivedFrom(field: "owner")
stakingPositions: [StakingPosition!]! @derivedFrom(field: "owner")
referralPositions: [ReferralPosition!]! @derivedFrom(field: "owner")
tradingMiningEpochVolumes: [TradingMiningEpochVolume!]! @derivedFrom(field: "trader")
tokens: [TokenPosition!]! @derivedFrom(field: "owner")
nfts: [ERC721NFT!]! @derivedFrom(field: "owner")
erc1155Tokens: [ERC1155TokenBalance!]! @derivedFrom(field: "owner")
}
type TokenTransfer @entity(immutable: true) {
# The `transactionIndex` is the index of the transaction in the block.
# The `logIndex` is the index of the log in the block logs.
id: Bytes! # tx hash + log index
token: ERC20Token!
from: Bytes!
to: Bytes!
amount: BigInt!
transaction: Transaction!
}
type TokenPosition @entity {
id: Bytes! # token + owner addresses
token: ERC20Token!
owner: Account! # address
balance: BigInt!
}
type ERC20Token @entity {
id: Bytes! # address
totalSupply: BigInt!
name: String!
symbol: String!
# derived fields
totalSupplyHourData: [TotalSupplyHourData!]! @derivedFrom(field: "token")
}
type RewardsClaimed @entity(immutable: true) {
id: Bytes!
staker: Bytes! # address
stakingPosition: StakingPosition!
rewardAmount: BigInt! # uint256
blockNumber: BigInt!
blockTimestamp: BigInt!
transactionHash: Bytes!
}
type TokensStaked @entity(immutable: true) {
id: Bytes!
staker: Bytes! # address
stakingPosition: StakingPosition!
amount: BigInt! # uint256
blockNumber: BigInt!
blockTimestamp: BigInt!
transactionHash: Bytes!
}
type TokensWithdrawn @entity(immutable: true) {
id: Bytes!
staker: Bytes! # address
stakingPosition: StakingPosition!
amount: BigInt! # uint256
blockNumber: BigInt!
blockTimestamp: BigInt!
transactionHash: Bytes!
}
type StakingPosition @entity {
id: Bytes! # pool + owner addresses
pool: Staking!
owner: Account! # address
stakedBalance: BigInt! # amount currently staked
totalRewardsClaimed: BigInt! # historical rewards claimed
tokensStaked: [TokensStaked!]! @derivedFrom(field: "stakingPosition")
tokensWithdrawn: [TokensWithdrawn!]! @derivedFrom(field: "stakingPosition")
rewardsClaimed: [RewardsClaimed!]! @derivedFrom(field: "stakingPosition")
}
type Staking @entity {
id: Bytes! # address
rewardToken: Bytes! # address
stakingToken: Bytes! # address
timeUnit: BigInt!
rewardsBalance: BigInt!
stakedBalance: BigInt!
totalRewardsClaimed: BigInt!
totalStaked: BigInt!
rewardRatioNumerator: BigInt!
rewardRatioDenominator: BigInt!
stakingPositions: [StakingPosition!]! @derivedFrom(field: "pool")
}
type ERC721Transfer @entity(immutable: true) {
id: Bytes! # tx hash + log index
nft: ERC721NFT!
from: Account!
to: Account!
transaction: Transaction!
}
type ERC721NFT @entity {
id: Bytes! # contract address + tokenId
contract: ERC721Token! # address
tokenId: BigInt!
tokenUri: String!
owner: Account! # address
}
type ERC721Token @entity {
id: Bytes! # address
name: String!
symbol: String!
totalSupply: BigInt!
}
type ReferralProgram @entity {
id: Bytes! # address
rewardToken: Bytes! # address
affiliateComission: [BigInt!]! # bps
traderDiscount: [BigInt!]! # bps
# creation timestamp
createdAtTimestamp: BigInt!
# creation block number
createdAtBlockNumber: BigInt!
# last modification transaction
latestUpdateTransaction: Transaction!
# totalRewards
totalRewards: BigInt!
totalAirdropped: BigInt!
referralPositions: [ReferralPosition!]! @derivedFrom(field: "referralProgram")
}
type ReferralPosition @entity {
id: Bytes! # referral address + owner addresses
referralProgram: ReferralProgram!
owner: Account! # address
tier: Int!
affiliatedTo: Account
totalAffiliateComission: BigInt!
totalTraderDiscount: BigInt!
totalAirdroppedAmount: BigInt!
totalRewardsPending: BigInt!
accountsReferred: Int!
}
type TradingMining @entity {
id: Bytes! # address
totalRewards: BigInt!
rewardToken1: Bytes! # address
rewardToken2: Bytes! # address
token1Percentage: Int!
startTime: BigInt!
epochDuration: BigInt!
pcdHolderBonusPercentage: Int!
maxRewardPerEpochPerAddress: BigInt!
}
type TradingMiningEpoch @entity {
id: Bytes! # address + epoch
epoch: BigInt!
totalVolume: BigInt!
totalRewards: BigInt!
token1Percentage: Int!
}
type TradingMiningEpochVolume @entity {
id: Bytes! # trading mining address + trader address + epoch
epoch: BigInt!
volume: BigInt!
trader: Account!
}
type TotalSupplyHourData @entity {
# token address concatendated with date
id: Bytes!
# unix timestamp for start of hour
periodStartUnix: Int!
# pointer to token
token: ERC20Token!
minted: BigInt!
burnt: BigInt!
open: BigInt!
high: BigInt!
low: BigInt!
close: BigInt!
}
type MarketHourData @entity {
# market address concatendated with date
id: Bytes!
# unix timestamp for start of hour
periodStartUnix: Int!
# pointer to market
market: Market!
minted: BigInt!
burnt: BigInt!
# positive means net minting | negative means net burning
totalMint: BigInt!
# positive means net minting | negative means net burning
accumulatedTotalMint: BigInt!
volume: BigInt!
oiLong: BigInt!
oiShort: BigInt!
fundingRate: BigInt!
}
type ERC1155TokenBalance @entity {
id: Bytes! # contract address + tokenId + owner
owner: Account!
token: ERC1155Token!
amount: BigInt!
burnt: BigInt!
}
type ERC1155Token @entity {
id: Bytes! # contract address + tokenId
address: String!
tokenId: BigInt!
totalSupply: BigInt!
totalBurnt: BigInt!
tokenUri: String!
}
type ERC1155Transfer @entity {
id: Bytes! # transaction hash + log index + index of transaction in a batch
token: ERC1155Token!
from: Account!
to: Account!
amount: BigInt!
transaction: Transaction!
}