Query editor
WITH vault_transactions AS (-- Combine deposits and withdrawals to track share price over timeSELECTevt_block_time,contract_address,sender,owner,assets,shares,evt_tx_hash,evt_block_number,'deposit' AS transaction_typeFROM curve_lend_ethereum.Vault_evt_DepositWHERE evt_block_time >= NOW() - INTERVAL '730' DAYAND shares > 0AND assets > 0UNION ALLSELECTevt_block_time,contract_address,sender,receiver AS owner,assets,shares,evt_tx_hash,evt_block_number,'withdraw' AS transaction_typeFROM curve_lend_ethereum.Vault_evt_WithdrawWHERE evt_block_time >= NOW() - INTERVAL '730' DAYAND shares > 0AND assets > 0),share_price_samples AS (-- Calculate the price per share for each transactionSELECTevt_block_time,contract_address,assets,shares,CAST(assets AS DOUBLE) / CAST(shares AS DOUBLE) AS price_per_share,transaction_type,evt_tx_hashFROM vault_transactionsWHERE shares > 0),daily_share_prices AS (-- Get daily average share prices for each vaultSELECTDATE_TRUNC('day', evt_block_time) AS day,contract_address,AVG(price_per_share) AS avg_price_per_share,COUNT(*) AS num_transactions,-- Also get the last price of the day for more accurate daily snapshotsMAX(evt_block_time) AS last_event_timeFROM share_price_samplesGROUP BY 1, 2),lagged_prices AS (