Query editor
-- Active protocol count on HyperEVM without double-counting variants-- latest <= today (ET); aggregates variants into a canonical protocol-- Optional param version:-- WITH prm AS ( SELECT CAST({{threshold_usd}} AS DOUBLE) AS threshold_usd ),-- Hard-coded fallback:WITH prm AS ( SELECT 10000.0 AS threshold_usd ), -- $10k defaulttoday_est AS (SELECT CAST((current_timestamp AT TIME ZONE 'America/New_York') AS DATE) AS today_dt),series AS (SELECTCAST(day AS DATE) AS dt,CAST(tvl_usd AS DOUBLE) AS tvl_usd,protocolFROM dune.ktabes.dataset_total_num_of_hyperevm_defi_protocolsWHERE tvl_usd IS NOT NULL),-- Pick the latest available day up to "today ET"pick_dt AS (SELECT MAX(s.dt) AS dt_pickFROM series sJOIN today_est t ON s.dt <= t.today_dt),-- 1) Normalize slugs (lowercase + strip common “flavor” suffixes)normalized AS (SELECTs.dt,s.tvl_usd,LOWER(TRIM(s.protocol)) AS protocol_slug,-- Remove a single trailing flavor suffix (extend as needed)REGEXP_REPLACE(LOWER(TRIM(s.protocol)),'(?:-(pooled|isolated|perps|spot|amm|dex|vaults|lending|markets|core|v\\d+))$','') AS proto_baseFROM series s),-- 2) Optional manual overrides: declare canonical mappings here-- Add rows as needed: variant_slug -> canon_slugcanon_overrides AS (SELECT * FROM (VALUES('hypurrfi-pooled', 'hypurrfi'),('hypurrfi-isolated', 'hypurrfi')-- ,('example-spot','example')-- ,('example-perps','example')) AS t(variant_slug, canon_slug)),-- 3) Pick canonical slug: override if present, else use normalized basecanonized AS (SELECTn.dt,n.tvl_usd,