Query editor
-- check_assetchain_implied_rates_multiday_detailed_with_address.sql-- Calculates implied rates per transaction for June 23rd and 24th, 2025.-- Includes full block time, pool address, sorting by time, and both cNGN/USD and USD/cNGN rates.WITH daily_txs AS (SELECTCAST(transaction_hash AS VARCHAR) as transaction_hash,TRY_CAST(cngn_amount AS DOUBLE) as cngn_amt,TRY_CAST(usd_value AS DOUBLE) as usd_val,pool_name,CAST(pool_address AS VARCHAR) as pool_address,-- Extract the date part (YYYY-MM-DD)SUBSTR(CAST(block_time AS VARCHAR), 1, 10) as tx_date,-- Keep the full timestamp string for sorting (YYYY-MM-DD HH:MM)CAST(block_time AS VARCHAR) as full_time_strFROM dune.lavavc.dataset_assetchain_cngn_token_transfersWHERE (block_time LIKE '2025-06-23%' OR block_time LIKE '2025-06-24%')-- Added Strict Pool FilterAND (pool_name LIKE '%USDT%' OR pool_name LIKE '%USDC%'))-- 1. Individual TransactionsSELECTtx_date,full_time_str as exact_time,transaction_hash,pool_name,pool_address,cngn_amt,usd_val,-- Rate 1: cNGN per USDCASE WHEN usd_val > 0 THEN cngn_amt / usd_val ELSE NULL END as rate_cngn_per_usd,-- Rate 2: USD per cNGNCASE WHEN cngn_amt > 0 THEN usd_val / cngn_amt ELSE NULL END as rate_usd_per_cngnFROM daily_txsUNION ALL-- 2. Aggregate Summaries PER DAYSELECTtx_date,CONCAT(tx_date, ' 23:59:59') as exact_time, -- Force to end of day for sortingCONCAT('TOTAL_AGGREGATE_', tx_date) as transaction_hash,'ALL_POOLS' as pool_name, -- Placeholder for pool name column'ALL_POOLS_ADDRESS' as pool_address, -- Placeholder for pool address columnSUM(cngn_amt) as cngn_amt,SUM(usd_val) as usd_val,-- Daily Weighted Average: cNGN per USDSUM(cngn_amt) / NULLIF(SUM(usd_val), 0) as rate_cngn_per_usd,-- Daily Weighted Average: USD per cNGNSUM(usd_val) / NULLIF(SUM(cngn_amt), 0) as rate_usd_per_cngnFROM daily_txsGROUP BY tx_dateORDER BY exact_time DESC;