Query editor
WITH all_daily AS (SELECTdate_trunc('day', block_time) AS day,COUNT(*) AS num_mints,SUM(amount) AS total_minted_usdxl,COUNT(DISTINCT "to") AS unique_borrowersFROM tokens.transfersWHERE blockchain = 'hyperevm'AND contract_address = 0xca79db4b49f608ef54a5cb813fbed3a6387bc645AND "from" = 0x0000000000000000000000000000000000000000AND block_date >= DATE '2025-01-01'GROUP BY 1),with_cumulative AS (SELECTday,num_mints,total_minted_usdxl,unique_borrowers,SUM(total_minted_usdxl) OVER (ORDER BY day ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS cumulative_minted_usdxlFROM all_daily),cg_range_json AS (SELECT json_parse(http_get(CONCAT('https://api.coingecko.com/api/v3/coins/last-usd/market_chart/range?vs_currency=usd&from=',CAST(CAST(to_unixtime(CURRENT_TIMESTAMP - INTERVAL '90' DAY) AS BIGINT) AS VARCHAR),'&to=',CAST(CAST(to_unixtime(CURRENT_TIMESTAMP + INTERVAL '1' DAY) AS BIGINT) AS VARCHAR)))) AS j),cg_prices_raw AS (SELECTdate_trunc('day', from_unixtime(CAST(json_extract_scalar(pj, '$[0]') AS BIGINT) / 1000)) AS price_day,TRY_CAST(json_extract_scalar(pj, '$[1]') AS DOUBLE) AS price_usdFROM cg_range_jsonCROSS JOIN UNNEST(CAST(json_extract(j, '$.prices') AS ARRAY(JSON))) AS t(pj)WHERE json_extract_scalar(pj, '$[1]') IS NOT NULL),cg_daily AS (SELECTprice_day,AVG(price_usd) AS price_usdFROM cg_prices_rawGROUP BY 1)SELECTc.day,c.num_mints,c.unique_borrowers,ROUND(c.total_minted_usdxl, 2) AS total_minted_usdxl,ROUND(c.total_minted_usdxl * COALESCE(p.price_usd, 1), 2) AS total_minted_usd,ROUND(c.cumulative_minted_usdxl, 2) AS cumulative_minted_usdxl,ROUND(c.cumulative_minted_usdxl * COALESCE(p.price_usd, 1), 2) AS cumulative_minted_usd,ROUND(COALESCE(p.price_usd, 1), 6) AS price_usdFROM with_cumulative cLEFT JOIN cg_daily p ON c.day = p.price_dayWHERE c.day >= CURRENT_DATE - INTERVAL '90' DAYORDER BY c.day DESC