Query editor
-- This query used incompatible data types from Dune SQL alpha and may need to be updated.-- More details can be found on https://dune.com/docs/query/dunesql-changes/with market_flows as (select block_date as date_at,case when token_bought_address = 0x64aa3364F17a4D01c6f1751Fd97C2BD3D7e7f1D5 then amount_usdelse - amount_usd end as amount_usd,amount_usd as volume_usdfrom dex.tradeswhere blockchain = 'ethereum'and (token_sold_address = 0x64aa3364F17a4D01c6f1751Fd97C2BD3D7e7f1D5 or token_bought_address = 0x64aa3364F17a4D01c6f1751Fd97C2BD3D7e7f1D5)and block_date > date('2022-12-01')),rbs_flows as (-- RBS Lower Cushionselect date_trunc('day', t.evt_block_time) as date_at,-cast(t.amount_ as double)/1e18 as amount_usd -- assumes DAI = 1$,cast(t.amount_ as double)/1e18 as volume_usdfrom olympusdao_ethereum.OlympusMinter_evt_Burn as binner join olympusdao_ethereum.OlympusTreasury_evt_Withdrawal as ton b.evt_tx_hash = t.evt_tx_hashwhere b.policy_ = 0xbf2b6e99b0e8d4c96b946c182132f5752eaa55c6 --cushion swapsand t.evt_block_time > date('2022-12-01')union all-- RBS Lower Wall (V1)select date_trunc('day', t.evt_block_time) as date_at,-cast(t.amount_ as double)/1e18 as amount_usd -- assumes DAI = 1$,cast(t.amount_ as double)/1e18 as volume_usdfrom olympusdao_ethereum.Operator_evt_Swap as sinner join olympusdao_ethereum.OlympusTreasury_evt_Withdrawal as ton s.evt_tx_hash = t.evt_tx_hashwhere t.evt_block_time > date('2022-12-01') and t.token_ = 0x6b175474e89094c44da98b954eedeac495271d0funion all-- RBS Lower Wall (V2)select date_trunc('day', t.evt_block_time) as date_at,-cast(t.amount_ as double)/1e18 as amount_usd -- assumes DAI = 1$,cast(t.amount_ as double)/1e18 as volume_usdfrom olympusdao_ethereum.Operatorv2_evt_Swap as sinner join olympusdao_ethereum.OlympusTreasury_evt_Withdrawal as ton s.evt_tx_hash = t.evt_tx_hashwhere t.evt_block_time > date('2022-12-01') and t.token_ = 0x6b175474e89094c44da98b954eedeac495271d0f)select *, sum(net_flow) over (partition by source order by date_at asc) as cum_netflowsfrom (select *, 'AMMs' as sourcefrom (select date_at,sum(amount_usd) as net_flow,sum(volume_usd) as volumefrom market_flowsgroup by 1) dunion allselect *, 'RBS' as sourcefrom (select date_at