siavashjBTC Fees $ Yearly copy copy
    Updated 2023-07-25
    with btc_prices as (
    select
    date_trunc('month',hour) as b_day,
    avg(price) as b_price
    from ethereum.core.fact_hourly_token_prices
    where symbol = 'WBTC'
    and date_trunc('month',hour) >= '2010-01-01'
    group by 1
    ),
    prices as (
    select
    date_trunc('year',b_day) as days,
    b_price
    from btc_prices
    ),
    inputs as (
    select
    date_trunc('year',block_timestamp) as date,
    count(distinct tx_id) as "Input TXs",
    count(distinct user) as "Input User",
    sum(value) as "Input Amount BTC"
    from (
    select
    i.block_timestamp,
    i.tx_id,
    outputs[0]:scriptPubKey:address as user,
    value
    from bitcoin.core.fact_inputs i join bitcoin.core.fact_transactions t
    on i.tx_id = t.tx_id
    where i.block_timestamp >= '2010-01-01'
    ) --join prices on days = date_trunc('year',block_timestamp)
    where date_trunc('year',block_timestamp) >= '2010-01-01'
    group by 1
    ),
    outputs as (
    select
    Run a query to Download Data