SniperShare weekly number of swaps by token
    Updated 2023-05-19
    with
    prices as (
    select
    RECORDED_HOUR::date as date,
    id,
    token,
    avg(close) as avg_price
    from
    flow.core.fact_hourly_prices
    where
    RECORDED_HOUR::date >= CURRENT_DATE - {{Last_days}}
    group by 1,2,3
    ),
    token_swap as (
    SELECT
    block_timestamp::date as date,
    token,
    tx_id,
    TRADER as user,
    TOKEN_out_AMOUNT as amount_in,
    TOKEN_out_AMOUNT * avg_price volume_out,
    TOKEN_in_AMOUNT as amount_in,
    TOKEN_in_AMOUNT * avg_price as volume_in
    from
    flow.core.ez_swaps a
    join flow.core.dim_swap_pool_labels b on a.SWAP_CONTRACT = b.SWAP_CONTRACT
    join prices c on c.date = a.BLOCK_TIMESTAMP::date
    and c.id = a.TOKEN_in_CONTRACT
    where
    BLOCK_TIMESTAMP::date >= current_date - {{Last_days}}
    )
    SELECT
    token,
    trunc(date,'week') as weekly,
    count(DISTINCT tx_id) as swaps,
    Run a query to Download Data