Query editor
-- Hard gate for the Tycho call-provenance switchover (Dune query 7993122).-- Atomic conservation is evaluated with UINT256 arithmetic; no DOUBLE cast is-- permitted in this query.WITH all_facts AS (SELECTrouter_call_key,chain,economic_amount_in_atomic,economic_input_statusFROM dune.propeller_heads.result_tycho_router_call_fact_v3_live),facts AS (SELECT router_call_key, chain, economic_amount_in_atomicFROM all_factsWHERE economic_input_status LIKE 'verified_%'OR economic_input_status LIKE 'excluded_source_proven_%'),provenance AS (SELECTrouter_call_key,external_atomic,recycled_atomic,unresolved_atomicFROM dune.propeller_heads.dataset_tycho_call_provenance),missing_fact_rows AS (SELECT f.router_call_key, f.chainFROM facts fLEFT JOIN provenance pON p.router_call_key = f.router_call_keyWHERE p.router_call_key IS NULL),missing_fact_chains AS (SELECT chain, COUNT(*) AS missing_countFROM missing_fact_rowsGROUP BY 1),duplicate_provenance_keys AS (SELECT router_call_keyFROM provenanceGROUP BY 1HAVING COUNT(*) > 1)SELECT(SELECT COUNT(*)FROM missing_fact_rows) AS facts_missing_provenance,(SELECT COUNT(*)FROM provenance pLEFT JOIN all_facts fON f.router_call_key = p.router_call_key