Query editor
WITH mrkt_config AS (SELECTLOWER('0:2E5AE99EC1F98602A3FF9A7712C5173E97C407D2893CAD65CCDC0924A59DA97B') AS mrkt_address,LOWER('0:0000000000000000000000000000000000000000000000000000000000000000') AS native_ton_address_string,9 AS ton_decimals),latest_ton_price_usd_cte AS (SELECTCOALESCE(tpd.price_usd * POW(10, (SELECT ton_decimals FROM mrkt_config)), 0.0) AS price_per_whole_tonFROM ton.prices_daily tpdWHERE LOWER(tpd.token_address) = (SELECT native_ton_address_string FROM mrkt_config)ORDER BY tpd.timestamp DESCLIMIT 1),native_ton_outflows_data AS (SELECTdestination,value / POW(10, (SELECT ton_decimals FROM mrkt_config)) AS amount_tonFROM ton.messagesWHERE LOWER(source) = (SELECT mrkt_address FROM mrkt_config)AND value > 0AND direction = 'out'AND destination IS NOT NULLAND LOWER(source) != LOWER(destination)),aggregated_ton_outflow_stats AS (SELECTCOALESCE(SUM(amount_ton), 0) AS total_ton_sent_volume,COALESCE(COUNT(*), 0) AS total_outflow_tx_count,COALESCE(COUNT(DISTINCT destination), 0) AS unique_recipient_countFROM native_ton_outflows_data)SELECTROUND(COALESCE(ats.total_ton_sent_volume, 0) * COALESCE((SELECT price_per_whole_ton FROM latest_ton_price_usd_cte), 0), 2) AS "Total Value (USD)",ROUND(COALESCE(ats.total_ton_sent_volume, 0), 2) AS "Total Value (TON)",COALESCE(ats.unique_recipient_count, 0) AS "Unique Recipients",COALESCE(ats.total_outflow_tx_count, 0) AS "Total Transactions",ROUND(COALESCE(ats.total_ton_sent_volume, 0) /NULLIF(COALESCE(ats.unique_recipient_count, 0), 0), 2) AS "Avg. TON per Recipient",ROUND((COALESCE(ats.total_ton_sent_volume, 0) * COALESCE((SELECT price_per_whole_ton FROM latest_ton_price_usd_cte), 0)) /NULLIF(COALESCE(ats.unique_recipient_count, 0), 0), 2) AS "Avg. USD per Recipient"FROM aggregated_ton_outflow_stats ats;