hmxinternFees over time
    Updated 2024-09-16
    with trading_fees_log as (
    select date_trunc('day', block_timestamp) as time,
    sum(case
    when EVENT_NAME = 'LogSettleTradingFeeAmount' then DECODED_LOG['feeUsd']
    when EVENT_NAME = 'LogSettleBorrowingFeeValue' then DECODED_LOG['feeUsd']
    when EVENT_NAME = 'LogSettleLiquidationFeeValue' then DECODED_LOG['usd']
    end) / pow(10, 30) as usd,
    case
    when EVENT_NAME = 'LogSettleTradingFeeAmount' then 'tradingFees'
    when EVENT_NAME = 'LogSettleBorrowingFeeValue' then 'BorrowingFees'
    when EVENT_NAME = 'LogSettleLiquidationFeeValue' then 'LiquidationFees'
    end as type
    from blast.core.fact_decoded_event_logs
    where CONTRACT_ADDRESS = lower('0x9F1f13eBC178122C3ef6c14FA3A523680563F58b')
    and EVENT_NAME in (
    'LogSettleTradingFeeAmount',
    'LogSettleBorrowingFeeValue',
    'LogSettleLiquidationFeeValue'
    )
    group by 1, 3
    ),
    hlp_fees as (
    select date_trunc('day', block_timestamp) as time,
    sum(decoded_log['feeUsd']) / pow(10, 30) as usd,
    'HlpFees' as type,
    from blast.core.fact_decoded_event_logs
    where contract_address = lower('0xF0D92907236418Fa8Ee900E384b4c6928f7cADfc')
    and event_name in ('CollectAddLiquidityFee', 'CollectRemoveLiquidityFee')
    group by 1, 3
    )

    select *, avg("Total fees") over (order by time ROWS BETWEEN 6 PRECEDING AND CURRENT ROW) as "7 days avg."
    from (
    select time,
    sum(iff(type = 'tradingFees', usd, 0)) as "Trading fees",
    sum(iff(type = 'BorrowingFees', usd, 0)) as "Borrowing fees",
    QueryRunArchived: QueryRun has been archived