Query editor
WITHaddress AS (SELECTcd.output_token AS token,cd.output_auction AS auction,cd.output_treasury AS treasury,cd.output_governor AS governor,cd.output_metadata AS metadataFROMnouns_builder_ethereum.Manager_call_deploy cdWHEREcd.output_token = {{token address}}),bid_event AS(SELECTbytearray_to_uint256(bytearray_substring(data,1,32)) AS token_id,bytearray_substring(data,1+12+32,20) AS bidder,cast(bytearray_to_uint256(bytearray_substring(data,1+32*2,32)) as decimal)/1e18 AS bid_amountFROM ethereum.logs elWHERE block_number > 15799619AND topic0 = 0x1edd36b28569cf1cf930c008c5bcb196ea19525977951413bec3118946951561AND contract_address = (SELECT auction FROM address)),settle_events AS (SELECTbytearray_to_uint256(bytearray_substring(data,1,32)) AS token_id,bytearray_substring(data,32+13,20) AS winner,cast(bytearray_to_uint256(bytearray_substring(data,1+32*2,32))as decimal) / 1e18 AS settled_amountFROM ethereum.logs elWHERE block_number > 15799619AND topic0 = 0xc9f72b276a388619c6d185d146697036241880c36654b1a3ffdad07c24038d99AND contract_address = (SELECT auction FROM address))SELECT*,AVG(settled_amount) OVER (ORDER BY token_id ROWS BETWEEN 7 PRECEDING AND CURRENT ROW) AS settled_amount_7ma,AVG(settled_amount) OVER (ORDER BY token_id ROWS BETWEEN 30 PRECEDING AND CURRENT ROW) AS settled_amount_30maFROM(SELECTcast(token_id as int) AS token_id,er.name AS winner_ens,winner,settled_amount,COUNT(DISTINCT bidder) AS bidders,COUNT(bid_amount) AS bidsFROM bid_event beFULL OUTER JOIN settle_events se USING(token_id)LEFT JOIN ens.reverse_latest er ON se.winner = er.addressGROUP BY 1,2,3,4)ORDER BY 1 DESC