Moeosmosis - swap distribution
    Updated 2024-03-05

    with price_tb as (select
    RECORDED_HOUR::date as day,
    CURRENCY,
    avg (price) as price
    from osmosis.price.ez_prices
    group by 1,2)
    , swap_table as (
    select
    s.*,
    p1.price * FROM_AMOUNT / pow(10, from_decimal) as FROM_AMOUNT_USD
    from
    osmosis.defi.fact_swaps s
    left join price_tb p1 on p1.day = block_timestamp :: date
    and p1.CURRENCY = from_currency

    where
    block_timestamp >= current_date - 90
    and s.from_decimal is not NULL
    and s.from_decimal>0

    )
    ,
    base as (
    select
    tx_id,
    sum(FROM_AMOUNT_USD) as swap_amt
    from
    swap_table
    where
    FROM_AMOUNT_USD is not null
    group by
    1
    having
    swap_amt > 0
    QueryRunArchived: QueryRun has been archived