Query editor
-- cngn_flow_analysis_cngn_volume_monthly.sql-- Monthly cNGN Token Flow Analysis (Buys vs Sells in cNGN Quantity)WITH cngn_addresses AS (SELECT LOWER('0x7923C0f6FA3d1BA6EAFCAedAaD93e737Fd22FC4F') as addr UNION ALL -- Asset ChainSELECT LOWER('0x52828daa48C1a9A06F37500882b42daf0bE04C3B') UNION ALL -- PolygonSELECT LOWER('0x46C85152bFe9f96829aA94755D9f915F9B10EF5F') UNION ALL -- BaseSELECT LOWER('0xa8AEA66B361a8d53e8865c62D142167Af28Af058') UNION ALL -- BNBSELECT LOWER('0x17CDB2a01e7a34CbB3DD4b83260B05d0274C8dab') -- Eth)SELECTDATE_TRUNC('month', block_time) AS month,-- Inflow (Buys): User Bought cNGN (Received cNGN)ROUND(SUM(CASE WHEN LOWER(TRIM(token_out_address)) IN (SELECT addr FROM cngn_addresses) THEN cngn_amount ELSE 0 END), 2) AS buys_cngn,-- Outflow (Sells): User Sold cNGN (Negative, User Sent cNGN)ROUND(-SUM(CASE WHEN LOWER(TRIM(token_in_address)) IN (SELECT addr FROM cngn_addresses) THEN cngn_amount ELSE 0 END), 2) AS sells_cngn,-- Net Flow (Buys - Sells)ROUND(SUM(CASEWHEN LOWER(TRIM(token_out_address)) IN (SELECT addr FROM cngn_addresses) THEN cngn_amountWHEN LOWER(TRIM(token_in_address)) IN (SELECT addr FROM cngn_addresses) THEN -cngn_amountELSE 0END), 2) AS net_flow_cngnFROM dune.lavavc_team_2642.result_c_ngn_unified_dex_trading_history_all_chainGROUP BY 1ORDER BY 1 ASC;