jackguyTop 100 Dex Users by Swaps
Updated 2023-05-05
99
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
›
⌄
SELECT --*,
-- date_trunc('week', block_timestamp) as week,
ORIGIN_FROM_ADDRESS as user,
count(DISTINCT date_trunc('week', block_timestamp)) as active_weeks,
--count(DISTINCT ORIGIN_FROM_ADDRESS) as users,
sum(
CASE
when not amount_in_usd is NULL then amount_in_usd
when not amount_out_usd is NULL then amount_out_usd
--when token_price1 is NULL then token_price2 * TOKEN_OUT
--else token_price1 * TOKEN_IN end as tt
else 0 end
) as volume_usd,
count(DISTINCT tx_hash) as events
FROM avalanche.core.ez_dex_swaps
LEFT outer join (
SELECT
date_trunc('day', hour) as day1,
token_address as ta1,
median(price) as token_price1
FROM avalanche.core.fact_hourly_token_prices
GROUP BY 1,2
) as a on day1 = date_trunc('day', block_timestamp)
and ta1 = TOKEN_IN
LEFT outer join (
SELECT
date_trunc('day', hour) as day2,
token_address as ta2,
median(price) as token_price2
FROM avalanche.core.fact_hourly_token_prices
GROUP BY 1,2
) as b on day2 = date_trunc('day', block_timestamp)
and ta2 = TOKEN_OUT
WHERE block_timestamp BETWEEN '{{ start_day }}' AND '{{ end_day }}'
--and CASE when token_price1 is NULL then token_price2 * TOKEN_OUT
-- else token_price1 * TOKEN_IN end < 1000000000
Run a query to Download Data