-
Notifications
You must be signed in to change notification settings - Fork 16
/
substreams.yaml
348 lines (315 loc) · 10.9 KB
/
substreams.yaml
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
specVersion: v0.1.0
package:
name: uniswap_v3
version: v0.2.11
url: https://github.com/streamingfast/substreams-uniswap-v3
image: ./sf_substreams_uniswap.jpeg
description: This is a full-blown replica of the Uniswap-v3 subgraph, by the Uniswap team, but completely rewritten in Rust, yet much faster.
imports:
entity: https://github.com/streamingfast/substreams-entity-change/releases/download/v1.1.0/substreams-entity-change-v1.1.0.spkg
protobuf:
files:
- uniswap/v1/uniswap.proto
importPaths:
- ./proto
excludePaths:
- sf/substreams
- google
binaries:
default:
type: wasm/rust-v1
file: target/wasm32-unknown-unknown/release/substreams_uniswap_v3.wasm
# build: cargo build --release --target wasm32-unknown-unknown
network: mainnet
modules:
- name: map_pools_created
kind: map
initialBlock: 12369621
inputs:
- source: sf.ethereum.type.v2.Block
output:
type: proto:uniswap.types.v1.Pools
doc: |
This module will loop over block transactions and detect pools created events.
Once the pool created events have been detected, `Pools` structs will be emitted out of the module.
Try with
```
substreams gui substreams.yaml map_pools_created -t +1000
```
- name: store_pools_created
kind: store
updatePolicy: set
valueType: proto:uniswap.types.v1.Pool
inputs:
- map: map_pools_created
doc: |
This module stores the Pools emitted by the `map_pools_created` module.
Dynamic data sources pattern for Uniswap v3 pools.
- name: store_tokens
kind: store
updatePolicy: add
valueType: int64
inputs:
- map: map_pools_created
doc: |
`Int64` store accumulator for each time a token is used for any combination for a pool.
- name: store_pool_count
kind: store
updatePolicy: add
valueType: bigint
inputs:
- map: map_pools_created
doc: |
`BigInt` store accumulator for each time a pool is created.
- name: map_tokens_whitelist_pools
kind: map
initialBlock: 12369621
inputs:
- map: map_pools_created
output:
type: proto:uniswap.types.v1.ERC20Tokens
doc: |
This modules loops over the pools created and emits `ERC20Tokens` structs out of the module.
Tokens part of the pair of a pool are checked against the `WHITELIST_TOKENS` constant to see
if they are part of the list. If so push the address of the pool in the field `whitelist_pools`
of the token.
Try with
```
substreams gui substreams.yaml map_tokens_whitelist_pools -t +1000
```
- name: store_tokens_whitelist_pools
kind: store
updatePolicy: append
valueType: string
inputs:
- map: map_tokens_whitelist_pools
doc: |
`String` appender store which stores the `whitelist_pools` field of a token.
- name: map_extract_data_types
kind: map
initialBlock: 12369621
inputs:
- source: sf.ethereum.type.v2.Block
- store: store_pools_created
output:
type: proto:uniswap.types.v1.Events
doc: |
Chunky module which emits multiple types of `Events`. Looping over every transaction to filter out `Events`.
For some events, we have to loop over `StorageChanges` to be able to fetch certain changes such as liquidity
increases and decreases.
For more information on what the `Event` contains, check proto/uniswap/v1/uniswap.proto.
Try with
```
substreams gui substreams.yaml map_extract_data_types -t +1000
```
- name: store_pool_sqrt_price
kind: store
updatePolicy: set
valueType: proto:uniswap.types.v1.Events.PoolSqrtPrice
inputs:
- map: map_extract_data_types
doc: |
Store setter for `PoolSqrtPrice` emitted out of the `map_extract_data_types`.
- name: store_prices
kind: store
updatePolicy: set
initialBlock: 12369621
valueType: bigdecimal
inputs:
- source: sf.substreams.v1.Clock
- map: map_extract_data_types
- store: store_pools_created
doc: |
`BigDecimal` store setter for storing the price of token0 <> token1 and vice versa.
Also store the Daily and Hourly prices.
For example: Pool: TOKEN0 <> TOKEN1
- pool:{pool_address}:{token0_addr}:token0 -> 100
- pool:{pool_address}:{token1_addr}:token1 -> 1
This means that the price of TOKEN0 is 100 for 1 TOKEN1
- name: store_pool_liquidities
kind: store
updatePolicy: set
initialBlock: 12369621
valueType: bigint
inputs:
- source: sf.substreams.v1.Clock
- map: map_extract_data_types
doc: |
`BigInt` store setter for storing pool liquidites which were extracted from `map_extract_data_types`.
- name: store_total_tx_counts
kind: store
updatePolicy: add
valueType: bigint
inputs:
- source: sf.substreams.v1.Clock
- map: map_extract_data_types
doc: |
`BigInt` accumulator store for the total transaction counts for pools, tokens, factory,
daily factory, daily and hourly for token and pool data.
- name: store_swaps_volume
kind: store
updatePolicy: add
valueType: bigdecimal
inputs:
- source: sf.substreams.v1.Clock
- map: map_extract_data_types
- store: store_pools_created
- store: store_total_tx_counts
- store: store_eth_prices
doc: |
`BigDecimal` accumulator store for the swap volume of various entries such as `amount0_abs`, `amount1_abs`,
`volume_usd`, `volume_usd_untracked`, `volume_eth`, `fee_usd` and `fee_eth`. The `_0` and `_1` entries
are the value of one token for another token.
- name: store_native_amounts
kind: store
updatePolicy: set
valueType: bigdecimal
inputs:
- map: map_extract_data_types
doc: |
`BigDecimal` setter store for the native amounts out of any `Event` type: `Mint`, `Swap` and `Burn` amounts
(amount0 and amount1).
- name: store_eth_prices
kind: store
updatePolicy: set
initialBlock: 12369621
valueType: bigdecimal
inputs:
- source: sf.substreams.v1.Clock
- map: map_extract_data_types
- store: store_pools_created
- store: store_prices
- store: store_tokens_whitelist_pools
- store: store_native_amounts
- store: store_pool_liquidities
doc: |
`BigDecimal` setter store for the `eth_price`. This module uses a multiple stores and `map_extract_data_types` to find the `eth_price`
of any given token. If a pool contains a token which has a pair with a _well-known_ token, the `eth_price` is easily found.
Stores the USD price of ETH.
For example:
- Pool: DAI <> WBTC -> we check if there is a pool with DAI <> ETH and easily derive the price
- Pool: ANYTOKEN0 <> DAI -> we can derive the price by finding the pool DAI <> ETH
- Pool: ANYTOKEN0 <> ANYTOKEN1 -> more complicated case where we have to check on either side of the pool
and try to find a path to reach a `whitelisted_token` which has a pool with ETH to be able to derive the price
- name: store_token_tvl
kind: store
initialBlock: 12369621
updatePolicy: add
valueType: bigdecimal
inputs:
- map: map_extract_data_types
doc: |
`BigDecimal` accumulator store for the `total_value_locked` for tokens.
- name: store_derived_tvl
kind: store
initialBlock: 12369621
updatePolicy: set
valueType: bigdecimal
inputs:
- source: sf.substreams.v1.Clock
- map: map_extract_data_types
- store: store_token_tvl
- store: store_pools_created
- store: store_eth_prices
doc: |
`BigDecimal` accumulator store for the derived `total_value_locked` in `USD`, `ETH`, `USDUntracked` and `ETHUntracked` for
pools and tokens.
- name: store_derived_factory_tvl
kind: store
initialBlock: 12369621
updatePolicy: add
valueType: bigdecimal
inputs:
- source: sf.substreams.v1.Clock
- store: store_derived_tvl
mode: deltas
doc: |
`BigDecimal` accumulator store for the derived `total_value_locked` in `USD`, `ETH`, `USDUntracked` and `ETHUntracked` for the factory.
- name: store_ticks_liquidities
kind: store
updatePolicy: add
valueType: bigint
inputs:
- source: sf.substreams.v1.Clock
- map: map_extract_data_types
doc: |
`BigInt` accumulator store for the liquidities of the pools. Tracking `liquidityGross` and `liquidityNet` for pool values at all times,
daily and hourly for `Mint` and `Burn` events.
- name: store_positions
kind: store
updatePolicy: set
valueType: proto:uniswap.types.v1.Events.PositionEvent
inputs:
- map: map_extract_data_types
doc: |
`PositionEvent` setter store for `Position` Events emitted out of `map_extract_data_types`. `CreatedPosition`, `IncreaseLiquidityPosition`,
`DecreaseLiquidityPosition`, `CollectPosition` and `TransferPosition` are stored.
- name: store_min_windows
kind: store
updatePolicy: min
valueType: bigdecimal
inputs:
- source: sf.substreams.v1.Clock
- store: store_prices
mode: deltas
- store: store_eth_prices
mode: deltas
doc: |
`BigDecimal` minimum store for the price of `eth` and token prices for `open` and `low` for daily and hourly.
- name: store_max_windows
kind: store
updatePolicy: max
valueType: bigdecimal
inputs:
- source: sf.substreams.v1.Clock
- store: store_prices
mode: deltas
- store: store_eth_prices
mode: deltas
doc: |
`BigDecimal` maximum store for the price of `eth` and token prices for `open` and `low` for daily and hourly.
- name: graph_out
kind: map
initialBlock: 12369621
inputs:
- source: sf.substreams.v1.Clock
- store: store_pool_count
mode: deltas
- store: store_total_tx_counts
mode: deltas
- store: store_swaps_volume
mode: deltas
- store: store_derived_factory_tvl
mode: deltas
- store: store_eth_prices
mode: deltas
- map: map_extract_data_types
- map: map_pools_created
- store: store_pool_sqrt_price
mode: deltas
- store: store_pool_sqrt_price
- store: store_pool_liquidities
mode: deltas
- store: store_token_tvl
mode: deltas
- store: store_prices
mode: deltas
- store: store_prices
- store: store_tokens
- store: store_tokens_whitelist_pools
mode: deltas
- store: store_derived_tvl
mode: deltas
- store: store_ticks_liquidities
mode: deltas
- store: store_total_tx_counts
- store: store_eth_prices
- store: store_positions
- store: store_min_windows
mode: deltas
- store: store_max_windows
mode: deltas
output:
type: proto:sf.substreams.entity.v1.EntityChanges
doc: |
`EntityChanges` emitted out for all the entities defined in the `schema.graphql` for the Uniswap v3 Subgraph.