Query editor
WITH prices_data AS (SELECTblockchain,DATE(timestamp) AS day,contract_address,AVG(price) AS priceFROM prices.dayWHERE contract_address IN (0xbf5495efe5db9ce00f80364c8b423567e58d2110, -- ezETH Ethereum0x2416092f143378750bb29b79ed961ab195cceea5, -- ezETH (other chains)0xC02aaa39b223FE8D0A0e5C4F27eAD9083C756Cc2 -- WETH Ethereum)GROUP BY 1, 2, 3),pivoted AS (SELECTday,MAX(CASE WHEN blockchain = 'ethereum' AND contract_address = 0xbf5495efe5db9ce00f80364c8b423567e58d2110 THEN price END) AS ezeth_eth,MAX(CASE WHEN blockchain = 'arbitrum' AND contract_address = 0x2416092f143378750bb29b79ed961ab195cceea5 THEN price END) AS ezeth_arb,MAX(CASE WHEN blockchain = 'base' AND contract_address = 0x2416092f143378750bb29b79ed961ab195cceea5 THEN price END) AS ezeth_base,MAX(CASE WHEN blockchain = 'linea' AND contract_address = 0x2416092f143378750bb29b79ed961ab195cceea5 THEN price END) AS ezeth_linea,MAX(CASE WHEN blockchain = 'taiko' AND contract_address = 0x2416092f143378750bb29b79ed961ab195cceea5 THEN price END) AS ezeth_taiko,MAX(CASE WHEN blockchain = 'uni' AND contract_address = 0x2416092f143378750bb29b79ed961ab195cceea5 THEN price END) AS ezeth_uni,MAX(CASE WHEN blockchain = 'bera' AND contract_address = 0x2416092f143378750bb29b79ed961ab195cceea5 THEN price END) AS ezeth_bera,MAX(CASE WHEN blockchain = 'blast' AND contract_address = 0x2416092f143378750bb29b79ed961ab195cceea5 THEN price END) AS ezeth_blast,MAX(CASE WHEN blockchain = 'optimism' AND contract_address = 0x2416092f143378750bb29b79ed961ab195cceea5 THEN price END) AS ezeth_optimism,MAX(CASE WHEN blockchain = 'ethereum' AND contract_address = 0xC02aaa39b223FE8D0A0e5C4F27eAD9083C756Cc2 THEN price END) AS weth_priceFROM prices_dataGROUP BY day)SELECTday, 'Ethereum' AS chain,ezeth_eth / weth_price AS peg_ratio,(ezeth_eth / weth_price) - 1 AS deviationFROM pivotedWHERE ezeth_eth IS NOT NULLUNION ALLSELECTday, 'Arbitrum' AS chain,ezeth_arb / weth_price AS peg_ratio,(ezeth_arb / weth_price) - 1 AS deviationFROM pivotedWHERE ezeth_arb IS NOT NULLUNION ALLSELECTday, 'Base' AS chain,ezeth_base / weth_price AS peg_ratio,(ezeth_base / weth_price) - 1 AS deviationFROM pivotedWHERE ezeth_base IS NOT NULLUNION ALLSELECTday, 'Linea' AS chain,ezeth_linea / weth_price AS peg_ratio,(ezeth_linea / weth_price) - 1 AS deviationFROM pivotedWHERE ezeth_linea IS NOT NULL