-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathschema-common.graphql
213 lines (182 loc) · 5.96 KB
/
schema-common.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
enum Blockchain {
ETHEREUM
BSC
XDAI
POLYGON
OPTIMISM
AVALANCHE
NEAR
}
enum TokenStandard {
ERC20
ERC721
ERC1155
}
enum ProtocolName {
UNISWAP_V2
}
enum ProtocolType {
STAKING
LENDING
EXCHANGE
INSURANCE
STABLECOIN
DERIVATIVE
SYNTHETIC_TOKEN
TOKEN_MANAGEMENT # Meta LP vaults
PREDICTION_MARKET
}
enum PositionType {
INVESTMENT
DEBT
}
enum TransactionType {
INVEST
REDEEM
BORROW
REPAY
TRANSFER_IN
TRANSFER_OUT
}
type Account @entity {
id: ID! # {accountAddress}
positions: [Position!]! @derivedFrom(field: "account")
}
type Token @entity {
id: ID! # {tokenAddress}
tokenStandard: TokenStandard!
name: String
symbol: String
decimals: Int
mintedByMarket: Market
blockNumber: BigInt! # could be block at which we got first event on this token
timestamp: BigInt!
}
type Market @entity {
id: ID! # {protocol pair/pool/vault address}
account: Account!
protocolName: ProtocolName!
protocolType: ProtocolType!
# Generally protocols accept one or multiple tokens and mint tokens to the depositor to track ownership
# Some protocols reward DAO tokens or other incentivisation tokens to holders of LP tokens
# Some protocols don't mint any tokens to track ownership, in that case outputToken is null
# and inputToken balances are used to calculate returns
inputTokens: [Token!]! # Tokens that need to be deposited to take a position in protocol
outputToken: Token # Token that is minted to track ownership of position in protocol
rewardTokens: [Token!] # Aditional tokens that are given as reward for position in a protocol
inputTokenTotalBalances: [String!]! # Total balance of this market contract of all input tokens in TokenBalance string format
outputTokenTotalSupply: BigInt! # Total supply of output token
blockNumber: BigInt!
timestamp: BigInt!
positions: [Position!]! @derivedFrom(field: "market")
history: [MarketSnapshot!]! @derivedFrom(field: "market")
}
type MarketSnapshot @entity {
id: ID! # {trasactionHash}{logIndex}
market: Market!
inputTokenBalances: [String!]! # TokenBalance string format
outputTokenTotalSupply: BigInt!
blockNumber: BigInt!
timestamp: BigInt!
transactionHash: String!
transactionIndexInBlock: BigInt!
logIndex: BigInt!
}
type Transaction @entity {
id: ID! # {account}{transactionHash}{logIndex}
transactionHash: Bytes!
market: Market!
marketSnapshot: MarketSnapshot!
# A transaction.from is always transaction origin because outside EVM transaction.origin and msg.sender are same
from: Account!
to: Account
# token amounts will always be positive here, Their credit or debit status will change based on transaction type
transactionType: TransactionType!
inputTokenAmounts: [String!]!
outputTokenAmount: BigInt!
rewardTokenAmounts: [String!]!
transferredFrom: String
transferredTo: String
gasUsed: BigInt!
gasPrice: BigInt!
blockNumber: BigInt!
timestamp: BigInt!
transactionIndexInBlock: BigInt!
}
# String format for a TokenBalance
# tokenAddress|accountAddress|tokenAmountBigInt
# It is required because we want to keep track of closed positions as well
# We can not use same ID for a user's new position after existing one has been closed
# To be able to fetch current open position for a user + market + position type we need
# ID to be dependent on only these three things. There three things will be same for all positions
# of a specific user in specfic market therefore we need this AccountPosition entity
type AccountPosition @entity {
id: ID! # {userAddress}{marketAddress}{positionType}
positionCounter: BigInt!
positions: [Position!]! @derivedFrom(field: "accountPosition")
}
# We can not keep balances and roi updated all the time.
# We can update these only when the account of the position makes some changes in the position
# at others time when market variables are changing because of other's actions then we won't update these
type Position @entity {
id: ID! # {accountPositionId}{autoIncrement}
accountPosition: AccountPosition!
account: Account!
accountAddress: String!
market: Market!
marketAddress: String!
positionType: PositionType!
outputTokenBalance: BigInt!
inputTokenBalances: [String!]! # TokenBalance string format
rewardTokenBalances: [String!]! # TokenBalance string format
closed: Boolean!
blockNumber: BigInt!
timestamp: BigInt!
historyCounter: BigInt!
history: [PositionSnapshot!]! @derivedFrom(field: "position")
}
# Created before every update (transaction) to Position
type PositionSnapshot @entity {
id: ID! # {positionId}{autoIncrement}
position: Position!
transaction: Transaction!
outputTokenBalance: BigInt!
inputTokenBalances: [String!]! # TokenBalance string format
rewardTokenBalances: [String!]! # TokenBalance string format
}
type MarketDayData @entity {
" marketAddress + dayId "
id: ID!
" first trade of the day timestamp "
timestamp: BigInt!
" market id - pair address "
market: String!
"amount of input tokens swapped in "
inputTokensDailySwapInVolume: [String!]!
" amount of input tokens swapped out "
inputTokensDailySwapOutVolume: [String!]!
" total amount of reserves per input token "
inputTokenTotalBalances: [String!]!
" reserve amount per input token this day "
inputTokenDailyInflow: [String!]!
" reserve amount per input token this day "
inputTokenDailyOutflow: [String!]!
" total balance of LP tokens "
outputTokenTotalBalance: BigInt!
" amount of LP tokens minted this day "
outputTokenDailyInflowVolume: BigInt!
" amount of LP tokens burned this day "
outputTokenDailyOutflowVolume: BigInt!
" fee in base points, applied to swap-in amount, taken by protocol "
protocolFee: BigInt!
" amount of fees generated this day, per token "
feesGenerated: [String!]!
" number of TXs this day swap "
dailySwapTXs: BigInt!
" number of TXs this day mint "
dailyMintTXs: BigInt!
" number of TXs this day burn "
dailyBurnTXs: BigInt!
" dayId - timestamp/86400 "
dayId: BigInt!
}