Query editor
WITH wpaw_inflows AS (SELECTc."to" AS address,SUM(c."value") AS total_wpaw_inflowsFROM erc20_ethereum.evt_Transfer AS cWHEREc.contract_address = 0xc11158c5da9db1d553ed28f0c2ba1cbedd42cfcb --$wPAWGROUP BYc."to"),wpaw_outflows AS (SELECTc."from" AS address,SUM(c."value") AS total_wpaw_outflowsFROM erc20_ethereum.evt_Transfer AS cWHEREc.contract_address = 0xc11158c5da9db1d553ed28f0c2ba1cbedd42cfcb --$wPAWGROUP BYc."from"),wpaw_holders AS (SELECTi.address,i.total_wpaw_inflows - COALESCE(o.total_wpaw_outflows, CAST(0 AS uint256)) AS wpaw_heldFROM wpaw_inflows AS iLEFT JOIN wpaw_outflows AS oON i.address = o.address),-- Daily inflows and outflows separately (no negative arithmetic)daily_inflows AS (SELECTDATE_TRUNC('day', evt_block_time) AS day,"to" AS address,SUM("value") AS daily_inflowsFROM erc20_ethereum.evt_TransferWHERE contract_address = 0xc11158c5da9db1d553ed28f0c2ba1cbedd42cfcb --$wPAWGROUP BY DATE_TRUNC('day', evt_block_time), "to"),daily_outflows AS (SELECTDATE_TRUNC('day', evt_block_time) AS day,"from" AS address,SUM("value") AS daily_outflowsFROM erc20_ethereum.evt_TransferWHERE contract_address = 0xc11158c5da9db1d553ed28f0c2ba1cbedd42cfcb --$wPAWGROUP BY DATE_TRUNC('day', evt_block_time), "from"),-- Calculate cumulative inflows and outflows separatelycumulative_flows AS (SELECTd.day,h.address,COALESCE(SUM(di.daily_inflows) OVER (PARTITION BY h.addressORDER BY d.dayROWS UNBOUNDED PRECEDING), CAST(0 AS uint256)) AS cumulative_inflows,