Query editor
-- select * from aave_gnosis.supply limit 10WITH market_stats AS (-- Calculate TVL (Total Value Locked) per tokenSELECTtoken_address,symbol,SUM(CASE WHEN transaction_type = 'deposit' THEN amount ELSE -amount END) as tvl,SUM(CASE WHEN transaction_type = 'deposit' THEN amount_usd ELSE -amount_usd END) as tvl_usd,COUNT(DISTINCT CASE WHEN transaction_type = 'deposit' THEN depositor END) as unique_depositors,COUNT(DISTINCT CASE WHEN transaction_type = 'withdraw' THEN depositor END) as unique_withdrawers,COUNT(DISTINCT depositor) as total_unique_users,COUNT(CASE WHEN transaction_type = 'deposit' THEN 1 END) as deposit_count,COUNT(CASE WHEN transaction_type = 'withdraw' THEN 1 END) as withdrawal_count,AVG(CASE WHEN transaction_type = 'deposit' THEN amount END) as avg_deposit_size,AVG(CASE WHEN transaction_type = 'withdraw' THEN amount END) as avg_withdrawal_size,MAX(CASE WHEN transaction_type = 'deposit' THEN amount END) as max_deposit,MAX(CASE WHEN transaction_type = 'withdraw' THEN amount END) as max_withdrawal,MIN(block_time) as first_interaction,MAX(block_time) as latest_interactionFROMaave_gnosis.supplyGROUP BYtoken_address, symbol)SELECTsymbol,token_address,tvl,tvl_usd,unique_depositors,unique_withdrawers,total_unique_users,deposit_count,withdrawal_count,avg_deposit_size,avg_withdrawal_size,max_deposit,max_withdrawal,first_interaction,latest_interaction,deposit_count + withdrawal_count as total_transactions,CASE WHEN withdrawal_count > 0 THENROUND(CAST(deposit_count AS DOUBLE) / withdrawal_count, 2)ELSE NULL END as deposit_to_withdrawal_ratioFROMmarket_statsORDER BYtvl_usd DESC