Skip to content

Commit 9401b5f

Browse files
committed
feat: add comprehensive unit/anvil/integration tests
1 parent cefb196 commit 9401b5f

17 files changed

+5079
-263
lines changed

internal/config/config.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,10 @@ func (c *Config) GetRewardsSqlForkDates() (ForkMap, error) {
593593
Date: "2025-05-14",
594594
BlockNumber: 3840004,
595595
},
596+
RewardsFork_Sabine: Fork{
597+
Date: "1970-01-01",
598+
BlockNumber: 0,
599+
},
596600
}, nil
597601
case Chain_Holesky:
598602
return ForkMap{
@@ -631,6 +635,10 @@ func (c *Config) GetRewardsSqlForkDates() (ForkMap, error) {
631635
Date: "2025-05-14",
632636
BlockNumber: 3840004,
633637
},
638+
RewardsFork_Sabine: Fork{
639+
Date: "1970-01-01",
640+
BlockNumber: 0,
641+
},
634642
}, nil
635643
case Chain_Sepolia:
636644
return ForkMap{
@@ -724,8 +732,8 @@ func (c *Config) GetRewardsSqlForkDates() (ForkMap, error) {
724732
BlockNumber: 0,
725733
},
726734
RewardsFork_Sabine: Fork{
727-
Date: "2025-12-19",
728-
BlockNumber: 1871733,
735+
Date: "1970-01-01",
736+
BlockNumber: 0,
729737
},
730738
}, nil
731739
case Chain_Mainnet:

