Deebs-DeFi-j9fRbzSUM ETH Custom
    Updated 2023-06-14
    -- 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