with Tprice as (
select
TOKEN_ADDRESS,
avg(PRICE) as Price
from arbitrum.price.ez_hourly_token_prices
where HOUR >= current_timestamp - interval '24 hours'
and token_address in (select
DISTINCT TOKEN_ADDRESS
from arbitrum.vertex.ez_clearing_house_events
)
group by 1
)
select
sum(AMOUNT * price) as TVL
from arbitrum.vertex.ez_clearing_house_events
join Tprice using (TOKEN_ADDRESS)