Query editor
/* Polygon — Safe inflows / outflows / net / running balance (MATIC) */WITH addr AS (-- Your Safe address in bytes format (remove 0x for FROM_HEX)SELECT FROM_HEX('DCE35F5F9AB98C6DD671B15FB23602F67E296C0B') AS safe),daily AS (SELECTDATE_TRUNC('day', t.block_time) AS day,-- Inflows: MATIC sent to the SafeSUM(CASE WHEN t."to" = (SELECT safe FROM addr)THEN COALESCE(TRY_CAST(t.value AS DECIMAL), 0) / 1e18ELSE 0 END) AS inflow_matic,-- Outflows: MATIC sent from the SafeSUM(CASE WHEN t."from" = (SELECT safe FROM addr)THEN COALESCE(TRY_CAST(t.value AS DECIMAL), 0) / 1e18ELSE 0 END) AS outflow_maticFROM polygon.transactions tWHERE (t."to" = (SELECT safe FROM addr) OR t."from" = (SELECT safe FROM addr))AND t.success = TRUEGROUP BY 1)SELECTday,inflow_matic,outflow_matic,(inflow_matic - outflow_matic) AS net_matic,SUM(inflow_matic - outflow_matic) OVER (ORDER BY day) AS balance_maticFROM dailyORDER BY day;