-
Notifications
You must be signed in to change notification settings - Fork 57
/
schema.graphql
242 lines (205 loc) · 12.2 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
# Uniswap global values across all exchanges
type Uniswap @entity {
id: ID!
exchangeCount: Int!
exchanges: [Exchange!]! @derivedFrom(field: "factory")
totalVolumeInEth: BigDecimal!
totalLiquidityInEth: BigDecimal!
totalVolumeUSD: BigDecimal! # Accumulate at each trade, not just calculated off whatever totalVolume is. making it more accurate as it is a live conversion
totalLiquidityUSD: BigDecimal! # Current value of liquidity in USD
totalTokenSells: BigInt! # Total events where tokens have been sold
totalTokenBuys: BigInt! # Total events where tokens have been bought
totalAddLiquidity: BigInt! # Total events where liqidity has been added
totalRemoveLiquidity: BigInt! # Total events where liquidity have been removed
exchangeHistoryEntityCount: BigInt! # Count of all historical entities for exchanges - used for unique ids
uniswapHistoryEntityCount: BigInt! # Count of all historical entities for Uniswap - used for unique ids
txCount: BigInt!
}
type Exchange @entity {
id: ID! # Uniswap Exchange address
tokenAddress: Bytes! # Token address
tokenSymbol: String # Can't always get this, since any contract can be a uniswap contract (no erc20 interface)
tokenName: String # Can't always get this, since any contract can be a uniswap contract (no erc20 interface)
tokenDecimals: Int # Can't always get this, since any contract can be a uniswap contract (no erc20 interface)
fee: BigDecimal! # Always 0.3% for v1 uniswap
version: Int! # V1 only right now
startTime: Int! # Time exchange was created
ethLiquidity: BigDecimal! # Equals the liquidty provided. Will likely be different than ethBalance
tokenLiquidity: BigDecimal! # Equals the token liquidity provided. Will likely be different thatn tokenBalance
ethBalance: BigDecimal! # Equals the ether balance of the contract
tokenBalance: BigDecimal! # Equals the token balance of the contract
combinedBalanceInEth: BigDecimal! # Equal to ethBalance + (tokenBalance/price). Stored to simplify users calculating their own personal return. because the ratio may have changes a lot in one direction
combinedBalanceInUSD: BigDecimal! # Equal to combinedBalanceInUSD * DAI/ETH
totalUniToken: BigDecimal! # Count of the unilying unitokens that represent liquidity provided ownership
# Counting Events
addLiquidityCount: BigInt! # Count the number of times liquidity has been added
removeLiquidityCount: BigInt! # Count the number of times liquidity has been removed
sellTokenCount: BigInt! # Count the number of times the tokens been sold
buyTokenCount: BigInt! # Count the number of times the tokens been bought
# Price values using eth
lastPrice: BigDecimal! # The last trade price
price: BigDecimal! # Price is the total amount of tokens that equal one ETH. i.e. if ETH was 100 USD, price for DAI would be 100
tradeVolumeToken: BigDecimal! # Total tokens traded EVER
tradeVolumeEth: BigDecimal! # Total eth traded EVER
tradeVolumeUSD: BigDecimal! # Total USD traded EVER, accumulated at each trade with current token usd price * amount
totalValue: BigDecimal! # totalValue is accumulation of trade price * trade volume. i.e. TV = tokensSold * priceTokensSold
weightedAvgPrice: BigDecimal! # Avg price of all trades since inception. WAP = totalValue / totalVolume
totalTxsCount: BigInt! # Total tx count EVER
# Price values uing usd
lastPriceUSD: BigDecimal! # The last trade price in USD
priceUSD: BigDecimal! # USD / token
weightedAvgPriceUSD: BigDecimal! # weightAvgPriceUSD = ( $1 of ETH in ETH ) / weightedAvgPrice
# Fields used to help derived relationship
factory: Uniswap
tokenHolders: [UserExchangeData!] # Relationship to show all token holders on the exchange
}
type User @entity {
id: ID! # user eth adddress
exchangeBalances: [UserExchangeData!]! @derivedFrom(field: "user")
}
# trading and liquidity data around a user and their activity on a given exchange
type UserExchangeData @entity {
id: ID! # ID is concatenation of token and user addr. i.e. 0xahiow4-0xkashkd34....
userAddress: Bytes!
user: User!
exchange: Exchange!
# Liquidity Provider Data
ethDeposited: BigDecimal! # where negative means eth was exchanged for tokens
tokensDeposited: BigDecimal! # Where negative means tokens were exchanged for eth
ethWithdrawn: BigDecimal!
tokensWithdrawn: BigDecimal!
uniTokenBalance: BigDecimal!
# Trading Data
# Note - Fee is always charged in what the user is paying with. i.e. you buy eth by paying in token. Fee is in token
# Note - ethBought, ethSold, tokensBought, and tokensSold are effected by a basic Transfer
ethBought: BigDecimal!
ethSold: BigDecimal!
tokensBought: BigDecimal!
tokensSold: BigDecimal!
ethFeesPaid: BigDecimal!
tokenFeesPaid: BigDecimal!
ethFeesInUSD: BigDecimal!
tokenFeesInUSD: BigDecimal!
}
enum EventType {
AddLiquidity,
RemoveLiquidity,
TokenPurchase,
EthPurchase
}
type Transaction @entity {
id: ID! # txn hash concatenated with exchange - need this for token to token swaps
exchangeAddress: Bytes!
addLiquidityEvents: [AddLiquidityEvent!] @derivedFrom(field: "transaction")
removeLiquidityEvents: [RemoveLiquidityEvent!] @derivedFrom(field: "transaction")
tokenPurchaseEvents: [TokenPurchaseEvent!] @derivedFrom(field: "transaction")
ethPurchaseEvents: [EthPurchaseEvent!] @derivedFrom(field: "transaction")
block: Int!
timestamp: Int!
user: Bytes!
fee: BigDecimal!
}
interface TransactionEvent {
id: ID!
transaction: Transaction!
ethAmount: BigDecimal!
tokenAmount: BigDecimal!
}
# Note - No fee to provide liqidity
type AddLiquidityEvent implements TransactionEvent @entity {
id: ID! # Incrementing ID, 1, 2, etc, as txhashes can contain multiple events
transaction: Transaction!
ethAmount: BigDecimal!
tokenAmount: BigDecimal!
uniTokensMinted: BigDecimal!
}
# Note - No fee to provide liqidity
type RemoveLiquidityEvent implements TransactionEvent @entity {
id: ID! # Incrementing ID, 1, 2, etc, as txhashes can contain multiple events
transaction: Transaction!
ethAmount: BigDecimal!
tokenAmount: BigDecimal!
uniTokensBurned: BigDecimal!
}
type TokenPurchaseEvent implements TransactionEvent @entity {
id: ID! # Incrementing ID, 1, 2, etc, as txhashes can contain multiple events
transaction: Transaction!
# Monetary Values. Positive or negative determined by the TradeType
ethAmount: BigDecimal!
tokenAmount: BigDecimal!
tokenFee: BigDecimal!
ethFee: BigDecimal!
}
type EthPurchaseEvent implements TransactionEvent @entity {
id: ID! # Incrementing ID, 1, 2, etc, as txhashes can contain multiple events
transaction: Transaction!
# Monetary Values. Positive or negative determined by the TradeType
ethAmount: BigDecimal!
tokenAmount: BigDecimal!
tokenFee: BigDecimal!
ethFee: BigDecimal!
}
##### Below are entites specifically for uniswap historical data #####
# Historical data for each event of each exchange. Useful for creating graphs and data analysis
type ExchangeHistoricalData @entity {
id: ID!
exchangeAddress: Bytes!
type: EventType!
timestamp: Int!
ethLiquidity: BigDecimal! # Equals the liquidty provided. Will likely be different than ethBalance
tokenLiquidity: BigDecimal! # Equals the token liquidity provided. Will likely be different thatn tokenBalance
ethBalance: BigDecimal! # Equals the ether balance of the contract
tokenBalance: BigDecimal! # Equals the token balance of the contract
combinedBalanceInEth: BigDecimal! # Equal to ethBalance + (tokenBalance/price). Stored to simplify users calculating their own personal return. because the ratio may have changes a lot in one direction
combinedBalanceInUSD: BigDecimal! # Equal to combinedBalanceInUSD * DAI/ETH. USD price at time of transaction
totalUniToken: BigDecimal! # Count of the unilying unitokens that represent liquidity provided ownership
tokenPriceUSD: BigDecimal! # USD / token. USD price at time of transaction
price: BigDecimal! # Price is the total amount of tokens that equal one ETH. i.e. if ETH was 100 USD, price for DAI would be 100
tradeVolumeToken: BigDecimal! # Total tokens traded EVER. i.e. cumulative
tradeVolumeEth: BigDecimal! # Total eth traded EVER. i.e. cumulative
tradeVolumeUSD: BigDecimal! # Total USD traded EVER - cumulative with price at time of trade
totalTxsCount: BigInt! # Total tx count EVER
feeInEth: BigDecimal!
}
# Data accumulated and condensed into day stats for each exchange
type ExchangeDayData @entity {
id: ID! # token address concatenated with unix date (Nov 2nd 2018 is 17837)
date: Int! # starts on 1541116800 (Nov 2nd 2018 00:00:00). all dates must start on 00:00:00
exchangeAddress: Bytes!
ethBalance: BigDecimal! # Eth balance at last event within the day
tokenBalance: BigDecimal! # Token balance at last event within the day
marginalEthRate: BigDecimal! # tokenBalance / ethBalance
ethVolume: BigDecimal! # Cumulative volume throughout the day
tokenPriceUSD: BigDecimal! # USD token price at last event within the day
totalEvents: BigInt!
}
# Data accumulated and condensed into day stats for all of Uniswap
type UniswapDayData @entity {
id: ID! # timestamp rounded to current day by dividing by 86400 - should only be one per day
date: Int!
dailyVolumeInETH: BigDecimal!
dailyVolumeInUSD: BigDecimal!
totalVolumeInEth: BigDecimal! # volume just on eth -i.e. we dont double count volume
totalLiquidityInEth: BigDecimal! # 2 * SUM(exchanges.ethLiquidity). Since tokenLiquiduity = ethLiquidity value, can just *2
totalVolumeUSD: BigDecimal! # Accumulate at each trade, not just calculated off whatever totalVolume is. making it more accurate as it is a live conversion
totalLiquidityUSD: BigDecimal!
totalTokenSells: BigInt! # Total events where tokens have been sold
totalTokenBuys: BigInt! # Total events where tokens have been bought
totalAddLiquidity: BigInt! # Total events where liqidity has been added
totalRemoveLiquidity: BigInt! # Total events where liquidity have been removed
txCount: BigInt!
}
# Data checkpointed at each timestamp for 24hour data
type UniswapHistoricalData @entity {
id: ID! # unique based on incremental entity count, one for each transactions
timestamp: Int!
totalVolumeInEth: BigDecimal! # volume just on eth -i.e. we dont double count volume
totalLiquidityInEth: BigDecimal! # 2 * SUM(exchanges.ethLiquidity). Since tokenLiquiduity = ethLiquidity value, can just *2
totalVolumeUSD: BigDecimal! # Accumulate at each trade, not just calculated off whatever totalVolume is. making it more accurate as it is a live conversion
totalLiquidityUSD: BigDecimal!
totalTokenSells: BigInt! # Total events where tokens have been sold
totalTokenBuys: BigInt! # Total events where tokens have been bought
totalAddLiquidity: BigInt! # Total events where liqidity has been added
totalRemoveLiquidity: BigInt! # Total events where liquidity have been removed
txCount: BigInt!
}