Query editor
WITH price AS(WITH data AS (SELECTDATE_TRUNC('day', block_time) AS time,CASEWHEN token_bought_address = 0xe29797910D413281d2821D5d9a989262c8121CC2 THEN amount_usd / CAST((token_bought_amount_raw / 1e18) AS DOUBLE)ELSE amount_usd / CAST((token_sold_amount_raw / 1e18) AS DOUBLE)END AS elimu_price_usdFROM dex.tradesWHEREblockchain = 'ethereum'AND token_bought_address = 0xe29797910D413281d2821D5d9a989262c8121CC2OR token_sold_address = 0xe29797910D413281d2821D5d9a989262c8121CC2AND ( token_sold_amount_raw <> CAST(0 as UINT256) AND token_bought_amount_raw <> CAST(0 as UINT256))AND CASEWHEN token_bought_address = 0xe29797910D413281d2821D5d9a989262c8121CC2 THEN token_bought_amount_raw > CAST(100 as UINT256)ELSE token_sold_amount_raw > CAST(100 as UINT256)END /* filter out strange transactions */ORDER BYtime NULLS FIRST)SELECTtime,AVG(elimu_price_usd) AS Price_USDFROM dataWHERE time > CAST('2021-07-01' AS TIMESTAMP)GROUP BY 1ORDER BY 1 NULLS FIRST),elimu_pool_bal AS(SELECT SUM(amount) OVER (ORDER BY day ROWS UNBOUNDED PRECEDING) AS ELIMU, dayFROM(SELECT SUM(amount/1e18) AS amount, dayFROM(SELECTdate_trunc('day', evt_block_time) AS day,CAST(value AS int256) AS amountFROM erc20_ethereum.evt_Transfer trWHERE contract_address = 0xe29797910D413281d2821D5d9a989262c8121CC2AND "to" = 0x0E2a3d127EDf3BF328616E02F1DE47F981Cf496AUNION ALLSELECTdate_trunc('day', evt_block_time) AS day,-1 * CAST(value AS int256) AS amountFROM erc20_ethereum.evt_Transfer trWHERE contract_address = 0xe29797910D413281d2821D5d9a989262c8121CC2AND "from" = 0x0E2a3d127EDf3BF328616E02F1DE47F981Cf496A)GROUP BY day)),weth_pool_bal AS(SELECT SUM(amount) OVER (ORDER BY day ROWS UNBOUNDED PRECEDING) AS weth, dayFROM(SELECT SUM(amount/1e18) AS amount, day