pkg/rewards/15_goldOperatorOperatorSetUniqueStakeRewards.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ operators_with_unique_stake AS (
7474
strategy,
7575
multiplier,
7676
reward_submission_date,
77+
registration_snapshot,
78+
slashable_until,
7779
-- Sum the weighted allocated stake across strategies
7880
SUM(allocated_stake * multiplier) OVER (
7981
PARTITION BY reward_hash, snapshot, operator
@@ -138,7 +140,10 @@ operators_with_slash_multiplier AS (
138140
ON DATE(b_reg.block_time) = owds.registration_snapshot
139141
LEFT JOIN blocks b_snapshot
140142
ON DATE(b_snapshot.block_time) = owds.snapshot
141-
GROUP BY owds.*, owds.in_deregistration_queue
143+
GROUP BY owds.reward_hash, owds.snapshot, owds.token, owds.tokens_per_registered_snapshot_decimal,
144+
owds.avs, owds.operator_set_id, owds.operator, owds.strategy, owds.multiplier,
145+
owds.reward_submission_date, owds.registration_snapshot, owds.slashable_until,
146+
owds.operator_allocated_weight, owds.rn, owds.in_deregistration_queue
142147
),
143148
144149
-- Step 5: Apply slash multiplier to tokens
@@ -196,7 +201,7 @@ func (rc *RewardsCalculator) GenerateGold15OperatorOperatorSetUniqueStakeRewards
196201
query, err := rewardsUtils.RenderQueryTemplate(_15_goldOperatorOperatorSetUniqueStakeRewardsQuery, map[string]interface{}{
197202
"destTableName": destTableName,
198203
"activeODRewardsTable": allTableNames[rewardsUtils.Table_11_ActiveODOperatorSetRewards],
199-
"operatorAllocationSnapshotsTable": allTableNames[rewardsUtils.Table_OperatorAllocationSnapshots],
204+
"operatorAllocationSnapshotsTable": "operator_allocation_snapshots",
200205
"operatorShareSnapshotsTable": "operator_share_snapshots",
201206
})
202207
if err != nil {

pkg/rewards/16_goldStakerOperatorSetUniqueStakeRewards.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ WITH operator_rewards AS (
1818
avs,
1919
operator_set_id,
2020
strategy,
21+
multiplier,
2122
tokens_per_registered_snapshot_decimal,
2223
-- Calculate staker split (total rewards minus operator split)
2324
tokens_per_registered_snapshot_decimal - operator_tokens as staker_split_total
@@ -27,20 +28,19 @@ WITH operator_rewards AS (
2728
-- Step 2: Get stakers delegated to each operator
2829
staker_delegations AS (
2930
SELECT
30-
or.*,
31+
op_rew.*,
3132
sds.staker
32-
FROM operator_rewards or
33+
FROM operator_rewards op_rew
3334
JOIN staker_delegation_snapshots sds
34-
ON or.operator = sds.operator
35-
AND or.snapshot = sds.snapshot
35+
ON op_rew.operator = sds.operator
36+
AND op_rew.snapshot = sds.snapshot
3637
),
3738
3839
-- Step 3: Get each staker's shares for the strategy
3940
staker_strategy_shares AS (
4041
SELECT
4142
sd.*,
42-
sss.shares,
43-
sd.multiplier
43+
sss.shares
4444
FROM staker_delegations sd
4545
JOIN staker_share_snapshots sss
4646
ON sd.staker = sss.staker

pkg/rewards/17_goldAvsOperatorSetUniqueStakeRewards.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package rewards
22

33
import (
4-
"database/sql"
5-
64
"github.com/Layr-Labs/sidecar/internal/config"
75
"github.com/Layr-Labs/sidecar/pkg/rewardsUtils"
86
"go.uber.org/zap"
@@ -85,7 +83,7 @@ func (rc *RewardsCalculator) GenerateGold17AvsOperatorSetUniqueStakeRewardsTable
8583
return err
8684
}
8785

88-
res := rc.grm.Exec(query, sql.Named("coloradoHardforkDate", forks[config.RewardsFork_Colorado].Date))
86+
res := rc.grm.Exec(query)
8987
if res.Error != nil {
9088
rc.logger.Sugar().Errorw("Failed to create gold_avs_operator_set_unique_stake_rewards v2.2", "error", res.Error)
9189
return res.Error

pkg/rewards/19_goldStakerOperatorSetTotalStakeRewards.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ WITH operator_rewards AS (
1818
avs,
1919
operator_set_id,
2020
strategy,
21+
multiplier,
2122
tokens_per_registered_snapshot_decimal,
2223
-- Calculate staker split (total rewards minus operator split)
2324
tokens_per_registered_snapshot_decimal - operator_tokens as staker_split_total
@@ -27,20 +28,19 @@ WITH operator_rewards AS (
2728
-- Step 2: Get stakers delegated to each operator
2829
staker_delegations AS (
2930
SELECT
30-
or.*,
31+
op_rew.*,
3132
sds.staker
32-
FROM operator_rewards or
33+
FROM operator_rewards op_rew
3334
JOIN staker_delegation_snapshots sds
34-
ON or.operator = sds.operator
35-
AND or.snapshot = sds.snapshot
35+
ON op_rew.operator = sds.operator
36+
AND op_rew.snapshot = sds.snapshot
3637
),
3738
3839
-- Step 3: Get each staker's shares for the strategy
3940
staker_strategy_shares AS (
4041
SELECT
4142
sd.*,
42-
sss.shares,
43-
sd.multiplier
43+
sss.shares
4444
FROM staker_delegations sd
4545
JOIN staker_share_snapshots sss
4646
ON sd.staker = sss.staker

pkg/rewards/20_goldAvsOperatorSetTotalStakeRewards.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package rewards
22

33
import (
4-
"database/sql"
5-
64
"github.com/Layr-Labs/sidecar/internal/config"
75
"github.com/Layr-Labs/sidecar/pkg/rewardsUtils"
86
"go.uber.org/zap"
@@ -85,7 +83,7 @@ func (rc *RewardsCalculator) GenerateGold20AvsOperatorSetTotalStakeRewardsTable(
8583
return err
8684
}
8785

88-
res := rc.grm.Exec(query, sql.Named("coloradoHardforkDate", forks[config.RewardsFork_Colorado].Date))
86+
res := rc.grm.Exec(query)
8987
if res.Error != nil {
9088
rc.logger.Sugar().Errorw("Failed to create gold_avs_operator_set_total_stake_rewards v2.2", "error", res.Error)
9189
return res.Error

pkg/rewards/21_goldStaging.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,32 +121,32 @@ avs_od_operator_set_rewards AS (
121121
),
122122
{{ end }}
123123
{{ if .enableRewardsV2_2 }}
124-
operator_od_operator_set_rewards_v2_2_unique_stake AS (
124+
operator_operator_set_unique_stake_rewards AS (
125125
SELECT DISTINCT
126126
operator as earner,
127127
snapshot,
128128
reward_hash,
129129
token,
130130
operator_tokens as amount
131-
FROM {{.operatorODOperatorSetRewardAmountsTableV2_2}}
131+
FROM {{.operatorOperatorSetUniqueStakeRewardsTable}}
132132
),
133-
staker_od_operator_set_rewards_v2_2_unique_stake AS (
133+
staker_operator_set_unique_stake_rewards AS (
134134
SELECT DISTINCT
135135
staker as earner,
136136
snapshot,
137137
reward_hash,
138138
token,
139139
staker_tokens as amount
140-
FROM {{.stakerODOperatorSetRewardAmountsTableV2_2}}
140+
FROM {{.stakerOperatorSetUniqueStakeRewardsTable}}
141141
),
142-
avs_od_operator_set_rewards_v2_2_unique_stake AS (
142+
avs_operator_set_unique_stake_rewards AS (
143143
SELECT DISTINCT
144144
avs as earner,
145145
snapshot,
146146
reward_hash,
147147
token,
148148
avs_tokens as amount
149-
FROM {{.avsODOperatorSetRewardAmountsTableV2_2}}
149+
FROM {{.avsOperatorSetUniqueStakeRewardsTable}}
150150
),
151151
operator_operator_set_total_stake_rewards AS (
152152
SELECT DISTINCT

pkg/rewards/operatorAllocationSnapshots.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,8 @@ const operatorAllocationSnapshotsQuery = `
104104
operator_set_id,
105105
magnitude,
106106
cast(day AS DATE) AS snapshot
107-
FROM
108-
cleaned_records
109-
CROSS JOIN
110-
generate_series(DATE(start_time), DATE(end_time) - interval '1' day, interval '1' day) AS day
107+
FROM cleaned_records
108+
CROSS JOIN generate_series(DATE(start_time), DATE(end_time) - interval '1' day, interval '1' day) AS day
111109
),
112110
max_magnitude_windows as (
113111
SELECT
@@ -127,11 +125,9 @@ const operatorAllocationSnapshotsQuery = `
127125
strategy,
128126
max_magnitude,
129127
cast(day AS DATE) AS snapshot
130-
FROM
131-
max_magnitude_windows
128+
FROM max_magnitude_windows
129+
CROSS JOIN generate_series(DATE(start_time), DATE(end_time) - interval '1' day, interval '1' day) AS day
132130
WHERE start_time < end_time
133-
CROSS JOIN
134-
generate_series(DATE(start_time), DATE(end_time) - interval '1' day, interval '1' day) AS day
135131
)
136132
SELECT
137133
das.operator,

0 commit comments

Comments
 (0)