Skip to content

Commit

Permalink
Setup gold table generation
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmcgary committed Oct 24, 2024
1 parent 34bf438 commit 1c5c97c
Show file tree
Hide file tree
Showing 15 changed files with 498 additions and 547 deletions.
8 changes: 8 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ type Environment int

type Chain string

func (c Chain) String() string {
return string(c)
}

type ForkName string

const (
Expand All @@ -24,6 +28,7 @@ const (

Fork_Nile ForkName = "nile"
Fork_Amazon ForkName = "amazon"
Fork_Panama ForkName = "panama"

ENV_PREFIX = "SIDECAR"
)
Expand Down Expand Up @@ -235,16 +240,19 @@ func (c *Config) GetForkDates() (ForkMap, error) {
return ForkMap{
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",
}, nil
case Chain_Holesky:
return ForkMap{
Fork_Amazon: "1970-01-01", // Amazon hard fork was never on testnet as we backfilled
Fork_Nile: "2024-08-13", // Last calculation end timestamp was 8-12: https://holesky.etherscan.io/tx/0x5fc81b5ed2a78b017ef313c181d8627737a97fef87eee85acedbe39fc8708c56#eventlog
Fork_Panama: "2024-10-01",
}, nil
case Chain_Mainnet:
return ForkMap{
Fork_Amazon: "2024-08-02", // Last calculation end timestamp was 8-01: https://etherscan.io/tx/0x2aff6f7b0132092c05c8f6f41a5e5eeeb208aa0d95ebcc9022d7823e343dd012#eventlog
Fork_Nile: "2024-08-12", // Last calculation end timestamp was 8-11: https://etherscan.io/tx/0x922d29d93c02d189fc2332041f01a80e0007cd7a625a5663ef9d30082f7ef66f#eventlog
Fork_Panama: "2024-10-01",
}, nil
}
return nil, errors.New("unsupported chain")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func (m *Migration) Up(db *sql.DB, grm *gorm.DB) error {
amount numeric not null,
strategy varchar not null,
strategy_index integer not null,
multiplier numeric not null,
multiplier numeric(78) not null,
start_timestamp timestamp with time zone not null,
end_timestamp timestamp with time zone not null,
duration bigint not null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func (m *Migration) Up(db *sql.DB, grm *gorm.DB) error {
amount numeric not null,
strategy varchar not null,
strategy_index integer not null,
multiplier numeric not null,
multiplier numeric(78) not null,
start_timestamp timestamp with time zone not null,
end_timestamp timestamp with time zone not null,
duration integer,
Expand Down
220 changes: 220 additions & 0 deletions internal/postgres/migrations/202410241539_goldTables/up.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
package _202410241539_goldTables

import (
"database/sql"
"github.com/Layr-Labs/go-sidecar/internal/config"
"github.com/Layr-Labs/go-sidecar/internal/storage"
"gorm.io/gorm"
)

type Migration struct {
}

var exludedAddresses = map[config.Chain][]string{
config.Chain_Preprod: []string{},
config.Chain_Holesky: []string{},
config.Chain_Mainnet: []string{
"0x3d4eec9f015c9016f5142055a965188d17bba06f",
"0x56458b6686a033476a9472e6917fca33ce2ba4fa",
"0xf1dfec3a799a25b9bf0911b03401e01d63915574",
"0xcc05239823c0873cef85c02f3ba58d0e8398e338",
"0x8440769d3b4cbb7ef5b04b127213b22dea23a82f",
"0x35563df2a9ca8f973cc9670dd0ea15ae60b3dbd3",
"0xcdb68cfc19a9808fd549b8b8506da0dbd5935ef4",
"0x49aff6e3baf509bfb6f151df159889feeb91f3a0",
"0x7ff1b597258e67520e7c570534d6c0955f696c4f",
"0x02179f4af1d7ea53841e3a2230375801ab3cc2f9",
"0xba59853cd3921550ae0773bb648543d138fc205a",
"0xca2d1d2b7cf448dbfc8888addb9008d71049561f",
"0xbc57586af1eaa69732d27a9d9901c6926eb811b7",
"0xf926ce2998b8c87e8b758ae46b5b4ad043f9a299",
"0x97c0551954040e958c81444c06c8543cdee64a73",
"0x8264312120aaba43adff803829e82986149d27ae",
"0x94c6326a478c1eca0fe09a07754eab89a547e4eb",
"0x6af265e3741817c6ad4bdad82d3d8976ac9bc3cf",
"0x26516df208cc2f71ad21e31f8725043ae08180b0",
"0xe2ff36e97afc1c0f5688d0ff76e7441acb0e68d7",
"0x64bd86ed5cbe443bdeda20ecfaab15ea66119603",
"0x2da4aa21033da104df6b58eaa24821be629756ae",
"0x0db954cf3399c6cfc8f8e1ba7b0f1cd97ccfcee4",
"0xda02bd9b9bb963dc3ad7f72b3648e380aba36448",
"0x748b6007c1f4fd09258fc0530cb099bf2d9bf4d1",
"0x774a78488b3aae1d8ffecd8852adb59fa9f4e0ff",
"0x33d2a6cfcd67cc62625921105f8bf052d97c29fd",
"0x6e3e0e5f8dc4c90a7382664e3db63a42b80eb9d7",
"0xe7d40d9a77caddd8e8b4b484ed14c42f3b8d763a",
"0x321e71e7ff8ccc9e7f1e7377b6546996bfccc313",
"0xd1192457d3e392a05031aa33e6efbda3aad45c53",
"0xbf0aaf43144eca99503860d8c5ac16e0875184f6",
"0xa2ed4478e543ce5071ab4bbfcc27bc4b68ed983a",
"0xe9215566641932c6429a66e6c4397ecb00915996",
"0xa743c746c59bcb5e5305af71462452d75403f353",
"0x7643ac4c159f6e36d1d20c3b843009fea577dbff",
"0xc562e53262633effbf0da533e56a792777a2b6c5",
"0xfade4c25ded89f5a0071dd44d4b3735e703c4b46",
"0x43667652452e0c5ea936071853f2e78b82d2d902",
"0x3750a7a3be3c3d4c0aa32282eeb3b64a4b35eb93",
"0xd09dfe5bc2b11db2f3aca6b7c977b635e9bfd2e0",
"0x0a4715759339c0f23d455432d8c2bc36abe749cf",
"0x86bc3b961fb5acda1a60a3ddd13e47b8b8bf5c4c",
"0x56aeebc8fbf95e7b8c572a74efb40ea9dc8ba78e",
"0x9de3c8c0bff9b63c2d579f97e977912b99135343",
"0x140fd7285bfc7bc5dc6e74fc93253d2ee65e9c69",
"0x6295bbc8ab28c51b5878798976d38ade1017af86",
"0x4a836a3fc5d75002abf3ab3118609b269f43f677",
},
}

func (m *Migration) Up(db *sql.DB, grm *gorm.DB) error {
queries := []string{
`create table if not exists excluded_addresses (
address varchar not null PRIMARY KEY,
network varchar not null,
description varchar,
created_at timestamp with timezone default currrent_timestamp,
updated_at timestamp with timezone,
deleted_at timestamp with timezone,
unique(address)
)`,
`create table if not exists gold_1_active_rewards (
avs varchar not null,
snapshot date not null,
token varchar not null,
tokens_per_day double precision not null,
tokens_per_day_decimal numeric not null,
multiplier numeric(78) not null,
strategy varchar not null,
reward_hash varchar not null,
reward_type varchar not null,
reward_submission_date varchar not null
)`,
`create table if not exists gold_2_staker_reward_amounts (
reward_hash varchar not null,
snapshot date NOT NULL,
token varchar not null,
tokens_per_day double precision not null,
tokens_per_day_decimal numeric not null,
avs varchar not null,
strategy varchar not null,
multiplier numeric(78) not null,
reward_type varchar not null,
reward_submission_date varchar NOT NULL,
operator varchar not null,
staker varchar not null,
shares numeric not null,
staker_weight numeric not null,
rn bigint not null,
total_weight numeric not null,
staker_proportion numeric not null,
total_staker_operator_payout numeric not null,
operator_tokens numeric not null,
staker_tokens numeric not null
)`,
`create table if not exists gold_3_operator_reward_amounts (
reward_hash varchar not null,
snapshot date NOT NULL,
token varchar not null,
tokens_per_day double precision not null,
avs varchar not null,
strategy varchar not null,
multiplier numeric(78) not null,
reward_type varchar not null,
operator varchar not null,
operator_tokens numeric not null,
rn bigint NOT NULL
)`,
`create table if not exists gold_4_rewards_for_all (
reward_hash varchar not null,
snapshot date NOT NULL,
token varchar not null,
tokens_per_day double precision not null,
avs varchar not null,
strategy varchar not null,
multiplier numeric(78) not null,
reward_type varchar not null,
staker varchar not null,
shares numeric not null,
staker_weight numeric not null,
rn bigint NOT NULL,
total_staker_weight numeric not null,
staker_proportion numeric not null,
staker_tokens numeric(38) not null
)`,
`create table if not exists gold_5_rfae_stakers (
reward_hash varchar not null,
snapshot date NOT NULL,
token varchar not null,
tokens_per_day_decimal numeric not null,
avs varchar not null,
strategy varchar not null,
multiplier numeric(78) not null,
reward_type varchar not null,
reward_submission_date varchar NOT NULL,
operator varchar not null,
staker varchar not null,
shares numeric not null,
excluded_address varchar,
staker_weight numeric not null,
rn bigint NOT NULL,
total_weight numeric not null,
staker_proportion numeric not null,
total_staker_operator_payout numeric not null,
operator_tokens numeric not null,
staker_tokens numeric not null
)`,
`create table if not exists gold_6_rfae_operators (
reward_hash varchar not null,
snapshot date NOT NULL,
token varchar not null,
tokens_per_day_decimal numeric not null,
avs varchar not null,
strategy varchar not null,
multiplier numeric(78) not null,
reward_type varchar not null,
operator varchar not null,
operator_tokens numeric not null,
rn bigint NOT NULL
)`,
`create table if not exists gold_7_staging (
earner varchar not null,
snapshot date NOT NULL,
reward_hash varchar not null,
token varchar not null,
amount numeric not null
)`,
`create table if not exists gold_table (
earner varchar not null,
snapshot date NOT NULL,
reward_hash varchar not null,
token varchar not null,
amount numeric not null
)`,
}

for _, query := range queries {
if err := grm.Exec(query).Error; err != nil {
return err
}
}
for chain, addresses := range exludedAddresses {
rows := make([]*storage.ExcludedAddresses, 0)
for _, address := range addresses {
rows = append(rows, &storage.ExcludedAddresses{
Address: address,
Network: chain.String(),
Description: "panama fork",
})
}
if len(rows) == 0 {
continue
}
if err := grm.Model(&storage.ExcludedAddresses{}).Create(&rows).Error; err != nil {
return err
}
}
return nil
}

func (m *Migration) GetName() string {
return "202410241539_goldTables"
}
9 changes: 9 additions & 0 deletions internal/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@ type OperatorRestakedStrategies struct {
DeletedAt time.Time
}

type ExcludedAddresses struct {
Address string
Network string
Description string
CreatedAt time.Time
UpdatedAt time.Time
DeletedAt time.Time
}

// Not tables

type ActiveAvsOperator struct {
Expand Down
Loading

0 comments on commit 1c5c97c

Please sign in to comment.