Query editor
withL (contract,protocol) as (values(0x8917F8c7Feb840b5837EDC7e128123baa2f289F9 , 'Pendle'),(0xBBBBBbbBBb9cC5e90e3b3Af64bdAF62C37EEFFCb , 'Morpho'),(0xce7b00d1004d9ed22e702a6a7f5bbdce7297b090 , 'Strata'),(0x6206cA315c2fCDd2A857b47EFB285AA12c529a7a , 'Curve'),(0xF3fC7FDE5081192177f38895e57a1489e4bD56f2 , 'BNB Chain')),A as(select evt_block_time, "from" as user, "to" as pool, 0+value/1e18 as amount, evt_tx_hash as hash, contract_address from erc20_ethereum.evt_transfer union allselect evt_block_time, "to" as user, "from" as pool, 0-value/1e18 as amount, evt_tx_hash as hash, contract_address from erc20_ethereum.evt_transfer ),--B as(select date_trunc('day',evt_block_time) as time, protocol, sum(amount) as balancefrom A as ajoin L as b on a.pool = b.contractwhere contract_address= 0xd166337499e176bbc38a1fbd113ab144e5bd2df7group by 1,2 ),X as( select distinct time from B ),Y as( select distinct protocol from B ),Z as( select time,protocol from X,Y group by 1,2),C as(select a.time, a.protocol, case when balance is null then 0 else balance end as balancefrom Z as aleft join B as b on a.time = b.time and a.protocol = b.protocolgroup by 1,2,3 ),D as(select time, protocol, sum(balance) over(partition by protocol order by time) as balancefrom C),--E as(select time, sum(balance) as balancefrom Dgroup by 1),F as(select date_trunc('day',evt_block_time) as time, sum(amount) as supplyfrom Awhere contract_address= 0xd166337499e176bbc38a1fbd113ab144e5bd2df7and user = 0x0000000000000000000000000000000000000000group by 1),G as( select time, sum(supply) over(order by time) as supply from F),H as(select a.time, 'Naked Hold' as protocol, supply - balance as balancefrom G as aleft join E as b on a.time = b.time),---I as(