Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/fsm/fsmtron/fsm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
47 changes: 27 additions & 20 deletions pkg/walletsdk/evm/estimate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand All @@ -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))))
Expand All @@ -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)
}

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/walletsdk/tron/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down