Query editor
WITH redeemed AS (SELECTBYTEARRAY_SUBSTRING(topic1, 13, 20) AS wallet,VARBINARY_TO_UINT256(data) / 1e18 AS amount,block_time AS timestamp,'reward' AS evt_typeFROM ethereum.logsWHEREcontract_address = 0x70236b36f86ab4bd557fe9934e1246537b472918AND topic0 = 0xe2403640ba68fed3a2f88b7557551d1993f84b99bb10ff833f0cf8db0c5e0486),staked AS (SELECTBYTEARRAY_SUBSTRING(topic1, 13, 20) AS wallet,VARBINARY_TO_UINT256(data) / 1e18 AS amount,block_time AS timestamp,'stake' AS evt_typeFROM ethereum.logsWHEREcontract_address = 0x70236b36f86ab4bd557fe9934e1246537b472918AND topic0 = 0x5dac0c1b1112564a045ba943c9d50270893e8e826c49be8e7073adc713ab7bd7),ctx_price AS (-- raw daily pricesSELECTday,priceFROM prices.usd_dailyWHERE symbol = 'CTX'),price_filled AS (-- build a set of all days on which you have an event,-- join the raw price (which may be NULL for some days),-- then forward-fill the last seen non-NULL priceSELECTd.day,LAST_VALUE(cp.price)IGNORE NULLSOVER (ORDER BY d.dayROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS priceFROM (SELECT DISTINCT DATE_TRUNC('day', timestamp) AS dayFROM (SELECT timestamp FROM redeemedUNION ALLSELECT timestamp FROM staked) ev) dLEFT JOIN ctx_price cpON d.day = cp.day),events AS (SELECTe.wallet,e.timestamp,DATE_TRUNC('day', e.timestamp) AS day,e.evt_type,e.amount,