Deebs-DeFi-j9fRbzSUM ETH Custom
Updated 2023-06-14
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
›
⌄
-- forked from SUM OP Custom @ https://flipsidecrypto.xyz/edit/queries/0fcaa3ee-c1b5-4055-9229-9fc9c085705b
WITH buys AS(
select
CASE
WHEN token_out=lower({{token_address}}) THEN 'BOUGHT'
END AS ACTION,
SUM(amount_out) AS total_bought_sold
from ethereum.core.ez_dex_swaps
WHERE BLOCK_TIMESTAMP BETWEEN {{start_date}} AND {{end_date}}
AND token_out=lower({{token_address}})
group by 1
),
sells AS(
select
CASE
WHEN token_in=lower({{token_address}}) THEN 'SOLD'
END AS ACTION,
SUM(amount_in) AS total_bought_sold
from ethereum.core.ez_dex_swaps
WHERE BLOCK_TIMESTAMP BETWEEN {{start_date}} AND {{end_date}}
AND token_in=lower({{token_address}})
group by 1
)
SELECT
action,
total_bought_sold
FROM buys
UNION ALL
SELECT
action,
total_bought_sold
FROM sells
--LEFT JOIN sells s on b.token_in=s.token_out
Run a query to Download Data