Updated 2024-01-29
    with

    L as( select max(date_trunc('day',date)) as date from external.defillama.fact_protocol_fees_revenue),

    A as(
    select chain, protocol,
    max(date) as max_date,
    sum(case when date_trunc('day',date) >= (select date from L) - interval '7 day' then fees else 0 end) as data_1,
    sum(case when date_trunc('day',date) >= (select date from L) - interval '14 day' then fees else 0 end) as data_2,
    sum(case when date_trunc('day',date) >= (select date from L) - interval '30 day' then fees else 0 end) as data_3,
    sum(case when date_trunc('day',date) >= (select date from L) - interval '60 day' then fees else 0 end) as data_4
    from external.defillama.fact_protocol_fees_revenue
    where lower(protocol) != lower(chain)
    group by 1,2),

    -- label category
    B as(
    select a.chain, a.protocol,
    data_1, data_2 - data_1 as data_2,
    data_3, data_4 - data_3 as data_4,
    case when b.category is not null then b.category else c.category end as category
    from A as a
    left join external.defillama.dim_protocols as b on a.protocol = b.protocol
    left join external.defillama.dim_dexes as c on a.protocol = c.dex
    WHERE a.max_date = (select max(max_date) from A)
    and data_1 > 100
    group by 1,2,3,4,5,6,7 ),

    B1 as (
    select
    chain, protocol, data_1, data_2, data_3, data_4,
    case
    when lower(protocol) = lower(chain) then 'Blockchain'
    when protocol in ('Maestro','Aimbot','Banana Gun','Unibot') then 'Trading Bots'
    when protocol in ('PostTechSoFi','FriendRoom','friend.tech','Stars Arena') then 'SoFi'
    when protocol in ('Tangible RWA') then 'RWA'
    Last run: about 1 year agoAuto-refreshes every 24 hours
    BLOCKCHAIN
    PROTOCOL LABEL ALL
    CATEGORY LIST ALL
    RANK 7D
    DATA 7D ($)
    DATA 7D (%)
    RANK 30D
    DATA 30D ($)
    DATA 30D (%)
    1
    arbitrumSYNAPSECross Chain28 $10,87298%33 $31,133-12%
    2
    polygonACROSSCross Chain20 $2,92398%22 $9,0951%
    3
    arbitrumPOSTTECHSOFISoFi43 $1,43397%44 $4,56714%
    4
    bscRAINBOWServices20 $3,14096%24 $11,052-36%
    5
    arbitrumFRAX SWAPDexes38 $2,25795%39 $8,369-4%
    6
    ethereumPENDLEYield34 $37,96493%52 $74,098254%
    7
    ethereumSYNTHETIXSynthetics39 $32,71190%50 $90,809-65%
    8
    bobaSUSHISWAPDexes1 $37990%1 $1,323-22%
    9
    ethereumMAKERDAOCDP3 $3,669,0389%4 $14,736,031-1%
    10
    solanaLIFINITYDexes2 $126,6659%2 $508,193-8%
    11
    zksync eraPANCAKESWAPDexes2 $25,3319%3 $119,14944%
    12
    mantleAGNI FINANCEDexes2 $28,5139%2 $182,0740%
    13
    baseDACKIESWAPDexes19 $9909%18 $5,14948%
    14
    baseMAVERICK PROTOCOLDexes10 $4,9109%12 $19,73456%
    15
    baseBALANCERDexes13 $3,327893%17 $6,425-13%
    16
    polygonBALANCERDexes7 $78,39987%7 $219,431-9%
    17
    polygonGAMMAYield5 $138,01586%4 $600,780-30%
    18
    hydraHYDRADEXDexes1 $52185%1 $3,171-45%
    19
    zksync eraSATORIDerivatives5 $8,85183%6 $24,032114%
    20
    basePANCAKESWAPDexes7 $8,9558%8 $42,86519%
    ...
    397
    36KB
    4s