Query editor
withsupply as(selectdate_trunc('day',s.evt_block_time) as time, s.reserve as reserve, sum(cast(s.amount as double)) as amountfrom aave_v3_ethereum.Pool_evt_Supply as sgroup by 1,2), withdrawals as(selectdate_trunc('day',w.evt_block_time) as time, w.reserve reserve, sum(cast(w.amount as double)) as amountfrom aave_v3_ethereum.Pool_evt_Withdraw wgroup by 1,2), net_supply as (selectCOALESCE(s.time, w.time) as time, COALESCE(s.reserve, w.reserve) as reserve, coalesce(s.amount,0) as amount_added, COALESCE(w.amount,0) as amount_removedfrom supply sfull outer join withdrawals won s.time = w.timeand s.reserve = w.reserve)-- Create empty time series, days as (with days_seq as (SELECT sequence(date_trunc('day', cast('{{start_date}}' as timestamp)), date_trunc('day', cast(now() as timestamp)), interval '1' day) as day)SELECTdays.dayFROM days_seqCROSS JOIN unnest(day) as days(day)), net_supply_ts as (selectd.day as day, n.reserve as reserve, tk.symbol as symbol, n.amount_added as amount_added, n.amount_removed as amount_removed-- , n.amount_added - n.amount_removed as net_supply, sum((n.amount_added) / pow(10,COALESCE(tk.decimals,18)) * p.price) as amount_added_usd