Query editor
WITHcombined_deposits AS (SELECT 'rysk' AS source, contract_address, recipient, DATE_TRUNC('day', evt_block_time) AS date_day, amount, evt_tx_hashFROM rysk_beyond_arbitrum.liquiditypool_evt_depositUNION ALLSELECT 'lyra' AS source, contract_address, beneficiary AS recipient, DATE_TRUNC('day', evt_block_time) AS date_day, amountDeposited AS amount, evt_tx_hashFROM lyra_newport_arbitrum.LiquidityPool_evt_DepositProcessed),combined_withdraws AS (SELECT 'rysk' AS source, contract_address, recipient, DATE_TRUNC('day', evt_block_time) AS date_day, amount, evt_tx_hashFROM rysk_beyond_arbitrum.liquiditypool_evt_withdrawUNION ALLSELECT 'lyra' AS source, contract_address, beneficiary AS recipient, DATE_TRUNC('day', evt_block_time) AS date_day, amountWithdrawn AS amount, evt_tx_hashFROM lyra_newport_arbitrum.LiquidityPool_evt_WithdrawProcessed),deposit_amounts AS (SELECTsource,CASEWHEN source = 'rysk' THEN SUM(amount) / POWER(10, 6)ELSE SUM(amount) / POWER(10, 18)END AS amount_depositsFROM combined_depositsGROUP BY source),withdraw_amounts AS (SELECTsource,CASEWHEN source = 'rysk' THEN SUM(amount) / POWER(10, 6)ELSE SUM(amount) / POWER(10, 18)END AS amount_withdrawsFROM combined_withdrawsGROUP BY source),source_aggregates AS (SELECT d.source,d.amount_deposits,w.amount_withdraws,d.amount_deposits - w.amount_withdraws AS net_amountFROM deposit_amounts dJOIN withdraw_amounts w ON d.source = w.source),total_aggregates AS (SELECT SUM(amount_deposits) AS total_deposits,SUM(amount_withdraws) AS total_withdraws,SUM(net_amount + (SELECT (total_combined_balance_usd / 2) FROM query_2966770)) AS total_net_amountFROM source_aggregates)(SELECT source, amount_deposits, amount_withdraws, net_amountFROM source_aggregatesUNION ALLSELECT 'Premia',null,null,total_combined_balance_usd FROM query_2966770)UNION ALLSELECT 'total', total_deposits, total_withdraws, total_net_amount FROM total_aggregates