-
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.
- Loading branch information
1 parent
8cbaf97
commit f719ac0
Showing
10 changed files
with
161 additions
and
62 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package stakerOperators | ||
|
||
import ( | ||
"github.com/Layr-Labs/sidecar/pkg/rewardsUtils" | ||
"go.uber.org/zap" | ||
"time" | ||
) | ||
|
||
const _7_stakerOperator = ` | ||
insert into {{.destTableName}} ( | ||
earner, | ||
operator, | ||
reward_type, | ||
avs, | ||
token, | ||
strategy, | ||
multiplier, | ||
shares, | ||
amount, | ||
reward_hash, | ||
snapshot | ||
) | ||
select | ||
earner, | ||
operator, | ||
reward_type, | ||
avs, | ||
token, | ||
strategy, | ||
multiplier, | ||
shares, | ||
amount, | ||
reward_hash, | ||
snapshot | ||
from {{.stakerOperatorStaging}} | ||
on conflict on constraint uniq_staker_operator do nothing; | ||
` | ||
|
||
type StakerOperator struct { | ||
Earner string | ||
Operator string | ||
RewardType string | ||
Avs string | ||
Token string | ||
Strategy string | ||
Multiplier string | ||
Shares string | ||
Amount string | ||
RewardHash string | ||
Snapshot time.Time | ||
} | ||
|
||
func (sog *StakerOperatorsGenerator) GenerateAndInsert7StakerOperator(cutoffDate string) error { | ||
sog.logger.Sugar().Infow("Generating and inserting 7_stakerOperator", | ||
zap.String("cutoffDate", cutoffDate), | ||
) | ||
allTableNames := rewardsUtils.GetGoldTableNames(cutoffDate) | ||
destTableName := allTableNames[rewardsUtils.Sot_7_StakerOperatorTable] | ||
|
||
sog.logger.Sugar().Infow("Generating 7_stakerOperator", | ||
zap.String("destTableName", destTableName), | ||
zap.String("cutoffDate", cutoffDate), | ||
) | ||
|
||
query, err := rewardsUtils.RenderQueryTemplate(_7_stakerOperator, map[string]string{ | ||
"destTableName": destTableName, | ||
"stakerOperatorStaging": allTableNames[rewardsUtils.Sot_6_StakerOperatorStaging], | ||
}) | ||
if err != nil { | ||
sog.logger.Sugar().Errorw("Failed to render 7_stakerOperator query", "error", err) | ||
return err | ||
} | ||
|
||
res := sog.db.Debug().Exec(query) | ||
if res.Error != nil { | ||
sog.logger.Sugar().Errorw("Failed to generate 7_stakerOperator", | ||
zap.String("cutoffDate", cutoffDate), | ||
zap.Error(res.Error), | ||
) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (sog *StakerOperatorsGenerator) List7StakerOperator() ([]*StakerOperator, error) { | ||
var rewards []*StakerOperator | ||
res := sog.db.Model(&StakerOperator{}).Find(&rewards) | ||
if res.Error != nil { | ||
sog.logger.Sugar().Errorw("Failed to list 7_stakerOperator", "error", res.Error) | ||
return nil, res.Error | ||
} | ||
return rewards, 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