Query editor
with raw_data as (select json_parse(http_get('https://api.llama.fi/v2/historicalChainTvl/Cardano')) as json_data),tvl_data as (select cast(entry as json) as entryfrom raw_datacross join unnest(cast(json_data as array(json))) as t(entry)),parsed as (selectfrom_unixtime(cast(json_extract_scalar(entry, '$.date') as bigint)) as day,cast(json_extract_scalar(entry, '$.tvl') as double) as tvl_usdfrom tvl_data)selectday,tvl_usd,tvl_usd / 1e6 as tvl_usd_in_million,(tvl_usd - lag(tvl_usd) over (order by day))/ nullif(lag(tvl_usd) over (order by day), 0) * 1.0 as daily_change_pct,(tvl_usd - lag(tvl_usd) over (order by day))/ nullif(lag(tvl_usd) over (order by day), 0) * 100.0 as daily_change_pct_formattedfrom parsedwhereday >= casewhen cast('{{days}}' as varchar) = 'all-time' then date '2000-01-01'else current_date - interval '1' day * cast('{{days}}' as integer)endorder by day desc