Query editor
with eth_tvl as (SELECT time, contract_address, SUM(amount) as total_amountFROM (SELECT date_trunc('day', evt_block_time) as time, contract_address, CAST(value as DECIMAL(38,0)) as amountFROM erc20_ethereum.evt_TransferWHERE"to" = 0xfa7093cdd9ee6932b4eb2c9e1cde7ce00b1fa4b9UNION ALLSELECT date_trunc('day', evt_block_time) as time, contract_address, -CAST(value as DECIMAL(38,0)) as amountFROM erc20_ethereum.evt_TransferWHERE"from" = 0xfa7093cdd9ee6932b4eb2c9e1cde7ce00b1fa4b9)GROUP BY 1, 2), eth_tv_values as (SELECT eth_tvl.time, tokens.symbol, token_prices.price * (total_amount/POW(10, tokens.decimals)) as token_valueFROM eth_tvl JOIN (select symbol, contract_address, decimalsFROM tokens.erc20 as all_tokensWHERE blockchain = 'ethereum') AS tokens on eth_tvl.contract_address = tokens.contract_addressJOIN (SELECT time, contract_address, AVG(price) as priceFROM (SELECT date_trunc('day', hour) as time, contract_address, (median_price) as priceFROM dex.prices as dex_pricesWHERE blockchain = 'ethereum' and hour >= TIMESTAMP'2022-05-07 00:00'-- UNION ALL-- SELECT date_trunc('day', minute) as time, contract_address, (price) as price-- FROM prices.usd as dex_prices-- WHERE blockchain = 'ethereum' and minute >= TIMESTAMP'2022-01-01 00:00')GROUP BY 1, 2) as token_prices ON eth_tvl.contract_address = token_prices.contract_address and eth_tvl.time = token_prices.time)SELECT time, IF(weth_cumulative_value <= 0, NULL, weth_cumulative_value) as weth_cumulative_value, IF(dai_cumulative_value <= 0, NULL, dai_cumulative_value) AS dai_cumulative_value, IF(usdc_cumulative_value <= 0, NULL, usdc_cumulative_value) AS usdc_cumulative_value, IF(fxs_cumulative_value <= 0, NULL, fxs_cumulative_value) AS fxs_cumulative_value, IF(usdt_cumulative_value <= 0, NULL, usdt_cumulative_value) AS usdt_cumulative_value, IF(renbtc_cumulative_value <= 0, NULL, renbtc_cumulative_value) AS renbtc_cumulative_value, IF(cvx_cumulative_value <= 0, NULL, cvx_cumulative_value) AS cvx_cumulative_value, IF(wbtc_cumulative_value <= 0, NULL, wbtc_cumulative_value) AS wbtc_cumulative_value, IF(rail_cumulative_value <= 0, NULL, rail_cumulative_value) AS rail_cumulative_value, IF(snx_cumulative_value <= 0, NULL, snx_cumulative_value) AS snx_cumulative_value, IF(busd_cumulative_value <= 0, NULL, busd_cumulative_value) AS busd_cumulative_value, IF(wsteth_cumulative_value <= 0, NULL, wsteth_cumulative_value) AS wsteth_cumulative_value, IF(other_cumulative_value <= 0, NULL, other_cumulative_value) AS other_cumulative_value, IF(total_cumulative_value <= 0, NULL, total_cumulative_value) AS total_cumulative_value, IF(total_cumulative_value <= 0, NULL, total_cumulative_value)/1e6 AS total_cumulative_value_formatFROM(SELECTdate_series.time,SUM(IF(symbol = 'WETH', token_value, 0)) over (order by date_series.time) as weth_cumulative_value,