Skip to content

Commit

Permalink
remove checking ORS in rewards v2
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmcgary committed Dec 11, 2024
1 parent a7e62a8 commit 1179512
Show file tree
Hide file tree
Showing 12 changed files with 27 additions and 54 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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 *,
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion pkg/rewards/10_goldAvsODRewardAmounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 2 additions & 12 deletions pkg/rewards/11_goldStaging.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions pkg/rewards/8_goldOperatorODRewardAmounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 9 additions & 27 deletions pkg/rewards/9_goldStakerODRewardAmounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.*,
Expand All @@ -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.*,
Expand All @@ -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 (
Expand All @@ -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
`

Expand Down
2 changes: 1 addition & 1 deletion pkg/rewards/rewardsV2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 1179512

Please sign in to comment.