From c33f103abfb91209f51dfb73228ffd6e1f548a7a Mon Sep 17 00:00:00 2001 From: gpsanant Date: Wed, 11 Dec 2024 20:49:51 -0800 Subject: [PATCH 1/5] feat: rewards-v2 pay by snapshots --- .gitignore | 1 + go.mod | 1 + go.sum | 2 + internal/config/config.go | 2 +- pkg/rewards/10_goldAvsODRewardAmounts.go | 13 ++-- pkg/rewards/7_goldActiveODRewards.go | 71 +++++++++++++++++--- pkg/rewards/8_goldOperatorODRewardAmounts.go | 6 +- pkg/rewards/9_goldStakerODRewardAmounts.go | 6 +- pkg/rewards/operatorDirectedRewards.go | 2 +- pkg/rewards/rewardsV2_test.go | 7 ++ 10 files changed, 86 insertions(+), 25 deletions(-) diff --git a/.gitignore b/.gitignore index c367e7a3..58930609 100644 --- a/.gitignore +++ b/.gitignore @@ -33,3 +33,4 @@ chart_releases /snapshots/**/*.sql /snapshots/**/*.csv +.env \ No newline at end of file diff --git a/go.mod b/go.mod index 932ecec8..161a6aea 100644 --- a/go.mod +++ b/go.mod @@ -25,6 +25,7 @@ require ( github.com/wealdtech/go-merkletree/v2 v2.6.0 github.com/wk8/go-ordered-map/v2 v2.1.8 go.uber.org/zap v1.27.0 + golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 google.golang.org/grpc v1.65.0 gorm.io/driver/postgres v1.5.9 gorm.io/gorm v1.25.10 diff --git a/go.sum b/go.sum index c09d6acd..0c8f4b20 100644 --- a/go.sum +++ b/go.sum @@ -670,6 +670,8 @@ golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8T golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 h1:H2TDz8ibqkAF6YGhCdN3jS9O0/s90v0rJh3X/OLHEUk= +golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2/go.mod h1:K8+ghG5WaK9qNqU5K3HdILfMLy1f3aNYFI/wnl100a8= google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M= google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= diff --git a/internal/config/config.go b/internal/config/config.go index a263bb5f..b3cef47e 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -255,7 +255,7 @@ func (c *Config) GetForkDates() (ForkMap, error) { Fork_Amazon: "1970-01-01", // Amazon hard fork was never on preprod as we backfilled Fork_Nile: "2024-08-14", // Last calculation end timestamp was 8-13: https://holesky.etherscan.io/tx/0xb5a6855e88c79312b7c0e1c9f59ae9890b97f157ea27e69e4f0fadada4712b64#eventlog Fork_Panama: "2024-10-01", - Fork_Arno: "2024-12-12", + Fork_Arno: "2024-12-04", }, nil case Chain_Holesky: return ForkMap{ diff --git a/pkg/rewards/10_goldAvsODRewardAmounts.go b/pkg/rewards/10_goldAvsODRewardAmounts.go index 19b5f77e..77fd42dc 100644 --- a/pkg/rewards/10_goldAvsODRewardAmounts.go +++ b/pkg/rewards/10_goldAvsODRewardAmounts.go @@ -14,19 +14,16 @@ WITH reward_snapshot_operators AS ( ap.reward_hash, ap.snapshot AS snapshot, ap.token, - ap.tokens_per_day, - ap.tokens_per_day_decimal, + ap.tokens_per_registered_snapshot, + ap.tokens_per_registered_snapshot_decimal, ap.avs AS avs, ap.operator AS operator, ap.strategy, ap.multiplier, ap.reward_submission_date FROM {{.activeODRewardsTable}} ap - LEFT JOIN operator_avs_registration_snapshots oar - ON ap.avs = oar.avs - AND ap.snapshot = oar.snapshot - AND ap.operator = oar.operator - WHERE oar.avs IS NULL OR oar.operator IS NULL + WHERE + ap.num_registered_snapshots = 0 ), -- Step 2: Dedupe the operator tokens across strategies for each (operator, reward hash, snapshot) @@ -56,7 +53,7 @@ operator_token_sums AS ( token, avs, operator, - SUM(tokens_per_day_decimal) OVER (PARTITION BY reward_hash, snapshot) AS avs_tokens + SUM(tokens_per_registered_snapshot_decimal) OVER (PARTITION BY reward_hash, snapshot) AS avs_tokens FROM distinct_operators ) diff --git a/pkg/rewards/7_goldActiveODRewards.go b/pkg/rewards/7_goldActiveODRewards.go index 902c9438..bc5d3742 100644 --- a/pkg/rewards/7_goldActiveODRewards.go +++ b/pkg/rewards/7_goldActiveODRewards.go @@ -14,7 +14,6 @@ WITH active_rewards_modified AS ( SELECT *, - amount / (duration / 86400) AS tokens_per_day, CAST(@cutoffDate AS TIMESTAMP(6)) AS global_end_inclusive -- Inclusive means we DO USE this day as a snapshot FROM operator_directed_rewards WHERE end_timestamp >= TIMESTAMP '{{.rewardsStart}}' @@ -34,11 +33,12 @@ active_rewards_updated_end_timestamps AS ( */ start_timestamp AS reward_start_exclusive, LEAST(global_end_inclusive, end_timestamp) AS reward_end_inclusive, - tokens_per_day, + amount, token, multiplier, strategy, reward_hash, + duration, global_end_inclusive, block_date AS reward_submission_date FROM active_rewards_modified @@ -53,12 +53,13 @@ active_rewards_updated_start_timestamps AS ( ap.reward_end_inclusive, ap.token, -- We use floor to ensure we are always underesimating total tokens per day - FLOOR(ap.tokens_per_day) AS tokens_per_day_decimal, + FLOOR(ap.amount) AS amount_decimal, -- Round down to 15 sigfigs for double precision, ensuring know errouneous round up or down - ap.tokens_per_day * ((POW(10, 15) - 1) / POW(10, 15)) AS tokens_per_day, + ap.amount * ((POW(10, 15) - 1) / POW(10, 15)) AS amount, ap.multiplier, ap.strategy, ap.reward_hash, + ap.duration, ap.global_end_inclusive, ap.reward_submission_date FROM active_rewards_updated_end_timestamps ap @@ -69,10 +70,11 @@ active_rewards_updated_start_timestamps AS ( ap.operator, ap.reward_end_inclusive, ap.token, - ap.tokens_per_day, + ap.amount, ap.multiplier, ap.strategy, ap.reward_hash, + ap.duration, ap.global_end_inclusive, ap.reward_start_exclusive, ap.reward_submission_date @@ -100,22 +102,73 @@ exploded_active_range_rewards AS ( ) AS day ), --- Step 7: Prepare final active rewards -active_rewards_final AS ( +-- Step 7: Prepare cleaned active rewards +active_rewards_cleaned AS ( SELECT avs, operator, CAST(day AS DATE) AS snapshot, token, - tokens_per_day, - tokens_per_day_decimal, + amount, + amount_decimal, multiplier, strategy, + duration, reward_hash, reward_submission_date FROM exploded_active_range_rewards -- Remove snapshots on the start day WHERE day != reward_start_exclusive +), + +-- Step 8: Dedupe the active rewards by (avs, snapshot, operator, reward_hash) +active_rewards_reduced_deduped AS ( + SELECT DISTINCT avs, snapshot, operator, reward_hash + FROM active_rewards_cleaned +), + +-- Step 9: Divide by the number of snapshots that the operator was registered +op_avs_num_registered_snapshots AS ( + SELECT + ar.reward_hash, + ar.operator, + COUNT(*) AS num_registered_snapshots + FROM active_rewards_reduced_deduped ar + JOIN operator_avs_registration_snapshots oar + ON + ar.avs = oar.avs + AND ar.snapshot = oar.snapshot + AND ar.operator = oar.operator + GROUP BY ar.reward_hash, ar.operator +), + +-- Step 9: Divide amount to pay by the number of snapshots that the operator was registered +active_rewards_with_registered_snapshots AS ( + SELECT + arc.*, + COALESCE(nrs.num_registered_snapshots, 0) as num_registered_snapshots + FROM active_rewards_cleaned arc + LEFT JOIN op_avs_num_registered_snapshots nrs + ON + arc.reward_hash = nrs.reward_hash + AND arc.operator = nrs.operator +), + +-- Step 10: Divide amount to pay by the number of snapshots that the operator was registered +active_rewards_final AS ( + SELECT + ar.*, + CASE + -- If the operator was not registered for any snapshots, just get regular tokens per day to refund the AVS + WHEN ar.num_registered_snapshots = 0 THEN ar.amount_decimal / (duration / 86400) + ELSE ar.amount_decimal / ar.num_registered_snapshots + END AS tokens_per_registered_snapshot_decimal, + CASE + -- If the operator was not registered for any snapshots, just get regular tokens per day to refund the AVS + WHEN ar.num_registered_snapshots = 0 THEN ar.amount / (duration / 86400) + ELSE ar.amount / ar.num_registered_snapshots + END AS tokens_per_registered_snapshot + FROM active_rewards_with_registered_snapshots ar ) SELECT * FROM active_rewards_final diff --git a/pkg/rewards/8_goldOperatorODRewardAmounts.go b/pkg/rewards/8_goldOperatorODRewardAmounts.go index 5bb9718f..52d3684b 100644 --- a/pkg/rewards/8_goldOperatorODRewardAmounts.go +++ b/pkg/rewards/8_goldOperatorODRewardAmounts.go @@ -14,8 +14,8 @@ WITH reward_snapshot_operators AS ( ap.reward_hash, ap.snapshot AS snapshot, ap.token, - ap.tokens_per_day, - ap.tokens_per_day_decimal, + ap.tokens_per_registered_snapshot, + ap.tokens_per_registered_snapshot_decimal, ap.avs AS avs, ap.operator AS operator, ap.strategy, @@ -53,7 +53,7 @@ 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 + FLOOR(dop.tokens_per_registered_snapshot_decimal * COALESCE(oas.split, 1000) / CAST(10000 AS DECIMAL)) AS operator_tokens FROM distinct_operators dop LEFT JOIN operator_avs_split_snapshots oas ON dop.operator = oas.operator diff --git a/pkg/rewards/9_goldStakerODRewardAmounts.go b/pkg/rewards/9_goldStakerODRewardAmounts.go index 5956f39c..37d7ca2e 100644 --- a/pkg/rewards/9_goldStakerODRewardAmounts.go +++ b/pkg/rewards/9_goldStakerODRewardAmounts.go @@ -14,8 +14,8 @@ WITH reward_snapshot_operators AS ( ap.reward_hash, ap.snapshot AS snapshot, ap.token, - ap.tokens_per_day, - ap.tokens_per_day_decimal, + ap.tokens_per_registered_snapshot, + ap.tokens_per_registered_snapshot_decimal, ap.avs AS avs, ap.operator AS operator, ap.strategy, @@ -33,7 +33,7 @@ WITH reward_snapshot_operators AS ( staker_splits AS ( SELECT rso.*, - rso.tokens_per_day_decimal - FLOOR(rso.tokens_per_day_decimal * COALESCE(oas.split, 1000) / CAST(10000 AS DECIMAL)) AS staker_split + rso.tokens_per_registered_snapshot_decimal - FLOOR(rso.tokens_per_registered_snapshot_decimal * COALESCE(oas.split, 1000) / CAST(10000 AS DECIMAL)) AS staker_split FROM reward_snapshot_operators rso LEFT JOIN operator_avs_split_snapshots oas ON rso.operator = oas.operator diff --git a/pkg/rewards/operatorDirectedRewards.go b/pkg/rewards/operatorDirectedRewards.go index 9cc7d896..de604802 100644 --- a/pkg/rewards/operatorDirectedRewards.go +++ b/pkg/rewards/operatorDirectedRewards.go @@ -22,7 +22,7 @@ const operatorDirectedRewardsQuery = ` TO_CHAR(b.block_time, 'YYYY-MM-DD') AS block_date FROM operator_directed_reward_submissions AS odrs JOIN blocks AS b ON(b.number = odrs.block_number) - WHERE b.block_time < TIMESTAMP '{{.cutoffDate}}' + WHERE b.block_time <= TIMESTAMP '{{.cutoffDate}}' ) select avs, diff --git a/pkg/rewards/rewardsV2_test.go b/pkg/rewards/rewardsV2_test.go index cd890901..28b5d8d1 100644 --- a/pkg/rewards/rewardsV2_test.go +++ b/pkg/rewards/rewardsV2_test.go @@ -2,6 +2,7 @@ package rewards import ( "fmt" + "strings" "testing" "time" @@ -210,6 +211,12 @@ func Test_RewardsV2(t *testing.T) { assert.Nil(t, err) t.Logf("Gold staging rows for snapshot %s: %d", snapshotDate, len(goldRows)) + for i, row := range goldRows { + if strings.EqualFold(row.RewardHash, strings.ToLower("0xB38AB57E8E858F197C07D0CDF61F34EB07C3D0FC58390417DDAD0BF528681909")) { + t.Logf("%d: %s %s %s %s %s", i, row.Earner, row.Snapshot.String(), row.RewardHash, row.Token, row.Amount) + } + // t.Logf("%d: %s %s %s %s %s", i, row.Earner, row.Snapshot.String(), row.RewardHash, row.Token, row.Amount) + } fmt.Printf("Total duration for rewards compute %s: %v\n", snapshotDate, time.Since(snapshotStartTime)) testStart = time.Now() From 54734c848412a87eb418584fcc8595b97edaeaf0 Mon Sep 17 00:00:00 2001 From: Yash Patil <40046473+ypatil12@users.noreply.github.com> Date: Thu, 12 Dec 2024 11:51:26 -0500 Subject: [PATCH 2/5] chore: use decimal everywhere --- pkg/rewards/10_goldAvsODRewardAmounts.go | 1 - pkg/rewards/7_goldActiveODRewards.go | 18 +++++------------- pkg/rewards/9_goldStakerODRewardAmounts.go | 1 - 3 files changed, 5 insertions(+), 15 deletions(-) diff --git a/pkg/rewards/10_goldAvsODRewardAmounts.go b/pkg/rewards/10_goldAvsODRewardAmounts.go index 77fd42dc..2fe6d76f 100644 --- a/pkg/rewards/10_goldAvsODRewardAmounts.go +++ b/pkg/rewards/10_goldAvsODRewardAmounts.go @@ -14,7 +14,6 @@ WITH reward_snapshot_operators AS ( ap.reward_hash, ap.snapshot AS snapshot, ap.token, - ap.tokens_per_registered_snapshot, ap.tokens_per_registered_snapshot_decimal, ap.avs AS avs, ap.operator AS operator, diff --git a/pkg/rewards/7_goldActiveODRewards.go b/pkg/rewards/7_goldActiveODRewards.go index bc5d3742..e47582a8 100644 --- a/pkg/rewards/7_goldActiveODRewards.go +++ b/pkg/rewards/7_goldActiveODRewards.go @@ -52,10 +52,8 @@ active_rewards_updated_start_timestamps AS ( COALESCE(MAX(g.snapshot), ap.reward_start_exclusive) AS reward_start_exclusive, ap.reward_end_inclusive, ap.token, - -- We use floor to ensure we are always underesimating total tokens per day + -- We use floor to ensure we are always underestimating total tokens per day FLOOR(ap.amount) AS amount_decimal, - -- Round down to 15 sigfigs for double precision, ensuring know errouneous round up or down - ap.amount * ((POW(10, 15) - 1) / POW(10, 15)) AS amount, ap.multiplier, ap.strategy, ap.reward_hash, @@ -70,7 +68,7 @@ active_rewards_updated_start_timestamps AS ( ap.operator, ap.reward_end_inclusive, ap.token, - ap.amount, + ap.amount, ap.multiplier, ap.strategy, ap.reward_hash, @@ -109,7 +107,6 @@ active_rewards_cleaned AS ( operator, CAST(day AS DATE) AS snapshot, token, - amount, amount_decimal, multiplier, strategy, @@ -142,7 +139,7 @@ op_avs_num_registered_snapshots AS ( GROUP BY ar.reward_hash, ar.operator ), --- Step 9: Divide amount to pay by the number of snapshots that the operator was registered +-- Step 10: Divide amount to pay by the number of snapshots that the operator was registered active_rewards_with_registered_snapshots AS ( SELECT arc.*, @@ -154,7 +151,7 @@ active_rewards_with_registered_snapshots AS ( AND arc.operator = nrs.operator ), --- Step 10: Divide amount to pay by the number of snapshots that the operator was registered +-- Step 11: Divide amount to pay by the number of snapshots that the operator was registered active_rewards_final AS ( SELECT ar.*, @@ -162,12 +159,7 @@ active_rewards_final AS ( -- If the operator was not registered for any snapshots, just get regular tokens per day to refund the AVS WHEN ar.num_registered_snapshots = 0 THEN ar.amount_decimal / (duration / 86400) ELSE ar.amount_decimal / ar.num_registered_snapshots - END AS tokens_per_registered_snapshot_decimal, - CASE - -- If the operator was not registered for any snapshots, just get regular tokens per day to refund the AVS - WHEN ar.num_registered_snapshots = 0 THEN ar.amount / (duration / 86400) - ELSE ar.amount / ar.num_registered_snapshots - END AS tokens_per_registered_snapshot + END AS tokens_per_registered_snapshot_decimal FROM active_rewards_with_registered_snapshots ar ) diff --git a/pkg/rewards/9_goldStakerODRewardAmounts.go b/pkg/rewards/9_goldStakerODRewardAmounts.go index 37d7ca2e..f2f4f94e 100644 --- a/pkg/rewards/9_goldStakerODRewardAmounts.go +++ b/pkg/rewards/9_goldStakerODRewardAmounts.go @@ -14,7 +14,6 @@ WITH reward_snapshot_operators AS ( ap.reward_hash, ap.snapshot AS snapshot, ap.token, - ap.tokens_per_registered_snapshot, ap.tokens_per_registered_snapshot_decimal, ap.avs AS avs, ap.operator AS operator, From a2dce496e18ec5536eeb8247e442deae289c679d Mon Sep 17 00:00:00 2001 From: Sean McGary Date: Thu, 12 Dec 2024 11:08:33 -0600 Subject: [PATCH 3/5] Update preprod test data update query --- .../tests/testdata/combinedRewards/README.md | 2 +- .../README.md | 2 +- .../README.md | 44 +++++++++++-------- .../operatorRestakedStrategies/README.md | 2 +- .../testdata/operatorShareSnapshots/README.md | 2 +- .../tests/testdata/operatorShares/README.md | 4 +- .../stakerDelegationSnapshots/README.md | 2 +- .../testdata/stakerShareSnapshots/README.md | 2 +- .../tests/testdata/stakerShares/README.md | 36 +++++++-------- pkg/rewards/rewardsV2_test.go | 2 +- 10 files changed, 53 insertions(+), 45 deletions(-) diff --git a/internal/tests/testdata/combinedRewards/README.md b/internal/tests/testdata/combinedRewards/README.md index a06edf0f..e02385b1 100644 --- a/internal/tests/testdata/combinedRewards/README.md +++ b/internal/tests/testdata/combinedRewards/README.md @@ -87,5 +87,5 @@ select duration, block_number as block_number from dbt_preprod_holesky_rewards.rewards_combined -where block_time < '2024-12-10' +where block_time < '2024-12-13' ``` diff --git a/internal/tests/testdata/operatorAvsRegistrationSnapshots/README.md b/internal/tests/testdata/operatorAvsRegistrationSnapshots/README.md index 30a4f29d..ed331621 100644 --- a/internal/tests/testdata/operatorAvsRegistrationSnapshots/README.md +++ b/internal/tests/testdata/operatorAvsRegistrationSnapshots/README.md @@ -98,7 +98,7 @@ FROM transaction_logs t LEFT JOIN blocks b ON t.block_sequence_id = b.id WHERE t.address = '0x141d6995556135d4997b2ff72eb443be300353bc' AND t.event_name = 'OperatorAVSRegistrationStatusUpdated' - AND date_trunc('day', b.block_time) < TIMESTAMP '2024-12-10' + AND date_trunc('day', b.block_time) < TIMESTAMP '2024-12-13' ) select operator, diff --git a/internal/tests/testdata/operatorDirectedRewardSubmissions/README.md b/internal/tests/testdata/operatorDirectedRewardSubmissions/README.md index 7d549696..1bd489dd 100644 --- a/internal/tests/testdata/operatorDirectedRewardSubmissions/README.md +++ b/internal/tests/testdata/operatorDirectedRewardSubmissions/README.md @@ -2,32 +2,36 @@ ```sql WITH strategies AS ( - SELECT - tl.*, - output_data->'operatorDirectedRewardsSubmission'->>'token' as token, + SELECT + tl.*, + lower(arguments #>> '{2, Value}') as reward_hash, + output_data->'operatorDirectedRewardsSubmission'->>'token' as token, output_data->'operatorDirectedRewardsSubmission'->>'duration' as duration, output_data->'operatorDirectedRewardsSubmission'->>'startTimestamp' as start_timestamp, strategy_data, strategy_idx - 1 as strategy_idx -- Subtract 1 for 0-based indexing - FROM transaction_logs as tl, - jsonb_array_elements(output_data->'operatorDirectedRewardsSubmission'->'strategiesAndMultipliers') - WITH ORDINALITY AS t(strategy_data, strategy_idx) - where +FROM transaction_logs as tl, + jsonb_array_elements(output_data->'operatorDirectedRewardsSubmission'->'strategiesAndMultipliers') +WITH ORDINALITY AS t(strategy_data, strategy_idx) +where address = '0xb22ef643e1e067c994019a4c19e403253c05c2b0' - and event_name = 'OperatorDirectedAVSRewardsSubmissionCreated' -), -operators AS ( - SELECT + and event_name = 'OperatorDirectedAVSRewardsSubmissionCreated' + ), + operators AS ( +SELECT + lower(arguments #>> '{2, Value}') as reward_hash, operator_data, + operator_data->>'operator' as operator, output_data->'operatorDirectedRewardsSubmission' as rewards_submission, operator_idx - 1 as operator_idx -- Subtract 1 to make it 0-based indexing - FROM transaction_logs, - jsonb_array_elements(output_data->'operatorDirectedRewardsSubmission'->'operatorRewards') - WITH ORDINALITY AS t(operator_data, operator_idx) - where +FROM transaction_logs, + jsonb_array_elements(output_data->'operatorDirectedRewardsSubmission'->'operatorRewards') +WITH ORDINALITY AS t(operator_data, operator_idx) +where address = '0xb22ef643e1e067c994019a4c19e403253c05c2b0' - and event_name = 'OperatorDirectedAVSRewardsSubmissionCreated' -) + and event_name = 'OperatorDirectedAVSRewardsSubmissionCreated' + ), + joined_data as ( SELECT lower(arguments #>> '{1, Value}') as avs, lower(arguments #>> '{2, Value}') as reward_hash, @@ -45,5 +49,9 @@ SELECT transaction_hash, log_index FROM strategies -CROSS JOIN operators; + inner join operators on( + strategies.reward_hash = operators.reward_hash + ) + ) +select * from joined_data ``` diff --git a/internal/tests/testdata/operatorRestakedStrategies/README.md b/internal/tests/testdata/operatorRestakedStrategies/README.md index 796fc641..24d9d73c 100644 --- a/internal/tests/testdata/operatorRestakedStrategies/README.md +++ b/internal/tests/testdata/operatorRestakedStrategies/README.md @@ -54,7 +54,7 @@ select avs_directory_address from operator_restaked_strategies where avs_directory_address = '0x141d6995556135d4997b2ff72eb443be300353bc' -and block_time < '2024-12-10' +and block_time < '2024-12-13' ``` ## Expected results diff --git a/internal/tests/testdata/operatorShareSnapshots/README.md b/internal/tests/testdata/operatorShareSnapshots/README.md index 71439e7f..3b6165b8 100644 --- a/internal/tests/testdata/operatorShareSnapshots/README.md +++ b/internal/tests/testdata/operatorShareSnapshots/README.md @@ -38,7 +38,7 @@ preprod-rewardsV2 select * from dbt_preprod_holesky_rewards.operator_shares -where block_time < '2024-12-10' +where block_time < '2024-12-13' ``` ## Expected results diff --git a/internal/tests/testdata/operatorShares/README.md b/internal/tests/testdata/operatorShares/README.md index e3d05074..b8c5cfc8 100644 --- a/internal/tests/testdata/operatorShares/README.md +++ b/internal/tests/testdata/operatorShares/README.md @@ -87,12 +87,12 @@ SELECT FROM ( SELECT operator, strategy, shares, transaction_hash, log_index, block_time, block_date, block_number FROM dbt_testnet_holesky_rewards.operator_share_increases - where block_date < '2024-12-10' + where block_date < '2024-12-13' UNION ALL SELECT operator, strategy, shares * -1 AS shares, transaction_hash, log_index, block_time, block_date, block_number FROM dbt_testnet_holesky_rewards.operator_share_decreases - where block_date < '2024-12-10' + where block_date < '2024-12-13' ) combined_shares ``` diff --git a/internal/tests/testdata/stakerDelegationSnapshots/README.md b/internal/tests/testdata/stakerDelegationSnapshots/README.md index 92c095f6..96a59a5b 100644 --- a/internal/tests/testdata/stakerDelegationSnapshots/README.md +++ b/internal/tests/testdata/stakerDelegationSnapshots/README.md @@ -61,7 +61,7 @@ FROM ( UNION ALL SELECT *, 'delegations' AS src FROM dbt_preprod_holesky_rewards.staker_delegations ) as delegations_combined -where block_time < '2024-12-10' +where block_time < '2024-12-13' ``` diff --git a/internal/tests/testdata/stakerShareSnapshots/README.md b/internal/tests/testdata/stakerShareSnapshots/README.md index 5904126c..a805cee2 100644 --- a/internal/tests/testdata/stakerShareSnapshots/README.md +++ b/internal/tests/testdata/stakerShareSnapshots/README.md @@ -62,7 +62,7 @@ select block_date, block_number from dbt_preprod_holesky_rewards.staker_shares -where block_time < '2024-12-10' +where block_time < '2024-12-13' ``` ## Expected results diff --git a/internal/tests/testdata/stakerShares/README.md b/internal/tests/testdata/stakerShares/README.md index cb87fa63..468f48d2 100644 --- a/internal/tests/testdata/stakerShares/README.md +++ b/internal/tests/testdata/stakerShares/README.md @@ -131,28 +131,28 @@ SELECT block_date, block_number FROM ( - SELECT staker, strategy, shares, 0 as strategy_index, transaction_hash, log_index, block_time, block_date, block_number - FROM dbt_mainnet_ethereum_rewards.staker_deposits - where block_date < '2024-08-20' + 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-13' - UNION ALL + 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_mainnet_ethereum_rewards.m1_staker_withdrawals - where block_date < '2024-08-20' + -- 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-13' - UNION ALL + UNION ALL - SELECT staker, strategy, shares * -1, strategy_index, transaction_hash, log_index, block_time, block_date, block_number - FROM dbt_mainnet_ethereum_rewards.m2_staker_withdrawals - where block_date < '2024-08-20' + 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-13' - UNION all + 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_mainnet_ethereum_rewards.eigenpod_shares - where block_date < '2024-08-20' -) combined_staker_shares + -- 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-13' + ) combined_staker_shares ``` diff --git a/pkg/rewards/rewardsV2_test.go b/pkg/rewards/rewardsV2_test.go index 28b5d8d1..e1316013 100644 --- a/pkg/rewards/rewardsV2_test.go +++ b/pkg/rewards/rewardsV2_test.go @@ -73,7 +73,7 @@ func Test_RewardsV2(t *testing.T) { t.Log("Hydrated tables") snapshotDates := []string{ - "2024-12-12", + "2024-12-14", } fmt.Printf("Hydration duration: %v\n", time.Since(testStart)) From 1a170791d3042cb88c0be4026a1b065914ec8968 Mon Sep 17 00:00:00 2001 From: Sean McGary Date: Thu, 12 Dec 2024 11:38:03 -0600 Subject: [PATCH 4/5] Updated testdata version to a2dce496e18ec5536eeb8247e442deae289c679d --- .testdataVersion | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.testdataVersion b/.testdataVersion index 62872b9f..032314c4 100644 --- a/.testdataVersion +++ b/.testdataVersion @@ -1 +1 @@ -1490a0e18dd51ffbb59209ca9cf6513268af21f5 \ No newline at end of file +a2dce496e18ec5536eeb8247e442deae289c679d \ No newline at end of file From 419e9b8fa202eeed86ee7598cdd4e67387d1e1d9 Mon Sep 17 00:00:00 2001 From: gpsanant Date: Thu, 12 Dec 2024 09:59:52 -0800 Subject: [PATCH 5/5] fix: assorted --- pkg/postgres/postgres.go | 3 ++- pkg/rewards/8_goldOperatorODRewardAmounts.go | 1 - pkg/rewards/rewardsV2_test.go | 3 ++- scripts/downloadTestData.sh | 1 + 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/pkg/postgres/postgres.go b/pkg/postgres/postgres.go index 44df42d4..7cf0832c 100644 --- a/pkg/postgres/postgres.go +++ b/pkg/postgres/postgres.go @@ -3,6 +3,8 @@ package postgres import ( "database/sql" "fmt" + "regexp" + "github.com/Layr-Labs/sidecar/internal/config" "github.com/Layr-Labs/sidecar/internal/tests" "github.com/Layr-Labs/sidecar/pkg/postgres/migrations" @@ -11,7 +13,6 @@ import ( "gorm.io/driver/postgres" "gorm.io/gorm" "gorm.io/gorm/logger" - "regexp" ) type PostgresConfig struct { diff --git a/pkg/rewards/8_goldOperatorODRewardAmounts.go b/pkg/rewards/8_goldOperatorODRewardAmounts.go index 52d3684b..f3ec3c7c 100644 --- a/pkg/rewards/8_goldOperatorODRewardAmounts.go +++ b/pkg/rewards/8_goldOperatorODRewardAmounts.go @@ -14,7 +14,6 @@ WITH reward_snapshot_operators AS ( ap.reward_hash, ap.snapshot AS snapshot, ap.token, - ap.tokens_per_registered_snapshot, ap.tokens_per_registered_snapshot_decimal, ap.avs AS avs, ap.operator AS operator, diff --git a/pkg/rewards/rewardsV2_test.go b/pkg/rewards/rewardsV2_test.go index e1316013..599c990a 100644 --- a/pkg/rewards/rewardsV2_test.go +++ b/pkg/rewards/rewardsV2_test.go @@ -212,7 +212,8 @@ func Test_RewardsV2(t *testing.T) { t.Logf("Gold staging rows for snapshot %s: %d", snapshotDate, len(goldRows)) for i, row := range goldRows { - if strings.EqualFold(row.RewardHash, strings.ToLower("0xB38AB57E8E858F197C07D0CDF61F34EB07C3D0FC58390417DDAD0BF528681909")) { + if strings.EqualFold(row.RewardHash, strings.ToLower("0xB38AB57E8E858F197C07D0CDF61F34EB07C3D0FC58390417DDAD0BF528681909")) && + strings.EqualFold(row.Earner, strings.ToLower("0xaFF71569D30ED876987088a62E0EA881EBc761E6")) { t.Logf("%d: %s %s %s %s %s", i, row.Earner, row.Snapshot.String(), row.RewardHash, row.Token, row.Amount) } // t.Logf("%d: %s %s %s %s %s", i, row.Earner, row.Snapshot.String(), row.RewardHash, row.Token, row.Amount) diff --git a/scripts/downloadTestData.sh b/scripts/downloadTestData.sh index 2b82e230..0951bfbb 100755 --- a/scripts/downloadTestData.sh +++ b/scripts/downloadTestData.sh @@ -16,4 +16,5 @@ if [[ -z $version ]]; then exit 1 fi echo "Downloading testdata version $dataUrl" + curl -L $dataUrl | tar xvz -C ./