Skip to content

Commit

Permalink
Fix maxFeePerGas compensation calculation (#1847)
Browse files Browse the repository at this point in the history
* Fix maxFeePerGas compensation calculation

* Switch operands
  • Loading branch information
Stefan-Ethernal committed Aug 24, 2023
1 parent 2f430d0 commit 1794897
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion txrelayer/txrelayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ func (t *TxRelayerImpl) sendTransactionLocked(txn *ethgo.Transaction, key ethgo.
return ethgo.ZeroHash, fmt.Errorf("failed to get max priority fee per gas: %w", err)
}

// set retrieved max priority fee per gas increased by certain percentage
compMaxPriorityFee := new(big.Int).Mul(maxPriorityFee, big.NewInt(feeIncreasePercentage))
compMaxPriorityFee = compMaxPriorityFee.Div(compMaxPriorityFee, big.NewInt(100))
txn.MaxPriorityFeePerGas = new(big.Int).Add(maxPriorityFee, compMaxPriorityFee)
Expand All @@ -151,9 +152,11 @@ func (t *TxRelayerImpl) sendTransactionLocked(txn *ethgo.Transaction, key ethgo.

baseFee := feeHist.BaseFee[len(feeHist.BaseFee)-1]
// set max fee per gas as sum of base fee and max priority fee
// (increased by certain percentage)
maxFeePerGas := new(big.Int).Add(baseFee, maxPriorityFee)
compMaxFeePerGas := new(big.Int).Mul(maxFeePerGas, big.NewInt(feeIncreasePercentage))
txn.MaxFeePerGas = new(big.Int).Add(compMaxFeePerGas, maxFeePerGas)
compMaxFeePerGas = compMaxFeePerGas.Div(compMaxFeePerGas, big.NewInt(100))
txn.MaxFeePerGas = new(big.Int).Add(maxFeePerGas, compMaxFeePerGas)
}
} else if txn.GasPrice == 0 {
gasPrice, err := t.Client().Eth().GasPrice()
Expand Down

0 comments on commit 1794897

Please sign in to comment.