Query editor
WITH bids_raw AS (SELECTdate_trunc('hour', block_time) AS bid_hour,tx_from AS bidder,bytearray_to_uint256(bytearray_substring(data, 1, 32)) * 0.0001 AS price_usd,bytearray_to_uint256(bytearray_substring(data, 33, 32)) / 1e6 AS amount_usdFROM ethereum.logsWHERE contract_address = 0x73612914c81a9c072333ea9ea71a9b26a5b9a707AND topic0 = 0x4245c7a8a9dec532f85f6d48e5fa48bdedafddbb8ccc0f28ef9b3b2f00aefed4AND bytearray_to_uint256(bytearray_substring(data, 33, 32)) / 1e6 >= 100),bids AS (SELECTbid_hour,bidder,price_usd,amount_usd,amount_usd / NULLIF(price_usd, 0) AS tokens_allocatedFROM bids_raw),hours AS (SELECT DISTINCT bid_hour AS hourFROM bids),/* ---------- Capital-weighted FDV ---------- */hourly_weighted_fdv AS (SELECTbid_hour AS hour,(SUM(amount_usd) / SUM(tokens_allocated)) * 1e10 AS capital_weighted_fdvFROM bidsGROUP BY bid_hour),bids_expanded AS (SELECTh.hour AS clearing_hour,b.price_usd,b.amount_usdFROM hours hJOIN bids bON b.bid_hour <= h.hour),marginal_fdv AS (SELECTclearing_hour AS hour,MAX(price_usd) * 1e10 AS marginal_fdvFROM (SELECTclearing_hour,price_usd,SUM(amount_usd) OVER (PARTITION BY clearing_hourORDER BY price_usd DESCROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS cumulative_usdFROM bids_expanded