Query editor
withL (contract,protocol) as (values(0xD166337499E176bbC38a1FBd113Ab144e5bd2Df7 , 'sUSDat'),(0x7a7dE491e1BE5287874904e2b7c8488249A4D0a9 , 'Pendle'),(0xF4d0CF32908b2C7f1021339c43Df0F77f06896d7 , 'Curve'),(0xa0de671eb84de9dee1d311d996d25c41f63a0d86 , 'BNB Chain')),A as(select evt_block_time, "from" as user, "to" as pool, 0+value/1e6 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/1e6 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= 0x23238f20b894f29041f48d88ee91131c395aaa71group 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= 0x23238f20b894f29041f48d88ee91131c395aaa71and 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(select * from D union all