Skip to content

Commit

Permalink
fix: hardcode gas limit for smart contract claimer (#202)
Browse files Browse the repository at this point in the history
* fix: hardcode gas limit for smart contract claimer

* comments
  • Loading branch information
shrimalmadhur committed Aug 27, 2024
1 parent 2b1c6e6 commit 93010df
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pkg/internal/common/eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ type TxFeeDetails struct {
}

func (t *TxFeeDetails) Print() {
message := strings.Repeat("-", 25) + " Gas Fee Details " + strings.Repeat("-", 25)
message := strings.Repeat("-", 30) + " Gas Fee Details " + strings.Repeat("-", 30)
fmt.Println(message)
fmt.Printf("Gas Tip Cap: %0.9f Gwei\n", t.GasTipCapGwei)
fmt.Printf("Gas Fee Cap: %0.9f Gwei\n", t.GasFeeCapGwei)
fmt.Printf("Gas Limit: %d\n", t.GasLimit)
fmt.Printf("Gas Limit: %d (If claimer is a smart contract, this value is hardcoded)\n", t.GasLimit)
fmt.Printf("Approximate Max Cost of transaction: %0.12f ETH\n", t.CostInEth)
fmt.Println(strings.Repeat("-", len(message)))
}
Expand Down
14 changes: 14 additions & 0 deletions pkg/rewards/claim.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,24 @@ func Claim(cCtx *cli.Context, p utils.Prompter) error {
return err
}

// If claimer is a smart contract, we can't estimate gas using geth
// since balance of contract can be 0, as it can be called by an EOA
// to claim. So we hardcode the gas limit to 150_000 so that we can
// create unsigned tx without gas limit estimation from contract bindings
code, err := ethClient.CodeAt(ctx, config.ClaimerAddress, nil)
if err != nil {
return eigenSdkUtils.WrapError("failed to get code at address", err)
}
if len(code) > 0 {
// Claimer is a smart contract
noSendTxOpts.GasLimit = 150_000
}

unsignedTx, err := contractBindings.RewardsCoordinator.ProcessClaim(noSendTxOpts, elClaim, config.RecipientAddress)
if err != nil {
return eigenSdkUtils.WrapError("failed to create unsigned tx", err)
}

if config.OutputType == string(common.OutputType_Calldata) {
calldataHex := gethcommon.Bytes2Hex(unsignedTx.Data())

Expand Down

0 comments on commit 93010df

Please sign in to comment.