Query editor
WITH price_updates AS (SELECTblock_time,CAST(varbinary_to_uint256(varbinary_substring(data, 97, 32)) AS DOUBLE) / 1e18 AS priceFROM arbitrum.logsWHERE contract_address =0x7b31a39550c89194c0fc3f0b8bf1b389a15af36dAND topic0 =0xf94e53f8d9b2a3751616409b5de74a49f1b9b6430e3bae51fbfb0d1725e27196AND block_time >= NOW() - INTERVAL '30' DAY),updates_with_latest_time AS (SELECTblock_time,price,MAX(block_time) OVER () AS latest_price_timeFROM price_updates),price_points AS (SELECTMAX_BY(price, block_time) AS current_price,MAX(block_time) AS current_price_time,COALESCE(MAX_BY(price, block_time) FILTER (WHERE block_time<= latest_price_time - INTERVAL '7' DAY),MIN_BY(price, block_time)) AS reference_price,COALESCE(MAX(block_time) FILTER (WHERE block_time<= latest_price_time - INTERVAL '7' DAY),MIN(block_time)) AS reference_price_timeFROM updates_with_latest_time),calculation AS (SELECT*,DATE_DIFF('second',reference_price_time,current_price_time) / 86400.0 AS actual_daysFROM price_points)