Query editor
WITH markets AS(SELECT fixedProductMarketMaker, conditionIdsFROM polymarketfactory_polygon.FixedProductMarketMakerFactory_evt_FixedProductMarketMakerCreationWHERE collateralToken = 0x2791bca1f2de4661ed88a30c99a7a9449aa84174),summary AS (SELECT date_trunc('month', block_time) AS date,question_title,sum(usd) AS vol_usdFROM(SELECT block_time,question_title,bytearray_to_uint256(substr(DATA, 1, 32)) / 1e6 AS usdFROM polygon.logs logsLEFT JOIN markets mkt ON logs.contract_address = mkt.fixedProductMarketMakerLEFT JOIN dune.cryptokoryo_research.result_polymarket_all_questions questions ON questions.conditionid = mkt.conditionIds[1]WHERE topic0 in (0x4f62630f51608fc8a7603a9391a5101e58bd7c276139366fc107dc3b67c3dcf8, 0xadcf2a240ed9300d681d9a3f5382b6c1beed1b7e46643e0c7b42cbe6e2d766b4)AND logs.block_number >= 4023680UNION ALL SELECT evt_block_time,question_title,CASEWHEN makerAssetId = 0 THEN makerAmountFilledWHEN takerAssetId = 0 THEN takerAmountFilledEND / 1e6FROM polymarket_polygon.CTFExchange_evt_OrderFilled CTFELEFT JOIN markets mkt ON CTFE.contract_address = mkt.fixedProductMarketMakerLEFT JOIN dune.cryptokoryo_research.result_polymarket_all_questions questions ON questions.conditionid = mkt.conditionIds[1]UNION ALL SELECT evt_block_time,question_title,CASEWHEN makerAssetId = 0 THEN makerAmountFilledWHEN takerAssetId = 0 THEN takerAmountFilledEND / 1e6FROM polymarket_polygon.NegRiskCtfExchange_evt_OrderFilled NegRiskLEFT JOIN markets mkt ON NegRisk.contract_address = mkt.fixedProductMarketMakerLEFT JOIN dune.cryptokoryo_research.result_polymarket_all_questions questions ON questions.conditionid = mkt.conditionIds[1]) aGROUP BY 1,2ORDER BY 1)SELECTdate,CASEWHEN LOWER(question_title) LIKE '%presidential%'OR LOWER(question_title) LIKE '%democratic%'OR LOWER(question_title) LIKE '%republican%'OR LOWER(question_title) LIKE '%democrat%'OR LOWER(question_title) LIKE '%biden%'OR LOWER(question_title) LIKE '%trump%'OR LOWER(question_title) LIKE '%obama%'OR LOWER(question_title) LIKE '%kamala%'THEN 'Election Bets' ELSE 'Non-Election Bets'END AS Elections,vol_usd,SUM(vol_usd) OVER(PARTITION BY question_title ORDER BY date ) AS cumulative_usdFROMsummary