@@ -11,7 +11,7 @@ const operatorAllocationSnapshotsQuery = `
1111 SELECT *,
1212 ROW_NUMBER() OVER (PARTITION BY operator, avs, strategy, operator_set_id, cast(block_time AS DATE) ORDER BY block_time DESC, log_index DESC) AS rn
1313 FROM operator_allocations oa
14- INNER JOIN blocks b ON oa.block_number = b.number
14+ INNER JOIN blocks b ON oa.effective_block = b.number
1515 WHERE b.block_time < TIMESTAMP '{{.cutoffDate}}'
1616 ),
1717 -- Get the latest record for each day
@@ -42,8 +42,8 @@ const operatorAllocationSnapshotsQuery = `
4242 -- Deallocation (decrease or no change): Round DOWN to current day
4343 CASE
4444 WHEN LAG(magnitude) OVER (PARTITION BY operator, avs, strategy, operator_set_id ORDER BY block_time, block_number, log_index) IS NULL THEN
45- -- First allocation: round down to current day (conservative default)
46- date_trunc('day', block_time)
45+ -- First allocation: round up to next day
46+ date_trunc('day', block_time) + INTERVAL '1' day
4747 WHEN magnitude > LAG(magnitude) OVER (PARTITION BY operator, avs, strategy, operator_set_id ORDER BY block_time, block_number, log_index) THEN
4848 -- Increase: round up to next day
4949 date_trunc('day', block_time) + INTERVAL '1' day
0 commit comments