Query editor
-- Query 1.B (Corrected contract_cnt and Price Source): view_feem_projects_with_price-- Adds USD price to project data, referencing the materialized view_feem_projects_raw-- Price is derived from wS trades against stablecoins on DEXs.-- Materialize: Every 15 minutesWITH trades_wS_vs_stable AS (SELECTblock_time,amount_usd,CASEWHEN LOWER(token_bought_symbol) = 'ws' THEN token_bought_amountWHEN LOWER(token_sold_symbol) = 'ws' THEN token_sold_amountELSE 0END AS wS_amount,CASEWHEN LOWER(token_bought_symbol) = 'ws' THEN token_sold_symbolWHEN LOWER(token_sold_symbol) = 'ws' THEN token_bought_symbolELSE NULLEND AS stable_coin_symbolFROMdex.tradesWHEREblockchain = 'sonic'AND ((LOWER(token_bought_symbol) = 'ws' AND LOWER(token_sold_symbol) IN ('usdc', 'usdt', 'dai', 'usd+', 'frax', 'usdb')) OR(LOWER(token_sold_symbol) = 'ws' AND LOWER(token_bought_symbol) IN ('usdc', 'usdt', 'dai', 'usd+', 'frax', 'usdb')))AND amount_usd > 0AND token_bought_amount > 0AND token_sold_amount > 0),latest_wS_price AS (SELECT(amount_usd / wS_amount) AS sonic_usdFROMtrades_wS_vs_stableORDER BYblock_time DESCLIMIT 1)SELECTp.project_id,p.name,p.owner_address,p.receiver_address,p.rewards_to_claim_s,p.claimed_rewards_s,p.collected_rewards_s,p.quarter_rewards_s,p.transactions_count,p.is_active,p.contracts_raw_json, -- This is VARCHAR from view_feem_projects_rawp.contract_cnt, -- <<< USING THE contract_cnt DIRECTLY FROM pp.snapshot_ts,COALESCE(lsf.sonic_usd, 0) AS sonic_usd,p.rewards_to_claim_s * COALESCE(lsf.sonic_usd, 0) AS rewards_to_claim_usd,p.claimed_rewards_s * COALESCE(lsf.sonic_usd, 0) AS claimed_rewards_usd,p.collected_rewards_s * COALESCE(lsf.sonic_usd, 0) AS collected_rewards_usd,p.quarter_rewards_s * COALESCE(lsf.sonic_usd, 0) AS quarter_rewards_usdFROM