diff --git a/internal/fsm/fsmtron/fsm_test.go b/internal/fsm/fsmtron/fsm_test.go index aedcdf5..7723e11 100644 --- a/internal/fsm/fsmtron/fsm_test.go +++ b/internal/fsm/fsmtron/fsm_test.go @@ -86,7 +86,7 @@ func TestFSM(t *testing.T) { bc, err := blockchains.New(context.Background(), conf.Blockchain, sdk) require.NoError(t, err) - sysSvc := system.New(st, "sysVersion", "sysCommit") + sysSvc := system.New(l, st, "sysVersion", "sysCommit") bs, err := baseservices.New(appCtx, l, conf, st, explorerProxySvc, bc, sysSvc, dispatcher.New(), nil, sdk) require.NoError(t, err) diff --git a/pkg/walletsdk/evm/estimate.go b/pkg/walletsdk/evm/estimate.go index ebad7f0..1d54d1c 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,12 +44,7 @@ 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) + totalGasPrice = estimate.MaxFeePerGas totalFeeAmount = totalGasPrice.Mul(gasAmount) } else { amount = amount.Mul(decimal.NewFromInt(1).Mul(decimal.NewFromInt(10).Pow(decimal.NewFromInt(decimals)))) @@ -70,12 +65,7 @@ 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) + totalGasPrice = estimate.MaxFeePerGas totalFeeAmount = totalGasPrice.Mul(gasAmount) } @@ -137,19 +127,36 @@ func (s *EVM) EstimateFee(ctx context.Context) (*EstimateFeeResult, error) { SuggestGasPrice: suggestGasPrice, } - if s.config.Blockchain == wconstants.BlockchainTypeEthereum { - fee.SuggestGasTipCap = UnitMap[EtherUnitGWei] + // Apply blockchain-specific minimum gas tip caps + minGasTipCap := getMinGasTipCapByBlockchain(s.config.Blockchain) + if fee.SuggestGasTipCap.LessThan(minGasTipCap) { + fee.SuggestGasTipCap = minGasTipCap } - if fee.SuggestGasTipCap.LessThan(UnitMap[EtherUnitGWei]) { - fee.SuggestGasTipCap = UnitMap[EtherUnitGWei] - } - - fee.MaxFeePerGas = GetBaseFeeMultiplier(fee.SuggestGasPrice) + fee.MaxFeePerGas = GetBaseFeeMultiplier(fee.SuggestGasPrice).Add(fee.SuggestGasTipCap) 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 diff --git a/pkg/walletsdk/tron/resources.go b/pkg/walletsdk/tron/resources.go index 3c6563b..8c7b36b 100644 --- a/pkg/walletsdk/tron/resources.go +++ b/pkg/walletsdk/tron/resources.go @@ -278,7 +278,7 @@ func (t *Tron) AvailableForDelegateResources(ctx context.Context, addr string) ( resources := &Resources{ Energy: t.AvailableEnergy(accountResources), TotalEnergy: t.TotalEnergyLimit(accountResources), - Bandwidth: t.AvailableBandwidth(accountResources), + Bandwidth: t.AvailableBandwidthWithoutFree(accountResources), TotalBandwidth: t.TotalBandwidthLimit(accountResources), } if stackedEnergy.LessThan(resources.Energy) {