Query editor
withactions as (select * from query_3755108),agg as (selecta.underlying_token,a.symbol,sum(case actionwhen 'deposit' then amtelse -amtend) as sharesfrom actions a-- where operator = 0x5accc90436492f24e6af278569691e2c942a676d-- and underlying_token = 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2group by 1,2),latest_prices as (select * from (-- daily pricesselect *,rank() over(partition by token order by date desc) as rank_latestfrom query_3756648) where rank_latest = 1),token_agg as (selecta.symbol,a.underlying_token,a.shares as tokens,a.shares*p.price/sol.price as eth,a.shares*p.price as usd-- case-- when underlying_token = 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 then 1-- else rank()from agg aleft join latest_prices p-- on p.token = a.underlying_tokenon from_base58(a.underlying_token) = p.tokenleft join latest_prices sol-- on w.token = 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2on sol.token = 0x0cec34833868e79f650616e347bd70632fc56904df7d27a6960301bf29f36205)select * from (select * from token_agg)order by eth desc