0xHaM-dMatic Swap
    Updated 2023-01-30
    WITH matic as (
    SELECT
    date_trunc('day', block_timestamp) as date,
    sum(CASE WHEN symbol_in LIKE 'MATIC' then amount_in END)*-1 sell_token_vol,
    sum(CASE WHEN symbol_out LIKE 'MATIC' then amount_out END) buy_token_vol,
    sum(CASE
    WHEN symbol_in LIKE 'MATIC' then -1 * amount_in
    WHEN symbol_out LIKE 'MATIC' then amount_out
    END) as token_net_vol,
    count(DISTINCT (CASE WHEN symbol_in LIKE 'MATIC' or symbol_out LIKE 'MATIC' THEN tx_hash END)) as token_swap_tx,
    sum(sell_token_vol) over (order by date) as cum_sell_token_vol,
    sum(buy_token_vol) over (order by date) as cum_buy_token_vol,
    sum(token_net_vol) over (order by date) as cum_token_net_vol,
    sum(token_swap_tx) over (order by date) as cum_token_swap_tx
    FROM ethereum.core.ez_dex_swaps
    where block_timestamp::date >= CURRENT_DATE - INTERVAL '{{Past_Months}} MONTH'
    AND block_timestamp::date <= CURRENT_DATE - 1
    GROUP by 1

    UNION

    select
    date_trunc('day', block_timestamp) as date,
    sum(CASE WHEN origin_from_address = EVENT_INPUTS:from then EVENT_INPUTS:value/1e18 END)*-1 sell_token_vol,
    sum(CASE WHEN origin_from_address = EVENT_INPUTS:to then EVENT_INPUTS:value/1e18 END) buy_token_vol,
    sum(CASE
    WHEN origin_from_address = EVENT_INPUTS:from then -1 * (EVENT_INPUTS:value/1e18)
    WHEN origin_from_address = EVENT_INPUTS:to then (EVENT_INPUTS:value/1e18)
    END) as token_net_vol,
    count(DISTINCT tx_hash) as token_swap_tx,
    sum(sell_token_vol) over (order by date) as cum_sell_token_vol,
    sum(buy_token_vol) over (order by date) as cum_buy_token_vol,
    sum(token_net_vol) over (order by date) as cum_token_net_vol,
    sum(token_swap_tx) over (order by date) as cum_token_swap_tx
    from polygon.core.fact_event_logs
    where event_name = 'Swap'
    Run a query to Download Data