Skip to content

Commit 963e0af

Browse files
committed
release: Rewards v2 (#106)
Adds support for the new Rewards V2
2 parents 07b267e + c93a1d0 commit 963e0af

File tree

86 files changed

+4073
-110
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+4073
-110
lines changed

.gitignore

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
/*.sw*
33
*.terraform
44
*.terraform*
5+
*.sql
6+
*.dump
57
/bin
68
/scripts/runLocal
79
sidecar.db*
@@ -30,5 +32,5 @@ node_modules
3032
chart_releases
3133
/snapshots/**/*.sql
3234
/snapshots/**/*.csv
33-
*.sql
34-
*.dump
35+
36+
.env

.testdataVersion

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
e94b8e364dfddd0743746f089f89a3d570751f03
1+
da8f00be49d1447f22934629d9d6819e3d763af9

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ require (
2525
github.com/wealdtech/go-merkletree/v2 v2.6.0
2626
github.com/wk8/go-ordered-map/v2 v2.1.8
2727
go.uber.org/zap v1.27.0
28+
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2
2829
google.golang.org/grpc v1.65.0
2930
gorm.io/driver/postgres v1.5.9
3031
gorm.io/gorm v1.25.10

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,8 @@ golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8T
670670
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
671671
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
672672
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
673+
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 h1:H2TDz8ibqkAF6YGhCdN3jS9O0/s90v0rJh3X/OLHEUk=
674+
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2/go.mod h1:K8+ghG5WaK9qNqU5K3HdILfMLy1f3aNYFI/wnl100a8=
673675
google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE=
674676
google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M=
675677
google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg=

internal/config/config.go

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ package config
33
import (
44
"errors"
55
"fmt"
6-
"github.com/spf13/viper"
76
"strconv"
87
"strings"
8+
"time"
9+
10+
"github.com/spf13/viper"
911
)
1012

1113
type EnvScope string
@@ -29,6 +31,7 @@ const (
2931
Fork_Nile ForkName = "nile"
3032
Fork_Amazon ForkName = "amazon"
3133
Fork_Panama ForkName = "panama"
34+
Fork_Arno ForkName = "arno"
3235

3336
ENV_PREFIX = "SIDECAR"
3437
)
@@ -252,18 +255,21 @@ func (c *Config) GetForkDates() (ForkMap, error) {
252255
Fork_Amazon: "1970-01-01", // Amazon hard fork was never on preprod as we backfilled
253256
Fork_Nile: "2024-08-14", // Last calculation end timestamp was 8-13: https://holesky.etherscan.io/tx/0xb5a6855e88c79312b7c0e1c9f59ae9890b97f157ea27e69e4f0fadada4712b64#eventlog
254257
Fork_Panama: "2024-10-01",
258+
Fork_Arno: "2024-12-11",
255259
}, nil
256260
case Chain_Holesky:
257261
return ForkMap{
258262
Fork_Amazon: "1970-01-01", // Amazon hard fork was never on testnet as we backfilled
259263
Fork_Nile: "2024-08-13", // Last calculation end timestamp was 8-12: https://holesky.etherscan.io/tx/0x5fc81b5ed2a78b017ef313c181d8627737a97fef87eee85acedbe39fc8708c56#eventlog
260264
Fork_Panama: "2024-10-01",
265+
Fork_Arno: "2024-12-13",
261266
}, nil
262267
case Chain_Mainnet:
263268
return ForkMap{
264269
Fork_Amazon: "2024-08-02", // Last calculation end timestamp was 8-01: https://etherscan.io/tx/0x2aff6f7b0132092c05c8f6f41a5e5eeeb208aa0d95ebcc9022d7823e343dd012#eventlog
265270
Fork_Nile: "2024-08-12", // Last calculation end timestamp was 8-11: https://etherscan.io/tx/0x922d29d93c02d189fc2332041f01a80e0007cd7a625a5663ef9d30082f7ef66f#eventlog
266271
Fork_Panama: "2024-10-01",
272+
Fork_Arno: "2025-01-07",
267273
}, nil
268274
}
269275
return nil, errors.New("unsupported chain")
@@ -291,6 +297,23 @@ func (c *Config) GetOperatorRestakedStrategiesStartBlock() uint64 {
291297
return 0
292298
}
293299

300+
func (c *Config) IsRewardsV2EnabledForCutoffDate(cutoffDate string) (bool, error) {
301+
forks, err := c.GetForkDates()
302+
if err != nil {
303+
return false, err
304+
}
305+
cutoffDateTime, err := time.Parse(time.DateOnly, cutoffDate)
306+
if err != nil {
307+
return false, errors.Join(fmt.Errorf("failed to parse cutoff date %s", cutoffDate), err)
308+
}
309+
arnoForkDateTime, err := time.Parse(time.DateOnly, forks[Fork_Arno])
310+
if err != nil {
311+
return false, errors.Join(fmt.Errorf("failed to parse Arno fork date %s", forks[Fork_Arno]), err)
312+
}
313+
314+
return cutoffDateTime.Compare(arnoForkDateTime) >= 0, nil
315+
}
316+
294317
// CanIgnoreIncorrectRewardsRoot returns true if the rewards root can be ignored for the given block number
295318
//
296319
// Due to inconsistencies in the rewards root calculation on testnet, we know that some roots
@@ -306,6 +329,11 @@ func (c *Config) CanIgnoreIncorrectRewardsRoot(blockNumber uint64) bool {
306329
if blockNumber == 2812052 {
307330
return true
308331
}
332+
333+
// ignore rewards-v2 deployment/testing range
334+
if blockNumber >= 2877938 && blockNumber <= 2909856 {
335+
return true
336+
}
309337
case Chain_Holesky:
310338
// roughly 2024-08-01
311339
if blockNumber < 2046020 {

internal/tests/testdata/avsOperators/README.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,24 @@ where
1616
address = '0x135dda560e946695d6f155dacafc6f1f25c1f5af'
1717
and event_name = 'OperatorAVSRegistrationStatusUpdated'
1818
and block_number < 20613003
19-
``
19+
```
20+
21+
## preprod rewardsv2
22+
23+
24+
```sql
25+
select
26+
transaction_hash,
27+
transaction_index,
28+
block_number,
29+
address,
30+
arguments,
31+
event_name,
32+
log_index,
33+
output_data
34+
from transaction_logs
35+
where
36+
address = '0x141d6995556135d4997b2ff72eb443be300353bc'
37+
and event_name = 'OperatorAVSRegistrationStatusUpdated'
38+
and block_number < 2909490
39+
```

internal/tests/testdata/combinedRewards/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,23 @@ select
6969
from dbt_mainnet_ethereum_rewards.rewards_combined
7070
where block_time < '2024-08-20'
7171
```
72+
73+
## preprod rewardsv2
74+
75+
```sql
76+
select
77+
avs,
78+
reward_hash,
79+
token,
80+
amount as amount,
81+
strategy,
82+
strategy_index,
83+
multiplier as multiplier,
84+
start_timestamp::timestamp(6) as start_timestamp,
85+
end_timestamp::timestamp(6) as end_timestamp,
86+
reward_type,
87+
duration,
88+
block_number as block_number
89+
from dbt_preprod_holesky_rewards.rewards_combined
90+
where block_time < '2024-12-13'
91+
```

internal/tests/testdata/fetchExpectedResults.sh

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,28 @@ NETWORK=$1
55
sqlFileName="generateExpectedResults.sql"
66
outputFile="expectedResults.csv"
77

8+
postgresPort=5432
9+
810
if [[ -z $NETWORK ]]; then
911
echo "Usage: $0 <network>"
1012
exit 1
1113
fi
1214

1315
if [[ $NETWORK == "mainnet-reduced" ]]; then
1416
sqlFileName="mainnetReduced_${sqlFileName}"
17+
postgresPort=5434
1518
fi
1619

1720
if [[ $NETWORK == "testnet-reduced" ]]; then
1821
sqlFileName="testnetReduced_${sqlFileName}"
1922
fi
2023

21-
for d in operatorShares; do
24+
if [[ $NETWORK == "preprod-rewardsV2" ]]; then
25+
sqlFileName="preprodRewardsV2_${sqlFileName}"
26+
postgresPort=5435
27+
fi
28+
29+
for d in stakerShareSnapshots; do
2230
echo "Processing directory: $d"
2331
if [[ $d == "7_goldStaging" ]]; then
2432
files=$(ls "./${d}" | grep "_generateExpectedResults_")
@@ -30,12 +38,12 @@ for d in operatorShares; do
3038
sqlFileWithPath="${d}/$f"
3139
outputFileWithPath="${d}/expectedResults_${snapshotDate}.csv"
3240
echo "Generating expected results for ${sqlFileWithPath} to ${outputFileWithPath}"
33-
psql --host localhost --port 5434 --user blocklake --dbname blocklake --password < $sqlFileWithPath > $outputFileWithPath
41+
psql --host localhost --port $postgresPort --user blocklake --dbname blocklake --password < $sqlFileWithPath > $outputFileWithPath
3442
done
3543
else
3644
echo "Generating expected results for $d"
3745
sqlFileWithPath="${d}/${sqlFileName}"
3846
outputFileWithPath="${d}/${outputFile}"
39-
psql --host localhost --port 5434 --user blocklake --dbname blocklake --password < $sqlFileWithPath > $outputFileWithPath
47+
psql --host localhost --port $postgresPort --user blocklake --dbname blocklake --password < $sqlFileWithPath > $outputFileWithPath
4048
fi
4149
done

internal/tests/testdata/operatorAvsRegistrationSnapshots/README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,34 @@ select
8181
from filtered
8282
```
8383

84+
preprod rewardsv2
85+
86+
```sql
87+
with filtered as (
88+
SELECT
89+
lower(t.arguments #>> '{0,Value}') as operator,
90+
lower(t.arguments #>> '{1,Value}') as avs,
91+
case when (t.output_data ->> 'status')::integer = 1 then true else false end as status,
92+
t.transaction_hash,
93+
t.log_index,
94+
b.block_time::timestamp(6),
95+
to_char(b.block_time, 'YYYY-MM-DD') AS block_date,
96+
t.block_number
97+
FROM transaction_logs t
98+
LEFT JOIN blocks b ON t.block_sequence_id = b.id
99+
WHERE t.address = '0x141d6995556135d4997b2ff72eb443be300353bc'
100+
AND t.event_name = 'OperatorAVSRegistrationStatusUpdated'
101+
AND date_trunc('day', b.block_time) < TIMESTAMP '2024-12-13'
102+
)
103+
select
104+
operator,
105+
avs,
106+
status as registered,
107+
log_index,
108+
block_number
109+
from filtered
110+
```
111+
84112
## Expected results
85113

86114
_See `generateExpectedResults.sql`_
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
COPY (
2+
with filtered as (
3+
select * from dbt_preprod_holesky_rewards.operator_avs_status
4+
where block_time < '2024-12-11'
5+
),
6+
marked_statuses AS (
7+
SELECT
8+
operator,
9+
avs,
10+
registered,
11+
block_time,
12+
block_date,
13+
LEAD(block_time) OVER (PARTITION BY operator, avs ORDER BY block_time ASC, log_index ASC) AS next_block_time,
14+
LEAD(registered) OVER (PARTITION BY operator, avs ORDER BY block_time ASC, log_index ASC) AS next_registration_status,
15+
LEAD(block_date) OVER (PARTITION BY operator, avs ORDER BY block_time ASC, log_index ASC) AS next_block_date,
16+
LAG(registered) OVER (PARTITION BY operator, avs ORDER BY block_time ASC, log_index ASC) AS prev_registered,
17+
LAG(block_date) OVER (PARTITION BY operator, avs ORDER BY block_time ASC, log_index ASC) AS prev_block_date
18+
FROM filtered
19+
),
20+
removed_same_day_deregistrations AS (
21+
SELECT * from marked_statuses
22+
WHERE NOT (
23+
(registered = TRUE AND
24+
COALESCE(next_registration_status = FALSE, false) AND
25+
COALESCE(block_date = next_block_date, false)) OR
26+
(registered = FALSE AND
27+
COALESCE(prev_registered = TRUE, false) and
28+
COALESCE(block_date = prev_block_date, false)
29+
)
30+
)
31+
),
32+
registration_periods AS (
33+
SELECT
34+
operator,
35+
avs,
36+
block_time AS start_time,
37+
COALESCE(next_block_time, TIMESTAMP '2024-12-11') AS end_time,
38+
registered
39+
FROM removed_same_day_deregistrations
40+
WHERE registered = TRUE
41+
),
42+
registration_windows_extra as (
43+
SELECT
44+
operator,
45+
avs,
46+
date_trunc('day', start_time) + interval '1' day as start_time,
47+
date_trunc('day', end_time) as end_time
48+
FROM registration_periods
49+
),
50+
operator_avs_registration_windows as (
51+
SELECT * from registration_windows_extra
52+
WHERE start_time != end_time
53+
),
54+
cleaned_records AS (
55+
SELECT * FROM operator_avs_registration_windows
56+
WHERE start_time < end_time
57+
),
58+
final_results as (
59+
SELECT
60+
operator,
61+
avs,
62+
to_char(d, 'YYYY-MM-DD') AS snapshot
63+
FROM cleaned_records
64+
CROSS JOIN generate_series(DATE(start_time), DATE(end_time) - interval '1' day, interval '1' day) AS d
65+
)
66+
select * from final_results
67+
) TO STDOUT WITH DELIMITER ',' CSV HEADER;

0 commit comments

Comments
 (0)