Skip to content

Commit

Permalink
use only one claim function
Browse files Browse the repository at this point in the history
  • Loading branch information
bharath-123 committed Jan 16, 2024
1 parent c8dc8b7 commit 1bb8e44
Showing 1 changed file with 13 additions and 31 deletions.
44 changes: 13 additions & 31 deletions stader/api/node/claim-rewards.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ package node
import (
"math/big"

"github.com/ethereum/go-ethereum/core/types"
"github.com/stader-labs/stader-node/shared/services"
"github.com/stader-labs/stader-node/shared/types/api"
"github.com/stader-labs/stader-node/stader-lib/node"
"github.com/stader-labs/stader-node/stader-lib/stader"
"github.com/urfave/cli"
)

Expand Down Expand Up @@ -61,18 +59,10 @@ func CanClaimRewards(c *cli.Context) (*api.CanClaimRewards, error) {
return nil, err
}

var gasInfo stader.GasInfo
if operatorClaimVaultBalance.Cmp(withdrawableInEth) != 0 {
gasInfo, err = node.EstimateClaimOperatorRewardsWithAmount(orc, nodeAccount.Address, totalWithdrawableEth, opts)
if err != nil {
return nil, err
}
} else {
// estimate gas
gasInfo, err = node.EstimateClaimOperatorRewards(orc, opts)
if err != nil {
return nil, err
}
// estimate gas
gasInfo, err := node.EstimateClaimOperatorRewards(orc, opts)
if err != nil {
return nil, err
}

response.GasInfo = gasInfo
Expand Down Expand Up @@ -134,25 +124,17 @@ func ClaimRewards(c *cli.Context) (*api.ClaimRewards, error) {
return nil, err
}

totalWithdrawableEth := operatorRewardsBalance
if operatorRewardsBalance.Cmp(withdrawableInEth) > 0 {
totalWithdrawableEth = withdrawableInEth
}

// estimate gas
var tx *types.Transaction
if operatorRewardsBalance.Cmp(withdrawableInEth) == 0 {
tx, err = node.ClaimOperatorRewards(orc, opts)
if err != nil {
return nil, err
}
response.RewardsClaimed = operatorRewardsBalance
} else {
totalWithdrawableEth := operatorRewardsBalance
if operatorRewardsBalance.Cmp(withdrawableInEth) > 0 {
totalWithdrawableEth = withdrawableInEth
}
tx, err = node.ClaimOperatorRewardsWithAmount(orc, nodeAccount.Address, totalWithdrawableEth, opts)
if err != nil {
return nil, err
}
response.RewardsClaimed = totalWithdrawableEth
tx, err := node.ClaimOperatorRewards(orc, opts)
if err != nil {
return nil, err
}
response.RewardsClaimed = totalWithdrawableEth

response.TxHash = tx.Hash()

Expand Down

0 comments on commit 1bb8e44

Please sign in to comment.