Updated 2023-05-16Copy Reference Fork
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
›
⌄
WITH new_users AS (
SELECT
MIN(a.block_timestamp) AS min_date,
a.origin_from_address AS new_user
FROM ethereum.core.ez_dex_swaps AS a
WHERE a.platform LIKE 'uniswap%'
AND a.amount_in_usd > 0
GROUP BY new_user
),
eth_price AS (
SELECT
DATE_TRUNC('day', a.hour) AS date,
AVG(a.price) AS price_usd
FROM ethereum.core.fact_hourly_token_prices AS a
WHERE a.symbol = 'WETH'
GROUP BY 1
),
statistics AS (
SELECT
date_trunc('month', d.min_date) as month,
COUNT(DISTINCT a.origin_from_address) AS users,
COUNT(DISTINCT a.tx_hash) AS txs,
SUM(txs) OVER (ORDER BY month ASC) AS cumulative_n_txs,
SUM(a.amount_in_usd) AS volumes,
SUM(volumes) OVER (ORDER BY month ASC) AS cumulative_volumes,
SUM(b.tx_fee * c.price_usd) AS total_fees,
SUM(total_fees) OVER (ORDER BY month ASC) AS cumulative_fees
FROM
ethereum.core.ez_dex_swaps AS a
JOIN ethereum.core.fact_transactions AS b ON a.tx_hash = b.tx_hash
JOIN eth_price AS c ON DATE_TRUNC('day', a.block_timestamp) = c.date
JOIN new_users AS d ON a.origin_from_address = d.new_user
WHERE
a.platform LIKE 'uniswap%'
Run a query to Download Data