From 0bb52b53f3fe34575b4bb0b72244e152e22de15a Mon Sep 17 00:00:00 2001 From: Robert Allen Date: Tue, 28 Oct 2025 10:37:50 +0300 Subject: [PATCH 1/3] fix: bug in banwidth delegation accounting --- internal/fsm/fsmtron/fsm_test.go | 2 +- pkg/walletsdk/tron/resources.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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/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) { From 081467063a134e01a05e8cc44db574661c8a0112 Mon Sep 17 00:00:00 2001 From: Robert Allen Date: Tue, 28 Oct 2025 11:16:55 +0300 Subject: [PATCH 2/3] fix: fixed evm incorrectly assigning gas fee tip --- pkg/walletsdk/evm/estimate.go | 41 ++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 17 deletions(-) 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 From ef15aabc8ab8ade08d5f2216f548f88b89037141 Mon Sep 17 00:00:00 2001 From: Webster Swift Date: Tue, 28 Oct 2025 14:14:48 +0300 Subject: [PATCH 3/3] fix: adjust total gas price calculation to remove gas tip cap addition --- pkg/walletsdk/evm/estimate.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/walletsdk/evm/estimate.go b/pkg/walletsdk/evm/estimate.go index b4d48e9..1d54d1c 100644 --- a/pkg/walletsdk/evm/estimate.go +++ b/pkg/walletsdk/evm/estimate.go @@ -44,7 +44,7 @@ func (s *EVM) EstimateTransfer(ctx context.Context, fromAddress, toAddress, asse gasAmount = decimal.NewFromUint64(estimatedGas) gasTipCap = estimate.SuggestGasTipCap - 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)))) @@ -65,7 +65,7 @@ func (s *EVM) EstimateTransfer(ctx context.Context, fromAddress, toAddress, asse gasAmount = decimal.NewFromUint64(estimatedGas) gasTipCap = estimate.SuggestGasTipCap - totalGasPrice = estimate.MaxFeePerGas.Add(gasTipCap) + totalGasPrice = estimate.MaxFeePerGas totalFeeAmount = totalGasPrice.Mul(gasAmount) } @@ -133,7 +133,7 @@ func (s *EVM) EstimateFee(ctx context.Context) (*EstimateFeeResult, error) { fee.SuggestGasTipCap = minGasTipCap } - fee.MaxFeePerGas = GetBaseFeeMultiplier(fee.SuggestGasPrice) + fee.MaxFeePerGas = GetBaseFeeMultiplier(fee.SuggestGasPrice).Add(fee.SuggestGasTipCap) return fee, nil }