Query editor
withfluid_vaults as (select *-- from "query_4248818"from dune.dknugo.result_fluid_vaults -- on-chain), vaults_netflow as (select*, coll_shares * coll_share_price as coll_usd, debt_shares * debt_share_price as debt_usd, greatest(coll_shares * coll_share_price - coalesce(debt_shares * debt_share_price, 0), 0) as tvl, coll_shares_chg * coll_share_price as coll_net_flow_usd, debt_shares_chg * debt_share_price as debt_net_flow_usd, coll_shares_chg * coll_share_price - debt_shares_chg * debt_share_price as net_flow_usdfrom (selectr.day, r.user_address as vault, r.blockchain, r.name, r.cum_coll_shares as coll_shares, r.cum_debt_shares as debt_shares-- , if(v.type in (2, 4), rc.coll_usd, r.coll_usd) as coll_usd-- , if(v.type in (3, 4), rd.debt_usd, r.debt_usd) as debt_usd, if(v.type in (2, 4), if(rc.cum_coll_shares > 0, rc.coll_usd / rc.cum_coll_shares, 0), if(r.cum_coll_shares > 0, r.coll_usd / r.cum_coll_shares, 0)) as coll_share_price, if(v.type in (3, 4), if(rd.cum_debt_shares > 0, rd.debt_usd / rd.cum_debt_shares, 0), if(r.cum_debt_shares > 0, r.debt_usd / r.cum_debt_shares, 0)) as debt_share_price, r.cum_coll_shares - (lag(r.cum_coll_shares, 1) over (partition by r.user_address, r.blockchain order by r.day)) as coll_shares_chg, r.cum_debt_shares - (lag(r.cum_debt_shares, 1) over (partition by r.user_address, r.blockchain order by r.day)) as debt_shares_chgfrom dune.dknugo.result_fluid_user_reserves_daily as rinner join fluid_vaults as von r.user_address = v.addressand r.blockchain = v.blockchainleft join dune.dknugo.result_fluid_user_reserves_daily as rcon rc.user_address = v.supplyDexDataAddressand rc.blockchain = v.blockchainand rc.day = r.dayleft join dune.dknugo.result_fluid_user_reserves_daily as rdon rd.user_address = v.borrowDexDataAddressand rd.blockchain = v.blockchainand rd.day = r.day)), vaults_netflow_adj as (selectday, vault, blockchain, name, tvl, tvl - coalesce(lag(tvl, 1) over (partition by vault, blockchain order by day), 0) as tvl_chg_1d, tvl - coalesce(lag(tvl, 3) over (partition by vault, blockchain order by day), 0) as tvl_chg_3d, tvl - coalesce(lag(tvl, 7) over (partition by vault, blockchain order by day), 0) as tvl_chg_7d, net_flow_usd as netflow_1d, sum(net_flow_usd) over (partition by vault, blockchain order by day rows between 2 preceding and current row) as netflow_3d, sum(net_flow_usd) over (partition by vault, blockchain order by day rows between 6 preceding and current row) as netflow_7d, row_number() over (partition by vault, blockchain order by day desc) as rn