flyingfish2023-01-16 04:13 PM
Updated 2023-01-17
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 cte AS (
SELECT
block_timestamp
, origin_from_address
, origin_to_address
, token_in
, symbol_in
, token_out
, symbol_out
, platform
, pool_name
, event_name
, amount_in
, amount_in_usd
, amount_out
, amount_out_usd
, tx_hash
FROM ethereum.core.ez_dex_swaps
WHERE block_timestamp > '2023-01-01'
AND (token_in = lower('{{token_address}}')
OR token_out = lower('{{token_address}}'))
--AND origin_from_address = lower('0x46be62d1fc217063c1bf1f35d788690cec7a60ca')
),
token_balances AS (
SELECT user_address
, balance
FROM ethereum.core.fact_token_balances
WHERE contract_address = lower('{{token_address}}')
AND user_address in (SELECT DISTINCT origin_from_address FROM cte)
qualify(row_number() over (partition by user_address order by block_number desc)) = 1
)
SELECT *
FROM cte
LEFT OUTER JOIN token_balances
on cte.origin_from_address = token_balances.user_address
Run a query to Download Data