Query editor
/*This query returns the hourly stETH to ETH rate for the last 30 daysBase assumption: We determine the stETH:ETH rate primarily using the main stETH:ETH Curve pool because most of protocols built their Price Oracles based on this pool.Details of calculation:1. To calculate the stETH:ETH exchange rate, we get both ETH to stETH (sold_id = 0) and stETH to ETH (sold_id = 1) swap events in the pool (curvefi_ethereum.steth_swap_evt_TokenExchange)2. We compile events-data on a hour-by-hour basis, summing up the swap amounts3. We calculate "ETH amount" to "stETH amount" ratio (it's important to ensure that the stETH amount is non-zero)*/with exchanges AS (-- subquery with ETH->stETH swapsSELECTdate_trunc('hour', evt_block_time) AS time,CASE WHEN sold_id = int256 '0' THEN CAST("tokens_bought" as double)WHEN sold_id = int256 '1' THEN CAST("tokens_sold" as double)END AS steth_amount,CASE WHEN sold_id = int256 '0' THEN CAST("tokens_sold" as double)WHEN sold_id = int256 '1' THEN CAST("tokens_bought" as double)END AS eth_amountFROM curvefi_ethereum.steth_swap_evt_TokenExchange)SELECTtime,sum(steth_amount)/1e18 as steth_amount,sum(eth_amount) / sum(steth_amount) AS ratefrom exchangesWHERE steth_amount > 2 --filter to remove txns with minor quantities with screwed rateand time >= now() - interval '30' dayGROUP BY 1ORDER BY 1 DESC