Query editor
WITH thorchain_swap_data AS (SELECTtx_id,block_timestamp,from_amount_usd,COALESCE(affiliate_fee_basis_points,affiliate_fee_basis_points_array[array_position(affiliate_addresses_array, 'g1')]) AS affiliate_fee_bp,from_asset NOT LIKE '%RUNE%' AS from_is_externalFROM thorchain.defi_swapsWHERE (affiliate_address = 'g1' OR contains(affiliate_addresses_array, 'g1'))AND block_timestamp >= DATE '2024-01-01'),thorchain_tx_summary AS (SELECTtx_id,MIN(block_timestamp) AS block_timestamp,SUM(CASE WHEN from_is_external THEN from_amount_usd ELSE 0 END) AS total_volume_usd,SUM(CASE WHEN from_is_externalTHEN from_amount_usd * affiliate_fee_bp / 10000ELSE 0END) AS total_revenue_usdFROM thorchain_swap_dataGROUP BY tx_id)SELECTDATE_TRUNC('day', block_timestamp) AS day,'thorchain' AS chain,'Thorchain' AS sender_label,SUM(total_volume_usd) AS total_volume_usd,SUM(total_revenue_usd) AS total_revenue_usd,COUNT(*) AS unique_swapsFROM thorchain_tx_summaryGROUP BY 1,2,3ORDER BY day DESC;