Query editor
-- Compound Ethereum all-vault incident monitor-- Scope: Ethereum mainnet Compound v2 cTokens + v3 Comets with decoded market tables.-- Purpose: quick exploit/drain triage across ETH-chain Compound vaults.WITHparams AS (SELECTCURRENT_TIMESTAMP AS run_time,CURRENT_DATE - INTERVAL '1' DAY AS d1,CURRENT_DATE - INTERVAL '7' DAY AS d7,CURRENT_DATE - INTERVAL '90' DAY AS d90),underlying_map AS (SELECT contract_address, max_by(output_0, call_block_time) AS underlyingFROM compound_v2_ethereum.cerc20_call_underlyingWHERE call_successGROUP BY 1),comp_zero AS (SELECTevt_block_time AS block_time,evt_tx_hash AS tx_hash,CASEWHEN "from" = 0x0000000000000000000000000000000000000000 THEN 'COMP_MINT_FROM_ZERO'WHEN "to" = 0x0000000000000000000000000000000000000000 THEN 'COMP_BURN_TO_ZERO'END AS event_type,amount / 1e18 AS amount_normFROM compound_v2_ethereum.comp_evt_transfer, paramsWHERE evt_block_date >= d90AND ("from" = 0x0000000000000000000000000000000000000000 OR "to" = 0x0000000000000000000000000000000000000000)),v3_base_out AS (SELECT 'v3_cUSDC_base_withdraw' AS family, evt_block_time AS block_time, evt_tx_hash AS tx_hash, contract_address AS market, 'USDC' AS asset_symbol, amount / 1e6 AS amount_norm, src AS actor, "to" AS to_addrFROM compound_v3_ethereum.cusdcv3_evt_withdraw, params WHERE evt_block_date >= d1UNION ALLSELECT 'v3_cUSDT_base_withdraw', evt_block_time, evt_tx_hash, contract_address, 'USDT', amount / 1e6, src, "to"FROM compound_v3_ethereum.cusdtv3_evt_withdraw, params WHERE evt_block_date >= d1UNION ALLSELECT 'v3_cUSDS_base_withdraw', evt_block_time, evt_tx_hash, contract_address, 'USDS', amount / 1e18, src, "to"FROM compound_v3_ethereum.cusdsv3_evt_withdraw, params WHERE evt_block_date >= d1UNION ALLSELECT 'v3_cWETH_base_withdraw', evt_block_time, evt_tx_hash, contract_address, 'WETH', amount / 1e18, src, "to"FROM compound_v3_ethereum.cwethv3_evt_withdraw, params WHERE evt_block_date >= d1),v3_collateral_out AS (SELECT 'v3_cUSDC_collateral_withdraw' AS family, e.evt_block_time AS block_time, e.evt_tx_hash AS tx_hash, e.contract_address AS market, COALESCE(t.symbol, 'UNKNOWN') AS asset_symbol, e.amount / pow(10, COALESCE(t.decimals, 18)) AS amount_norm, e.src AS actor, e."to" AS to_addrFROM compound_v3_ethereum.cusdcv3_evt_withdrawcollateral eLEFT JOIN tokens.erc20 t ON t.blockchain='ethereum' AND t.contract_address=e.assetCROSS JOIN params WHERE e.evt_block_date >= d1UNION ALLSELECT 'v3_cUSDT_collateral_withdraw', e.evt_block_time, e.evt_tx_hash, e.contract_address, COALESCE(t.symbol, 'UNKNOWN'), e.amount / pow(10, COALESCE(t.decimals, 18)), e.src, e."to"FROM compound_v3_ethereum.cusdtv3_evt_withdrawcollateral eLEFT JOIN tokens.erc20 t ON t.blockchain='ethereum' AND t.contract_address=e.assetCROSS JOIN params WHERE e.evt_block_date >= d1UNION ALLSELECT 'v3_cUSDS_collateral_withdraw', e.evt_block_time, e.evt_tx_hash, e.contract_address, COALESCE(t.symbol, 'UNKNOWN'), e.amount / pow(10, COALESCE(t.decimals, 18)), e.src, e."to"FROM compound_v3_ethereum.cusdsv3_evt_withdrawcollateral e