with alamedaftx as (
select *
from solana.core.dim_labels
where label like '%alameda%'
or label like 'ftx%'
or address_name ilike '%alameda%'
or address_name ilike 'ftx%'),
Inflowt as (
select
sum (amount) as Inflow_Volume
from solana.core.fact_transfers
where tx_to in (select distinct address from alamedaftx)
and tx_from not in (select distinct address from alamedaftx)
and mint = 'So11111111111111111111111111111111111111112'
and block_timestamp >= CURRENT_DATE - 21),
Outflowt as (
select sum (amount) as Outflow_Volume
from solana.core.fact_transfers
where tx_from in (select distinct address from alamedaftx)
and tx_to not in (select distinct address from alamedaftx)
and mint = 'So11111111111111111111111111111111111111112'
and block_timestamp >= CURRENT_DATE - 21)
select inflow_volume as Inflow,
outflow_volume*-1 as Outflow,
inflow_volume - outflow_volume as Net_Flow
from Inflowt t1 join Outflowt t2