phu48. transfer to hackers
Updated 2022-10-15
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
solana_swaps AS (
SELECT
SWAP_PROGRAM ,BLOCK_TIMESTAMP ,BLOCK_ID ,TX_ID ,SUCCEEDED ,SWAPPER ,
SWAP_FROM_AMOUNT ,
SWAP_FROM_MINT,
a.address_name as from_asset,
SWAP_TO_AMOUNT,
SWAP_TO_MINT,
b.address_name as to_asset,
SWAP_TO_AMOUNT/SWAP_FROM_AMOUNT as ratio
FROM solana.core.fact_swaps
LEFT JOIN solana.core.dim_labels a ON SWAP_FROM_MINT = a.address
LEFT JOIN solana.core.dim_labels b ON SWAP_TO_MINT = b.address
WHERE SUCCEEDED = 'TRUE' AND block_timestamp >= '2022-10-08 21:00:00'
)
, stables AS (
SELECT
address,
label,
address_name
FROM solana.core.dim_labels WHERE label_subtype = 'token_contract' and address_name LIKE '%usd%'
)
, token_price_cte as (
SELECT
date_trunc(hour, block_timestamp) as swap_hour,
swap_from_mint, -- token address
nvl(from_asset,swap_from_mint) as token,
sum(swap_from_amount) as sold, -- tokens sold
sum(swap_to_amount) as stables,
stables/sold as token_swap_price_avg_usd,
median(ratio) as token_swap_price_median_usd
FROM solana_swaps
WHERE swap_to_mint IN (SELECT address FROM stables) --- use receiving as stables
AND swap_to_amount > 10 -- filter out swaps with USD prices that are too low
GROUP BY 1,2,3
Run a query to Download Data