mucrypto2023-08-26 01:37 AM
    Updated 2023-08-25
    with resps as
    (select defillama.get('/protocols', {}) as resp),

    cex as (
    select
    value:category::string as category,
    value:tvl::number as tvl
    from resps,
    lateral flatten (input => resp:data)
    where category = 'CEX'),

    defi as (
    select
    value:category::string as category,
    value:tvl::number as tvl
    from resps,
    lateral flatten (input => resp:data)
    where category not in ('CEX', 'Chain', 'Bridge')),

    cex_tvl as (
    select
    sum(tvl) as cex_tvl
    from cex),

    defi_tvl as (
    select
    sum(tvl) as defi_tvl
    from defi)

    select
    'CEX' as category,
    cex_tvl as tvl
    from cex_tvl

    union all

    Run a query to Download Data