AlexayUntitled Query1
    Updated 2022-08-25
    -- sql https://app.flipsidecrypto.com/velocity/queries/9436e24d-edc2-45d9-8ad1-96f78b9ccb3b
    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 >= CURRENT_DATE - 30*2
    ),
    stables AS (
    SELECT
    address,
    label,
    address_name
    FROM solana.core.dim_labels WHERE label_subtype = 'token_contract' and address_name LIKE '%usd%'
    ),
    prices as (
    SELECT
    date(block_timestamp) as date,
    swap_from_mint as 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 price_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
    Run a query to Download Data