with resps as
(select defillama.get('/protocols', {}) as resp),
b as (
select
value:category as category,
value:chainTvls as blockchains
from resps,
lateral flatten (input => resp:data)
where category = 'Uncollateralized Lending'),
a as (
select
*
from b,
lateral flatten (input => blockchains)),
list as (
select
key as "BLOCKCHAIN/CATEGORY",
sum(value) as tvl_,
from a
group by 1),
total as (
select
sum(tvl_) as total_number
from list)
select
"BLOCKCHAIN/CATEGORY",
tvl_,
case
when
tvl_ <1000 then concat('$', to_varchar(cast(tvl_ as decimal(38, 2))::string))
when