From 11795120661a7fa307f2b1c3eb540e56eda4b426 Mon Sep 17 00:00:00 2001 From: Sean McGary Date: Tue, 10 Dec 2024 21:17:08 -0600 Subject: [PATCH] remove checking ORS in rewards v2 --- ...eprodRewardsV2_generateExpectedResults.sql | 4 +-- ...eprodRewardsV2_generateExpectedResults.sql | 2 +- ...eprodRewardsV2_generateExpectedResults.sql | 2 +- ...eprodRewardsV2_generateExpectedResults.sql | 4 +-- ...eprodRewardsV2_generateExpectedResults.sql | 4 +-- ...eprodRewardsV2_generateExpectedResults.sql | 2 +- ...eprodRewardsV2_generateExpectedResults.sql | 8 ++--- pkg/rewards/10_goldAvsODRewardAmounts.go | 2 +- pkg/rewards/11_goldStaging.go | 14 ++------ pkg/rewards/8_goldOperatorODRewardAmounts.go | 1 + pkg/rewards/9_goldStakerODRewardAmounts.go | 36 +++++-------------- pkg/rewards/rewardsV2_test.go | 2 +- 12 files changed, 27 insertions(+), 54 deletions(-) diff --git a/internal/tests/testdata/operatorAvsRegistrationSnapshots/preprodRewardsV2_generateExpectedResults.sql b/internal/tests/testdata/operatorAvsRegistrationSnapshots/preprodRewardsV2_generateExpectedResults.sql index 69cd5e52..33ded9bd 100644 --- a/internal/tests/testdata/operatorAvsRegistrationSnapshots/preprodRewardsV2_generateExpectedResults.sql +++ b/internal/tests/testdata/operatorAvsRegistrationSnapshots/preprodRewardsV2_generateExpectedResults.sql @@ -1,7 +1,7 @@ COPY ( with filtered as ( select * from dbt_preprod_holesky_rewards.operator_avs_status - where block_time < '2024-12-10' + where block_time < '2024-12-11' ), marked_statuses AS ( SELECT @@ -34,7 +34,7 @@ marked_statuses AS ( operator, avs, block_time AS start_time, - COALESCE(next_block_time, TIMESTAMP '2024-12-10') AS end_time, + COALESCE(next_block_time, TIMESTAMP '2024-12-11') AS end_time, registered FROM removed_same_day_deregistrations WHERE registered = TRUE diff --git a/internal/tests/testdata/operatorRestakedStrategies/preprodRewardsV2_generateExpectedResults.sql b/internal/tests/testdata/operatorRestakedStrategies/preprodRewardsV2_generateExpectedResults.sql index 601592be..52eceb25 100644 --- a/internal/tests/testdata/operatorRestakedStrategies/preprodRewardsV2_generateExpectedResults.sql +++ b/internal/tests/testdata/operatorRestakedStrategies/preprodRewardsV2_generateExpectedResults.sql @@ -11,7 +11,7 @@ copy (with ranked_records AS ( ) AS rn FROM public.operator_restaked_strategies WHERE avs_directory_address = lower('0x141d6995556135d4997b2ff72eb443be300353bc') - and block_time < '2024-12-10' + and block_time < '2024-12-11' ), latest_records AS ( SELECT diff --git a/internal/tests/testdata/operatorShareSnapshots/preprodRewardsV2_generateExpectedResults.sql b/internal/tests/testdata/operatorShareSnapshots/preprodRewardsV2_generateExpectedResults.sql index c0c7dce7..1f9fa0db 100644 --- a/internal/tests/testdata/operatorShareSnapshots/preprodRewardsV2_generateExpectedResults.sql +++ b/internal/tests/testdata/operatorShareSnapshots/preprodRewardsV2_generateExpectedResults.sql @@ -1,5 +1,5 @@ COPY ( select * FROM dbt_preprod_holesky_rewards.operator_share_snapshots -where snapshot < '2024-10-12' +where snapshot < '2024-12-10' ) TO STDOUT WITH DELIMITER ',' CSV HEADER diff --git a/internal/tests/testdata/operatorShares/preprodRewardsV2_generateExpectedResults.sql b/internal/tests/testdata/operatorShares/preprodRewardsV2_generateExpectedResults.sql index 326f7274..42c38ff3 100644 --- a/internal/tests/testdata/operatorShares/preprodRewardsV2_generateExpectedResults.sql +++ b/internal/tests/testdata/operatorShares/preprodRewardsV2_generateExpectedResults.sql @@ -11,12 +11,12 @@ SELECT FROM ( SELECT operator, strategy, shares, transaction_hash, log_index, block_time, block_date, block_number FROM dbt_preprod_holesky_rewards.operator_share_increases - where block_date < '2024-12-10' + where block_date < '2024-12-11' UNION ALL SELECT operator, strategy, shares * -1 AS shares, transaction_hash, log_index, block_time, block_date, block_number FROM dbt_preprod_holesky_rewards.operator_share_decreases - where block_date < '2024-12-10' + where block_date < '2024-12-11' ) combined_shares ) TO STDOUT WITH DELIMITER ',' CSV HEADER diff --git a/internal/tests/testdata/stakerDelegationSnapshots/preprodRewardsV2_generateExpectedResults.sql b/internal/tests/testdata/stakerDelegationSnapshots/preprodRewardsV2_generateExpectedResults.sql index d9fb5e3b..1537e4b6 100644 --- a/internal/tests/testdata/stakerDelegationSnapshots/preprodRewardsV2_generateExpectedResults.sql +++ b/internal/tests/testdata/stakerDelegationSnapshots/preprodRewardsV2_generateExpectedResults.sql @@ -3,7 +3,7 @@ COPY ( select * from dbt_preprod_holesky_rewards.staker_delegation_status - where block_time < '2024-12-10' + where block_time < '2024-12-11' ), ranked_delegations as ( SELECT *, @@ -24,7 +24,7 @@ ranked_delegations as ( staker, operator, snapshot_time as start_time, CASE -- If the range does not have the end, use the cutoff date truncated to 0 UTC - WHEN LEAD(snapshot_time) OVER (PARTITION BY staker ORDER BY snapshot_time) is null THEN date_trunc('day', TIMESTAMP '2024-12-10') + WHEN LEAD(snapshot_time) OVER (PARTITION BY staker ORDER BY snapshot_time) is null THEN date_trunc('day', TIMESTAMP '2024-12-11') ELSE LEAD(snapshot_time) OVER (PARTITION BY staker ORDER BY snapshot_time) END AS end_time FROM snapshotted_records diff --git a/internal/tests/testdata/stakerShareSnapshots/preprodRewardsV2_generateExpectedResults.sql b/internal/tests/testdata/stakerShareSnapshots/preprodRewardsV2_generateExpectedResults.sql index 46188491..3101b1d4 100644 --- a/internal/tests/testdata/stakerShareSnapshots/preprodRewardsV2_generateExpectedResults.sql +++ b/internal/tests/testdata/stakerShareSnapshots/preprodRewardsV2_generateExpectedResults.sql @@ -2,5 +2,5 @@ COPY ( select * from dbt_preprod_holesky_rewards.staker_share_snapshots -where snapshot < '2024-12-10' +where snapshot < '2024-12-11' ) TO STDOUT WITH DELIMITER ',' CSV HEADER diff --git a/internal/tests/testdata/stakerShares/preprodRewardsV2_generateExpectedResults.sql b/internal/tests/testdata/stakerShares/preprodRewardsV2_generateExpectedResults.sql index 87731c97..d24cdfc2 100644 --- a/internal/tests/testdata/stakerShares/preprodRewardsV2_generateExpectedResults.sql +++ b/internal/tests/testdata/stakerShares/preprodRewardsV2_generateExpectedResults.sql @@ -12,26 +12,26 @@ SELECT FROM ( SELECT staker, strategy, shares, 0 as strategy_index, transaction_hash, log_index, block_time, block_date, block_number FROM dbt_preprod_holesky_rewards.staker_deposits - where block_date < '2024-12-10' + where block_date < '2024-12-11' UNION ALL -- Subtract m1 & m2 withdrawals SELECT staker, strategy, shares * -1, 0 as strategy_index, transaction_hash, log_index, block_time, block_date, block_number FROM dbt_preprod_holesky_rewards.m1_staker_withdrawals - where block_date < '2024-12-10' + where block_date < '2024-12-11' UNION ALL SELECT staker, strategy, shares * -1, strategy_index, transaction_hash, log_index, block_time, block_date, block_number FROM dbt_preprod_holesky_rewards.m2_staker_withdrawals - where block_date < '2024-12-10' + where block_date < '2024-12-11' UNION all -- Shares in eigenpod are positive or negative, so no need to multiply by -1 SELECT staker, '0xbeac0eeeeeeeeeeeeeeeeeeeeeeeeeeeeeebeac0' as strategy, shares, 0 as strategy_index, transaction_hash, log_index, block_time, block_date, block_number FROM dbt_preprod_holesky_rewards.eigenpod_shares - where block_date < '2024-12-10' + where block_date < '2024-12-11' ) combined_staker_shares ) TO STDOUT WITH DELIMITER ',' CSV HEADER diff --git a/pkg/rewards/10_goldAvsODRewardAmounts.go b/pkg/rewards/10_goldAvsODRewardAmounts.go index 304cacd0..bd5e7180 100644 --- a/pkg/rewards/10_goldAvsODRewardAmounts.go +++ b/pkg/rewards/10_goldAvsODRewardAmounts.go @@ -21,7 +21,7 @@ WITH reward_snapshot_operators AS ( ap.strategy, ap.multiplier, ap.reward_submission_date - FROM {{.activeRewardsTable}} ap + FROM {{.activeODRewardsTable}} ap LEFT JOIN operator_avs_registration_snapshots oar ON ap.avs = oar.avs AND ap.snapshot = oar.snapshot diff --git a/pkg/rewards/11_goldStaging.go b/pkg/rewards/11_goldStaging.go index e932bcc6..677078ae 100644 --- a/pkg/rewards/11_goldStaging.go +++ b/pkg/rewards/11_goldStaging.go @@ -77,24 +77,14 @@ staker_od_rewards AS ( FROM {{.stakerODRewardAmountsTable}} ), avs_od_rewards AS ( - with avs_refund_total_by_operator as ( - select - reward_hash, - snapshot, - token, - avs, - operator, - SUM(avs_tokens) as avs_tokens - FROM {{.avsODRewardAmountsTable}} - group by 1, 2, 3, 4, 5 - ) SELECT DISTINCT + -- We can select DISTINCT here because the avs's tokens are the same for each strategy in the reward hash avs as earner, snapshot, reward_hash, token, avs_tokens as amount - FROM avs_refund_total_by_operator + FROM {{.avsODRewardAmountsTable}} ), combined_rewards AS ( SELECT * FROM operator_rewards diff --git a/pkg/rewards/8_goldOperatorODRewardAmounts.go b/pkg/rewards/8_goldOperatorODRewardAmounts.go index e5f1427a..8ae90773 100644 --- a/pkg/rewards/8_goldOperatorODRewardAmounts.go +++ b/pkg/rewards/8_goldOperatorODRewardAmounts.go @@ -52,6 +52,7 @@ distinct_operators AS ( operator_splits AS ( SELECT dop.*, + COALESCE(oas.split, 1000) / CAST(10000 AS DECIMAL) as split_pct, FLOOR(dop.tokens_per_day_decimal * COALESCE(oas.split, 1000) / CAST(10000 AS DECIMAL)) AS operator_tokens FROM distinct_operators dop LEFT JOIN operator_avs_split_snapshots oas diff --git a/pkg/rewards/9_goldStakerODRewardAmounts.go b/pkg/rewards/9_goldStakerODRewardAmounts.go index 46c1293c..21d4046e 100644 --- a/pkg/rewards/9_goldStakerODRewardAmounts.go +++ b/pkg/rewards/9_goldStakerODRewardAmounts.go @@ -28,7 +28,7 @@ WITH reward_snapshot_operators AS ( AND ap.operator = oar.operator ), --- Step 2: Calculate the total staker split for each operator reward with dynamic split logic +-- Calculate the total staker split for each operator reward with dynamic split logic -- If no split is found, default to 1000 (10%) staker_splits AS ( SELECT @@ -40,20 +40,7 @@ staker_splits AS ( AND rso.avs = oas.avs AND rso.snapshot = oas.snapshot ), - --- Step 3: Filter operators restaked in strategies -_operator_restaked_strategies AS ( - SELECT - ss.* - FROM staker_splits ss - JOIN operator_avs_strategy_snapshots oas - ON ss.operator = oas.operator - AND ss.avs = oas.avs - AND ss.strategy = oas.strategy - AND ss.snapshot = oas.snapshot -), - --- Step 4: Get the stakers that were delegated to the operator for the snapshot +-- Get the stakers that were delegated to the operator for the snapshot staker_delegated_operators AS ( SELECT ors.*, @@ -64,7 +51,7 @@ staker_delegated_operators AS ( AND ors.snapshot = sds.snapshot ), --- Step 5: Get the shares for stakers delegated to the operator +-- Get the shares for stakers delegated to the operator staker_avs_strategy_shares AS ( SELECT sdo.*, @@ -78,15 +65,14 @@ staker_avs_strategy_shares AS ( WHERE sss.shares > 0 AND sdo.multiplier != 0 ), --- Step 6: Calculate the weight of each staker +-- Calculate the weight of each staker staker_weights AS ( SELECT *, SUM(multiplier * shares) OVER (PARTITION BY staker, reward_hash, snapshot) AS staker_weight FROM staker_avs_strategy_shares ), - --- Step 7: Get distinct stakers since their weights are already calculated +-- Get distinct stakers since their weights are already calculated distinct_stakers AS ( SELECT * FROM ( @@ -103,32 +89,28 @@ distinct_stakers AS ( WHERE rn = 1 ORDER BY reward_hash, snapshot, staker ), - --- Step 8: Calculate the sum of all staker weights for each reward and snapshot +-- Calculate the sum of all staker weights for each reward and snapshot staker_weight_sum AS ( SELECT *, SUM(staker_weight) OVER (PARTITION BY reward_hash, snapshot) AS total_weight FROM distinct_stakers ), - --- Step 9: Calculate staker proportion of tokens for each reward and snapshot +-- Calculate staker proportion of tokens for each reward and snapshot staker_proportion AS ( SELECT *, FLOOR((staker_weight / total_weight) * 1000000000000000) / 1000000000000000 AS staker_proportion FROM staker_weight_sum ), - --- Step 10: Calculate the staker reward amounts +-- Calculate the staker reward amounts staker_reward_amounts AS ( SELECT *, FLOOR(staker_proportion * staker_split) AS staker_tokens FROM staker_proportion ) - --- Step 11: Output the final table +-- Output the final table SELECT * FROM staker_reward_amounts ` diff --git a/pkg/rewards/rewardsV2_test.go b/pkg/rewards/rewardsV2_test.go index 2b33fd13..bf3601f3 100644 --- a/pkg/rewards/rewardsV2_test.go +++ b/pkg/rewards/rewardsV2_test.go @@ -75,7 +75,7 @@ func Test_RewardsV2(t *testing.T) { t.Log("Hydrated tables") snapshotDates := []string{ - "2024-12-09", + "2024-12-11", } fmt.Printf("Hydration duration: %v\n", time.Since(testStart))