Query editor
/*──────────────────────────────────────────────────────────────Dogwallets – Conteo & Volumen por address (VERSIÓN FINAL CORREGIDA)──────────────────────────────────────────────────────────────*/WITH/* 1 ▸ Parámetros */params AS (SELECTDATE '2025-05-26' AS date_start,DATE '2025-07-25' AS date_end,current_date - INTERVAL '7' DAY AS px_start,current_date + INTERVAL '1' DAY AS px_end,'GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN' AS usdc_issuer),/* 2 ▸ Eventos desde la vista materializada */raw_events AS (SELECT *FROM dune.dogstar.result_whales_war_operationsWHERE event_day BETWEEN (SELECT date_start FROM params) AND (SELECT date_end FROM params)),/* 3 ▸ Activos permitidos */allowed_assets AS (SELECT DISTINCT asset_code, asset_issuerFROM query_5034222UNION ALLSELECT 'XLM', NULL),/* 4 ▸ Eventos filtrados por activo */filtered_events AS (SELECT ev.*FROM raw_events evJOIN allowed_assets al ON ev.asset_code = al.asset_code AND COALESCE(ev.asset_issuer,'') = COALESCE(al.asset_issuer,'')),/* ──────────────────── PRECIOS ──────────────────── *//* 5 ▸ VWAP XLM-USDC */xlm_price AS (SELECTSUM(CASE WHEN ht.selling_asset_type='native' THEN ht.buying_amount ELSE ht.selling_amount END)/ NULLIF(SUM(CASE WHEN ht.selling_asset_type='native' THEN ht.selling_amount ELSE ht.buying_amount END), 0) AS pxFROM stellar.history_trades htJOIN params p ON TRUEWHERE ht.closed_at BETWEEN p.px_start AND p.px_endAND ((ht.selling_asset_type='native' AND ht.buying_asset_code='USDC' AND ht.buying_asset_issuer=p.usdc_issuer)OR (ht.buying_asset_type='native' AND ht.selling_asset_code='USDC' AND ht.selling_asset_issuer=p.usdc_issuer))AND ht.buying_amount >= 10 AND ht.selling_amount >= 0.1),/* 6 ▸ VWAP directos TOKEN-USDC */direct_trades AS (SELECTCASE WHEN ht.buying_asset_code='USDC' THEN ht.selling_asset_code ELSE ht.buying_asset_code END AS asset_code,CASE WHEN ht.buying_asset_code='USDC' THEN ht.selling_asset_issuer ELSE ht.buying_asset_issuer END AS asset_issuer,CASE WHEN ht.buying_asset_code='USDC' THEN ht.buying_amount ELSE ht.selling_amount END AS usdc_qty,CASE WHEN ht.buying_asset_code='USDC' THEN ht.selling_amount ELSE ht.buying_amount END AS token_qty