Query editor
WITH date_fill AS (SELECT timestamp AS evt_block_dateFROM utils.daysWHERE timestamp > TIMESTAMP '2024-12-01'AND timestamp < CURRENT_DATE),-- Single CTE combining all operations with conditional aggregationall_operations AS (SELECTevt_block_date,SUM(CASE WHEN operation_type = 'deposit' THEN amount END) AS daily_deposited,SUM(CASE WHEN operation_type = 'delegate' THEN amount END) AS daily_delegated,SUM(CASE WHEN operation_type = 'undelegate' THEN amount END) AS daily_undelegated,SUM(CASE WHEN operation_type = 'undelegate_ready' THEN amount END) AS daily_undelegated_ready,SUM(CASE WHEN operation_type = 'withdraw' THEN amount END) AS daily_withdrawn,SUM(CASE WHEN operation_type = 'rewards' THEN amount END) AS daily_rewards,SUM(CASE WHEN operation_type = 'clawback_initiated' THEN amount END) AS daily_clawback_initiated,SUM(CASE WHEN operation_type = 'clawback_executed' THEN amount END) AS daily_clawback_executedFROM (SELECT evt_block_date, 'deposit' AS operation_type, amountAssets / POWER(10,18) AS amountFROM beethoven_x_sonic.stS_evt_DepositedWHERE evt_block_date > TIMESTAMP '2024-12-01'UNION ALLSELECT evt_block_date, 'delegate' AS operation_type, amountAssets / POWER(10,18) AS amountFROM beethoven_x_sonic.stS_evt_DelegatedWHERE evt_block_date > TIMESTAMP '2024-12-01'UNION ALLSELECT evt_block_date, 'undelegate' AS operation_type, amountAssets / POWER(10,18) AS amountFROM beethoven_x_sonic.stS_evt_UndelegatedWHERE kind = 1 AND evt_block_date > TIMESTAMP '2024-12-01'UNION ALLSELECT evt_block_date, 'undelegate_ready' AS operation_type, amountAssets / POWER(10,18) AS amountFROM beethoven_x_sonic.stS_evt_UndelegatedWHERE kind = 1AND evt_block_date > TIMESTAMP '2024-12-01'AND evt_block_date <= CURRENT_DATE - INTERVAL '14' DAYUNION ALLSELECT evt_block_date, 'withdraw' AS operation_type, amountAssets / POWER(10,18) AS amountFROM beethoven_x_sonic.stS_evt_withdrawnWHERE evt_block_date > TIMESTAMP '2024-12-01'UNION ALLSELECT evt_block_date, 'rewards' AS operation_type, (amountClaimed - protocolFee) / POWER(10,18) AS amountFROM beethoven_x_sonic.stS_evt_RewardsClaimedWHERE evt_block_date > TIMESTAMP '2024-12-01'UNION ALLSELECT evt_block_date, 'clawback_initiated' AS operation_type, amountAssets / POWER(10,18) AS amountFROM beethoven_x_sonic.stS_evt_OperatorClawBackInitiated