Query editor
-- Vesting History + Forecast - by Donor, weekly, historic prices-- Each donation first appears at its full amount, valued at the price on the day it landed in the vesting contract.-- After that, each week shows the tokens still vesting at the end of that week, valued at that week's average price.-- Future weeks use the latest weekly price. Small donors are grouped into Other.WITH weeks AS (SELECTwk,wk + INTERVAL '6' DAY AS obs -- end of week: streams starting during the week are includedFROM UNNEST(SEQUENCE(date_trunc('week', date('2022-05-01')), date_trunc('week', current_date + INTERVAL '1460' DAY), INTERVAL '7' DAY)) AS t(wk)),prices_weekly AS (SELECTblockchain,contract_address,date_trunc('week', timestamp) AS wk,AVG(price) AS priceFROM prices.dayWHERE timestamp >= date('2022-04-25')AND (source = 'coinpaprika'OR volume >= 50000OR contract_address IN (0x50614cc8e44f7814549c223aa31db9296e58057c, -- ALIGN0xa27ec0006e59f245217ff08cd52a7e8b169e62d2 -- AZTEC))GROUP BY 1, 2, 3),priced_tokens AS (SELECT DISTINCT blockchain, contract_address FROM prices_weekly),-- streams grouped by donor bucket, token and landing day; tokens that never had an eligible price are dropped (they were worth $0)-- donations still waiting for a stream (landed in the last 30 days, no vest_start yet) are forecast as if their stream starts today;-- older donations that were never streamed (airdropped junk tokens) are left outstreams AS (SELECTCASE WHEN v.donor_name IN ('Ether.fi Foundation', 'LayerZero Foundation', 'Eigen Foundation', 'Uniswap DAO', 'Aztec Foundation', 'Nouns DAO', 'Moloch DAO', 'ENS DAO', 'Lido DAO', 'Taiko Labs', 'Octant / Golem Foundation', 'Aligned Layer', 'Arbitrum Community', 'Starknet Foundation', 'Puffer') THEN v.donor_name ELSE 'Other' END AS donor,v.blockchain,v.token_contract,CAST(v.donation_time AS DATE) AS donation_date,COALESCE(CAST(v.vest_start AS DATE), current_date) AS vest_start,COALESCE(CAST(v.vest_end AS DATE), current_date + CAST(v.vest_duration AS INTEGER) * INTERVAL '1' DAY) AS vest_end,v.vest_duration,SUM(v.quantity) AS quantityFROM dune.protocolguild.result_vesting_streams__main vINNER JOIN priced_tokens pON p.blockchain = v.blockchainAND p.contract_address = v.token_contractWHERE (v.vest_start IS NOT NULL OR v.donation_time >= current_date - INTERVAL '30' DAY)AND v.token_contract NOT IN (0x68725d45a960c100e082dd14ec82c9d83c2240a6, -- ALPHA (valued at $0 in Individual Donations 6364630)0x21283fece254bfb7c48c22bdc1a1db7ad0e162e7 -- GLAMDOG (valued at $0 in Individual Donations 6364630))GROUP BY 1, 2, 3, 4, 5, 6, 7),-- daily price on the day each donation landed, for its first data point