Query editor
with outflows as (select *,sum(-net_flow) over (order by date_at asc) as cum_spent,avg(-net_flow) over (order by date_at asc rows between 45 preceding and current row) as "45day_ma",avg(-net_flow) over (order by date_at asc rows between 30 preceding and current row) as "30day_ma",avg(-net_flow) over (order by date_at asc rows between 15 preceding and current row) as "15day_ma"from query_2029751 where source = 'RBS'),capacity as (select date_trunc('day', evt_block_time) as date_at,avg(capacity) as capacityfrom query_2033325 where high_ = falsegroup by 1),treasury as (select date_at, sum(amount) as amountfrom (-- funds received (IN)select date_trunc('day', evt_block_time) as date_at,case when evt_tx_hash = 0x3a9747db9118a70502c47aab5089a8ead164f1b85994dbbf89378a1d34ce17bf then 85925992 - 75000000else cast(value as double)/1e18 end as amountfrom erc20_ethereum.evt_Transferwhere evt_block_number > 15998126and "to" = 0xa8687A15D4BE32CC8F0a8a7B9704a4C3993D9613and contract_address = 0x6B175474E89094C44Da98b954EedeAC495271d0Funion all-- funds spent (OUT)select date_trunc('day', evt_block_time) as day_at,-cast(value as double)/1e18 as amountfrom erc20_ethereum.evt_Transferwhere evt_block_number > 15998126and "from" = 0xa8687A15D4BE32CC8F0a8a7B9704a4C3993D9613and contract_address = 0x6B175474E89094C44Da98b954EedeAC495271d0Fand evt_tx_hash not in (0x7022e1a08c3aecbff41ed7f253ffb96e6765020539ab1ee1a658bffccf8cf71c,0x9cc2725719aa9d08adb3edf030403056215995ea168160f44ff1800caae7eea3,0xe11502745ddf1e8c286552853bbc73dee472b7eeb2dc8323f099c26bff026ca5)) as tgroup by 1)select c.date_at,o.cum_spent,c.capacity,t.amount as treasury,o."45day_ma",o."30day_ma",o."15day_ma",case when c.date_at > date('2022-12-09') then c.capacity / o."45day_ma" else null end as rbs_runway_45dma,case when c.date_at > date('2022-12-09') then c.capacity / o."30day_ma" else null end as rbs_runway_30dma,case when c.date_at > date('2022-12-09') then c.capacity / o."15day_ma" else null end as rbs_runway_15dma,case when c.date_at > date('2022-12-09') then t.amount / o."45day_ma" else null end as treasury_runway_45dma,case when c.date_at > date('2022-12-09') then t.amount / o."30day_ma" else null end as treasury_runway_30dma,case when c.date_at > date('2022-12-09') then t.amount / o."15day_ma" else null end as treasury_runway_15dmafrom capacity as cleft join outflows as oon c.date_at = o.date_at