diff --git a/pkg/walletsdk/evm/estimate.go b/pkg/walletsdk/evm/estimate.go index ebad7f0..b4d48e9 100644 --- a/pkg/walletsdk/evm/estimate.go +++ b/pkg/walletsdk/evm/estimate.go @@ -32,7 +32,7 @@ func (s *EVM) EstimateTransfer(ctx context.Context, fromAddress, toAddress, asse return nil, fmt.Errorf("failed to estimate fee: %w", err) } - if assetIdentifier == s.config.Blockchain.GetAssetIdentifier() { //nolint:nestif + if assetIdentifier == s.config.Blockchain.GetAssetIdentifier() { estimatedGas, err := s.node.EstimateGas(ctx, ethereum.CallMsg{ From: common.HexToAddress(fromAddress), To: utils.Pointer(common.HexToAddress(toAddress)), @@ -44,11 +44,6 @@ func (s *EVM) EstimateTransfer(ctx context.Context, fromAddress, toAddress, asse gasAmount = decimal.NewFromUint64(estimatedGas) gasTipCap = estimate.SuggestGasTipCap - - if gasTipCap.GreaterThan(estimate.MaxFeePerGas) { - gasTipCap = estimate.MaxFeePerGas - } - totalGasPrice = estimate.MaxFeePerGas.Add(gasTipCap) totalFeeAmount = totalGasPrice.Mul(gasAmount) } else { @@ -70,11 +65,6 @@ func (s *EVM) EstimateTransfer(ctx context.Context, fromAddress, toAddress, asse gasAmount = decimal.NewFromUint64(estimatedGas) gasTipCap = estimate.SuggestGasTipCap - - if gasTipCap.GreaterThan(estimate.MaxFeePerGas) { - gasTipCap = estimate.MaxFeePerGas - } - totalGasPrice = estimate.MaxFeePerGas.Add(gasTipCap) totalFeeAmount = totalGasPrice.Mul(gasAmount) } @@ -137,12 +127,10 @@ func (s *EVM) EstimateFee(ctx context.Context) (*EstimateFeeResult, error) { SuggestGasPrice: suggestGasPrice, } - if s.config.Blockchain == wconstants.BlockchainTypeEthereum { - fee.SuggestGasTipCap = UnitMap[EtherUnitGWei] - } - - if fee.SuggestGasTipCap.LessThan(UnitMap[EtherUnitGWei]) { - fee.SuggestGasTipCap = UnitMap[EtherUnitGWei] + // Apply blockchain-specific minimum gas tip caps + minGasTipCap := getMinGasTipCapByBlockchain(s.config.Blockchain) + if fee.SuggestGasTipCap.LessThan(minGasTipCap) { + fee.SuggestGasTipCap = minGasTipCap } fee.MaxFeePerGas = GetBaseFeeMultiplier(fee.SuggestGasPrice) @@ -150,6 +138,25 @@ func (s *EVM) EstimateFee(ctx context.Context) (*EstimateFeeResult, error) { return fee, nil } +// getMinGasTipCapByBlockchain returns the minimum gas tip cap for a given blockchain in Wei. +func getMinGasTipCapByBlockchain(blockchain wconstants.BlockchainType) decimal.Decimal { + switch blockchain { + case wconstants.BlockchainTypeBinanceSmartChain: + return UnitMap[EtherUnitGWei].Div(decimal.NewFromInt(10)) + case wconstants.BlockchainTypeEthereum: + return UnitMap[EtherUnitGWei] + case wconstants.BlockchainTypePolygon: + return decimal.NewFromInt(30).Mul(UnitMap[EtherUnitGWei]) + case wconstants.BlockchainTypeArbitrum, + wconstants.BlockchainTypeOptimism, + wconstants.BlockchainTypeLinea: + return UnitMap[EtherUnitGWei].Div(decimal.NewFromInt(100)) + default: + // Default: 1 Gwei + return UnitMap[EtherUnitGWei] + } +} + func GetBaseFeeMultiplier(baseFeeWei decimal.Decimal) decimal.Decimal { items := []struct { threshold int64