Afonso_Diaz2023-04-13 03:18 PM
    Updated 2023-04-14
    with t as (
    select
    recorded_hour::date as date,
    currency,
    symbol,
    avg(price) as price_usd
    from osmosis.core.ez_prices
    group by 1, 2, 3
    ),

    t2 as (
    select
    block_timestamp,
    symbol,
    tx_id,
    trader as swapper,
    (from_amount / pow(10, from_decimal)) * price_usd as amount_usd
    from osmosis.core.fact_swaps a
    join t on date = block_timestamp::date and t.currency = a.from_currency
    where block_timestamp > current_date - {{ days }}
    and tx_succeeded = 1
    ),

    t3 as (
    select
    symbol,
    count(distinct tx_id) as swaps,
    count(distinct swapper) as swappers,
    sum(amount_usd) as volume_usd
    from t2
    group by 1
    order by 4 desc
    limit 10
    ),

    t4 as (
    Run a query to Download Data