Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
repos:
- repo: https://github.com/gitleaks/gitleaks
rev: v8.28.0 # latest version
hooks:
- id: gitleaks
args: ['--verbose', '--redact']
59 changes: 55 additions & 4 deletions pkg/server/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,33 @@ func (s *Server) StakingValidatorsHandler() gin.HandlerFunc {
return
}

// Get staking params for locked token type multiplier
stakingParamsResp, err := GetStakingParams(s.conf.Blockchain.StoryAPIEndpoint)
if err != nil {
logger.Error().Err(err).Msg("failed to get staking params")
c.JSON(http.StatusOK, Response{
Code: http.StatusInternalServerError,
Error: ErrInternalAPIServiceError.Error(),
})
return
}

var lockedTokenMultiplier decimal.Decimal
for _, tt := range stakingParamsResp.Msg.Params.TokenTypes {
if tt.TokenType == TokenTypeLocked {
lockedTokenMultiplier, err = decimal.NewFromString(tt.RewardsMultiplier)
if err != nil {
logger.Error().Err(err).Msg("failed to parse locked token type multiplier")
c.JSON(http.StatusOK, Response{
Code: http.StatusInternalServerError,
Error: ErrInternalAPIServiceError.Error(),
})
return
}
break
}
}

// Query from API and database
stakingValidatorsResp, err := GetStakingValidators(s.conf.Blockchain.StoryAPIEndpoint, params)
if err != nil {
Expand Down Expand Up @@ -517,9 +544,9 @@ func (s *Server) StakingValidatorsHandler() gin.HandlerFunc {
}

valAPR := sysAPR.Mul(decimal.NewFromInt(1).Sub(commissionRate))
// Locked token type has 0.5x APR
// Apply locked token type multiplier from staking params
if val.SupportTokenType == 0 {
valAPR = valAPR.Div(decimal.NewFromInt(2))
valAPR = valAPR.Mul(lockedTokenMultiplier)
}

validators = append(validators, StakingValidatorData{
Expand Down Expand Up @@ -609,9 +636,33 @@ func (s *Server) StakingValidatorHandler() gin.HandlerFunc {
}

valAPR := sysAPR.Mul(decimal.NewFromInt(1).Sub(commissionRate))
// Locked token type has 0.5x APR
// Apply locked token type multiplier from staking params
if val.SupportTokenType == 0 {
valAPR = valAPR.Div(decimal.NewFromInt(2))
stakingParamsResp, err := GetStakingParams(s.conf.Blockchain.StoryAPIEndpoint)
if err != nil {
logger.Error().Err(err).Msg("failed to get staking params")
c.JSON(http.StatusOK, Response{
Code: http.StatusInternalServerError,
Error: ErrInternalAPIServiceError.Error(),
})
return
}

for _, tt := range stakingParamsResp.Msg.Params.TokenTypes {
if tt.TokenType == TokenTypeLocked {
lockedTokenMultiplier, err := decimal.NewFromString(tt.RewardsMultiplier)
if err != nil {
logger.Error().Err(err).Msg("failed to parse locked token type multiplier")
c.JSON(http.StatusOK, Response{
Code: http.StatusInternalServerError,
Error: ErrInternalAPIServiceError.Error(),
})
return
}
valAPR = valAPR.Mul(lockedTokenMultiplier)
break
}
}
}

msg := StakingValidatorData{
Expand Down
Loading