-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add rewards-v2 support to staker-operator table generation (#165)
- Loading branch information
Showing
11 changed files
with
292 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
pkg/rewards/stakerOperators/6_operatorODStrategyPayouts.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package stakerOperators | ||
|
||
import ( | ||
"github.com/Layr-Labs/sidecar/pkg/rewardsUtils" | ||
"time" | ||
) | ||
|
||
// _6_operatorODStrategyPayoutQuery is the query that generates the operator OD strategy payouts. | ||
// | ||
// In OperatorDirectedRewards (OD), the operator is paid a reward set by the AVS irrespective of the strategies | ||
// that are delegated to the operator. Because we cant break out by strategy, we can only take the amount that | ||
// the operator is paid of ALL strategies for the given snapshot since it doesnt matter if there are 1 or N strategies | ||
// delegated to the operator; the amount remains the same. | ||
const _6_operatorODStrategyPayoutQuery = ` | ||
create table {{.destTableName}} as | ||
select | ||
od.operator, | ||
od.reward_hash, | ||
od.snapshot, | ||
od.token, | ||
od.avs, | ||
od.strategy, | ||
od.multiplier, | ||
od.reward_submission_date, | ||
od.split_pct, | ||
od.operator_tokens | ||
from {{.operatorODRewardAmountsTable}} as od | ||
` | ||
|
||
type OperatorODStrategyPayout struct { | ||
RewardHash string | ||
Snapshot time.Time | ||
Token string | ||
Avs string | ||
Strategy string | ||
Multiplier string | ||
RewardSubmissionDate time.Time | ||
SplitPct string | ||
OperatorTokens string | ||
} | ||
|
||
func (sog *StakerOperatorsGenerator) GenerateAndInsert6OperatorODStrategyPayouts(cutoffDate string) error { | ||
allTableNames := rewardsUtils.GetGoldTableNames(cutoffDate) | ||
destTableName := allTableNames[rewardsUtils.Sot_6_OperatorODStrategyPayouts] | ||
|
||
sog.logger.Sugar().Infow("Generating and inserting 6_operatorODStrategyPayouts", | ||
"cutoffDate", cutoffDate, | ||
) | ||
|
||
query, err := rewardsUtils.RenderQueryTemplate(_6_operatorODStrategyPayoutQuery, map[string]interface{}{ | ||
"destTableName": destTableName, | ||
"operatorODRewardAmountsTable": allTableNames[rewardsUtils.Table_8_OperatorODRewardAmounts], | ||
}) | ||
if err != nil { | ||
sog.logger.Sugar().Errorw("Failed to render 6_operatorODStrategyPayouts query", "error", err) | ||
return err | ||
} | ||
|
||
res := sog.db.Exec(query) | ||
|
||
if res.Error != nil { | ||
sog.logger.Sugar().Errorw("Failed to generate 6_operatorODStrategyPayouts", "error", res.Error) | ||
return err | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package stakerOperators | ||
|
||
import ( | ||
"github.com/Layr-Labs/sidecar/pkg/rewardsUtils" | ||
"time" | ||
) | ||
|
||
// _7_stakerODStrategyPayoutQuery is a constant value that represents a query. | ||
// | ||
// Unlike rewards v1 where all staker amounts are pre-summed across operator/strategies, | ||
// in rewards v2 they are already represented at the staker/operator/strategy/reward_hash level | ||
// so adding them to the staker-operator table is a simple select from what we have already. | ||
const _7_stakerODStrategyPayoutQuery = ` | ||
create table {{.destTableName}} as | ||
select | ||
staker, | ||
operator, | ||
avs, | ||
token, | ||
strategy, | ||
multiplier, | ||
shares, | ||
staker_tokens, | ||
reward_hash, | ||
snapshot | ||
from {{.stakerODRewardAmountsTable}} | ||
` | ||
|
||
type StakerODStrategyPayout struct { | ||
Staker string | ||
Operator string | ||
Avs string | ||
Token string | ||
Strategy string | ||
Multiplier string | ||
Shares string | ||
StakerTokens string | ||
RewardHash string | ||
Snapshot time.Time | ||
} | ||
|
||
func (sog *StakerOperatorsGenerator) GenerateAndInsert7StakerODStrategyPayouts(cutoffDate string) error { | ||
allTableNames := rewardsUtils.GetGoldTableNames(cutoffDate) | ||
destTableName := allTableNames[rewardsUtils.Sot_7_StakerODStrategyPayouts] | ||
|
||
sog.logger.Sugar().Infow("Generating and inserting 7_stakerODStrategyPayouts", | ||
"cutoffDate", cutoffDate, | ||
) | ||
|
||
query, err := rewardsUtils.RenderQueryTemplate(_7_stakerODStrategyPayoutQuery, map[string]interface{}{ | ||
"destTableName": destTableName, | ||
"stakerODRewardAmountsTable": allTableNames[rewardsUtils.Table_9_StakerODRewardAmounts], | ||
}) | ||
if err != nil { | ||
sog.logger.Sugar().Errorw("Failed to render 7_stakerODStrategyPayouts query", "error", err) | ||
return err | ||
} | ||
|
||
res := sog.db.Exec(query) | ||
|
||
if res.Error != nil { | ||
sog.logger.Sugar().Errorw("Failed to generate 7_stakerODStrategyPayouts", "error", res.Error) | ||
return err | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package stakerOperators | ||
|
||
import ( | ||
"github.com/Layr-Labs/sidecar/pkg/rewardsUtils" | ||
) | ||
|
||
// _8_avsODStrategyPayoutQuery is the query that generates the 8_avsODStrategyPayouts table | ||
// | ||
// AVS operator directed rewards are not actually rewards, but refunds for the case when the operator | ||
// defined in the rewards-v2 submission wasnt delegated at the time of the snapshot. Since operator rewards | ||
// in rewards-v2 are not based on strategy and are a lump sum between the AVS and operator, the refund | ||
// is also the same; a lump sum BACK to the AVS that was originally intended for the operator. As such, | ||
// there is no strategy, shares or multiplier fields to represent. | ||
const _8_avsODStrategyPayoutQuery = ` | ||
create table {{.destTableName}} as | ||
select | ||
reward_hash, | ||
snapshot, | ||
token, | ||
avs, | ||
operator, | ||
avs_tokens | ||
from {{.avsODRewardAmountsTable}} | ||
` | ||
|
||
type AvsODStrategyPayout struct { | ||
RewardHash string | ||
Snapshot string | ||
Token string | ||
Avs string | ||
Operator string | ||
AvsTokens string | ||
} | ||
|
||
func (sog *StakerOperatorsGenerator) GenerateAndInsert8AvsODStrategyPayouts(cutoffDate string) error { | ||
allTableNames := rewardsUtils.GetGoldTableNames(cutoffDate) | ||
destTableName := allTableNames[rewardsUtils.Sot_8_AvsODStrategyPayouts] | ||
|
||
sog.logger.Sugar().Infow("Generating and inserting 8_avsODStrategyPayouts", | ||
"cutoffDate", cutoffDate, | ||
) | ||
|
||
query, err := rewardsUtils.RenderQueryTemplate(_8_avsODStrategyPayoutQuery, map[string]interface{}{ | ||
"destTableName": destTableName, | ||
"avsODRewardAmountsTable": allTableNames[rewardsUtils.Table_10_AvsODRewardAmounts], | ||
}) | ||
if err != nil { | ||
sog.logger.Sugar().Errorw("Failed to render 8_avsODStrategyPayouts query", "error", err) | ||
return err | ||
} | ||
|
||
res := sog.db.Exec(query) | ||
|
||
if res.Error != nil { | ||
sog.logger.Sugar().Errorw("Failed to generate 8_avsODStrategyPayouts", "error", res.Error) | ||
return err | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.