hmxinternvolume query
    Updated 2024-06-06
    with trades as (
    select
    date_trunc('day', block_timestamp) as time, DECODED_LOG['primaryAccount'] as account,
    case
    when EVENT_NAME = 'LogIncreasePosition' then abs(DECODED_LOG['increasedSize'])
    when EVENT_NAME = 'LogDecreasePosition' then abs(DECODED_LOG['decreasedSize'])
    end as vol
    from blast.core.fact_decoded_event_logs
    where CONTRACT_ADDRESS = lower('0x0a8D9c0A4a039dDe3Cb825fF4c2f063f8B54313A')
    and EVENT_NAME in ('LogIncreasePosition', 'LogDecreasePosition')
    ),
    liquidate as (
    select
    date_trunc('day', block_timestamp) as time, DECODED_LOG['account'] as account,
    abs(DECODED_LOG['size']) as vol
    from blast.core.fact_decoded_event_logs
    where CONTRACT_ADDRESS = lower('0x963Cbe4cFcDC58795869be74b80A328b022DE00C')
    and EVENT_NAME = 'LogLiquidationPosition'
    )

    select account,
    sum(iff(datediff('day', time, date_trunc('day', current_timestamp())) <= 7, vol, 0)) / 1e30 as past_1_week,
    sum(iff(datediff('day', time, date_trunc('day', current_timestamp())) <= 14, vol, 0)) / 1e30 as past_2_week,
    sum(iff(datediff('day', time, date_trunc('day', current_timestamp())) <= 21, vol, 0)) / 1e30 as past_3_week,
    sum(iff(datediff('day', time, date_trunc('day', current_timestamp())) <= 28, vol, 0)) / 1e30 as past_4_week
    from (
    select time, account, vol from trades
    union all
    select time, account, vol from liquidate
    )
    group by account
    order by 5 desc,4 desc,3 desc,2 desc

    QueryRunArchived: QueryRun has been archived