From 169343dc0a22e0cd4db21bc5ec5ce7f0c4c7362a Mon Sep 17 00:00:00 2001 From: Madhur Shrimal Date: Mon, 26 Aug 2024 20:56:54 -0700 Subject: [PATCH 1/2] fix: hardcode gas limit for smart contract claimer --- pkg/internal/common/eth.go | 4 ++-- pkg/rewards/claim.go | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/pkg/internal/common/eth.go b/pkg/internal/common/eth.go index c78e2cc..8467573 100644 --- a/pkg/internal/common/eth.go +++ b/pkg/internal/common/eth.go @@ -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))) } diff --git a/pkg/rewards/claim.go b/pkg/rewards/claim.go index 9ac2233..aefa982 100644 --- a/pkg/rewards/claim.go +++ b/pkg/rewards/claim.go @@ -204,10 +204,23 @@ 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 it doesn't support estimate gas for calling smart contract + // from smart contract. So we set a default gas limit. + 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()) From 41b24bb53262c974cb88caf60163a142b8097103 Mon Sep 17 00:00:00 2001 From: Madhur Shrimal Date: Mon, 26 Aug 2024 21:03:34 -0700 Subject: [PATCH 2/2] comments --- pkg/rewards/claim.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pkg/rewards/claim.go b/pkg/rewards/claim.go index aefa982..8b929b5 100644 --- a/pkg/rewards/claim.go +++ b/pkg/rewards/claim.go @@ -205,8 +205,9 @@ func Claim(cCtx *cli.Context, p utils.Prompter) error { } // If claimer is a smart contract, we can't estimate gas using geth - // since it doesn't support estimate gas for calling smart contract - // from smart contract. So we set a default gas limit. + // 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)