Query editor
WITH fees_raw AS (SELECTDATE_TRUNC('day', block_time) AS day,CAST(bytearray_to_uint256(bytearray_substring(data, 129, 32)) AS DOUBLE) -CAST(bytearray_to_uint256(bytearray_substring(data, 161, 32)) AS DOUBLE) AS swap_fee_tokens,0 AS margin_fee_usdFROM base.logsWHERE contract_address = 0xbc2DC9feB0a8202eE4e3B908f55549684bf1C4e8AND topic0 = 0x0874b2d545cb271cdbda4e093020c452328b24af12382ed62c4d00f5c26709dbUNION ALLSELECTDATE_TRUNC('day', block_time) AS day,0 AS swap_fee_tokens,bytearray_to_uint256(bytearray_substring(data, 33, 32)) / 1e30 AS margin_fee_usdFROM base.logsWHERE contract_address = 0xbc2DC9feB0a8202eE4e3B908f55549684bf1C4e8AND topic0 = 0x5d0c0019d3d45fadeb74eff9d2c9924d146d000ac6bcf3c28bf0ac3c9baa011a)SELECTday,SUM(swap_fee_tokens) / 1e18 * 2050 AS swap_fees_usd,SUM(margin_fee_usd) AS margin_fees_usd,SUM(swap_fee_tokens) / 1e18 * 2050 +SUM(margin_fee_usd) AS total_fees_usd,SUM(SUM(swap_fee_tokens) / 1e18 * 2050 + SUM(margin_fee_usd)) OVER (ORDER BY day) AS cumulative_fees_usdFROM fees_rawGROUP BY 1ORDER BY 1 DESC