Query editor
WITH buyers AS (SELECTl.tx_from AS buyer,min(l.block_time) AS first_cash_time,sum(CAST(varbinary_to_uint256(l.data) AS DOUBLE)/1e6) AS usdt_spentFROM arbitrum.logs lWHERE l.block_date>=DATE '2025-04-22' AND l.block_date<DATE '2025-04-30'AND l.block_time>=TIMESTAMP '2025-04-22 21:59:34'AND l.block_time<TIMESTAMP '2025-04-29 21:59:34'AND l.contract_address=0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9AND l.topic0=0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3efAND l.tx_to=0xaf7bb1dd1a64a1c391be5c3fa00710c672690828AND varbinary_substring(l.topic1,13,20)=l.tx_fromAND varbinary_substring(l.topic2,13,20)=0xedf0ef8ea6c13c074babeeaf337775c4fa7ff173GROUP BY 1),prior_usdt_candidates AS (SELECTb.*,varbinary_substring(l.topic1,13,20) AS usdt_funder,l.block_time AS usdt_funding_time,row_number() OVER (PARTITION BY b.buyer ORDER BY l.block_number DESC,l.index DESC) AS rnFROM buyers bLEFT JOIN arbitrum.logs lON l.block_date>=DATE '2025-03-01' AND l.block_date<DATE '2025-04-30'AND l.contract_address=0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9AND l.topic0=0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3efAND varbinary_substring(l.topic2,13,20)=b.buyerAND l.block_time<b.first_cash_time),joined AS (SELECTp.*,a.first_funded_by AS gas_funder,a.first_funded_at,CASEWHEN p.usdt_funder IS NULL OR a.first_funded_by IS NULL THEN 'one or both sources unknown'WHEN p.usdt_funder=a.first_funded_by THEN 'same parent funded gas + USDT'ELSE 'different gas and USDT sources'END AS source_matchFROM prior_usdt_candidates pLEFT JOIN addresses.stats a ON a.blockchain='arbitrum' AND a.address=p.buyerWHERE p.rn=1),totals AS (SELECT count(*) wallets,sum(usdt_spent) usdt FROM joined),summary AS (SELECT'cohort summary' AS section,source_match AS label,CAST(NULL AS VARCHAR) AS parent_address,count(*) AS wallets,sum(usdt_spent) AS usdt_spentFROM joinedGROUP BY source_match),parent_groups AS (SELECTgas_funder AS parent,count(*) AS wallets,sum(usdt_spent) AS usdt_spent