Query editor
with staking_transfers as (selectblock_date, block_time, tt.contract_address, "from", "to", amount, casewhen "to" = 0xBe367d410D96E1cAeF68C0632251072CDf1b8250 then 'stake'when "from" = 0xBe367d410D96E1cAeF68C0632251072CDf1b8250 then 'unstake'end as status, casewhen amount_usd is not null then amount_usdelse amount * ph.priceend as amount_usdfrom tokens.transfers ttleft join prices.hour phon ph.contract_address = tt.contract_addressand ph.blockchain = 'somnia'and ph.timestamp = date_trunc('hour', tt.block_time)where tt.blockchain = 'somnia'and ("to" = 0xBe367d410D96E1cAeF68C0632251072CDf1b8250or "from" = 0xBe367d410D96E1cAeF68C0632251072CDf1b8250)), final as (select-- balance (approximated current staked)sum(case when status = 'stake' then amount else 0 end)- sum(case when status = 'unstake' then amount else 0 end) as total_staked_balance, sum(case when status = 'stake' then amount_usd else 0 end)- sum(case when status = 'unstake' then amount_usd else 0 end) as total_staked_balance_usd-- volume, sum(amount) as total_volume, sum(amount_usd) as total_volume_usd, sum(case when status = 'stake' then amount else 0 end) as total_staked, sum(case when status = 'unstake' then amount else 0 end) as total_unstaked-- transactions, count(*) as total_transactions, count(case when status = 'stake' then 1 end) as total_stake_txns, count(case when status = 'unstake' then 1 end) as total_unstake_txns-- wallets, count(distinct case when status = 'stake' then "to"when status = 'unstake' then "from"end) as total_unique_wallets, count(distinct case when status = 'stake' then "to" end) as total_unique_stakers, count(distinct case when status = 'unstake' then "from" end) as total_unique_unstakers-- averages & extremes, avg(case when status = 'stake' then amount end) as avg_stake_amount, avg(case when status = 'unstake' then amount end) as avg_unstake_amount, max(case when status = 'stake' then amount end) as largest_single_stake, max(case when status = 'unstake' then amount end) as largest_single_unstake