@@ -220,6 +220,12 @@ func (b *wrappedBackend) Close() error {
220220
221221// SuggestedFeeAndTip calculates the recommended gasFeeCap and gasTipCap for a transaction.
222222func (b * wrappedBackend ) SuggestedFeeAndTip (ctx context.Context , gasPrice * big.Int , boostPercent int ) (* big.Int , * big.Int , error ) {
223+ if gasPrice != nil {
224+ // 1. gasFeeCap: The absolute maximum price per gas does not exceed the user's specified price.
225+ // 2. gasTipCap: The entire amount (gasPrice - baseFee) can be used as a priority fee.
226+ return new (big.Int ).Set (gasPrice ), new (big.Int ).Set (gasPrice ), nil
227+ }
228+
223229 gasTipCap , err := b .backend .SuggestGasTipCap (ctx )
224230 if err != nil {
225231 return nil , nil , fmt .Errorf ("failed to suggest gas tip cap: %w" , err )
@@ -237,30 +243,17 @@ func (b *wrappedBackend) SuggestedFeeAndTip(ctx context.Context, gasPrice *big.I
237243 gasTipCap .Set (minimumTip )
238244 }
239245
240- var gasFeeCap * big.Int
241-
242- if gasPrice == nil {
243- latestBlockHeader , err := b .backend .HeaderByNumber (ctx , nil )
244- if err != nil {
245- return nil , nil , fmt .Errorf ("failed to get latest block header: %w" , err )
246- }
247-
248- if latestBlockHeader == nil || latestBlockHeader .BaseFee == nil {
249- return nil , nil , ErrEIP1559NotSupported
250- }
251-
252- // EIP-1559: gasFeeCap = (2 * baseFee) + gasTipCap
253- gasFeeCap = new (big.Int ).Mul (latestBlockHeader .BaseFee , big .NewInt (int64 (baseFeeMultiplier )))
254- gasFeeCap .Add (gasFeeCap , gasTipCap )
255-
256- } else {
257- gasFeeCap = new (big.Int ).Set (gasPrice )
246+ latestBlockHeader , err := b .backend .HeaderByNumber (ctx , nil )
247+ if err != nil {
248+ return nil , nil , fmt .Errorf ("failed to get latest block header: %w" , err )
258249 }
259-
260- // gasTipCap cannot exceed gasFeeCap
261- if gasTipCap .Cmp (gasFeeCap ) > 0 {
262- gasTipCap .Set (gasFeeCap )
250+ if latestBlockHeader == nil || latestBlockHeader .BaseFee == nil {
251+ return nil , nil , ErrEIP1559NotSupported
263252 }
264253
254+ // EIP-1559: gasFeeCap = (2 * baseFee) + gasTipCap
255+ gasFeeCap := new (big.Int ).Mul (latestBlockHeader .BaseFee , big .NewInt (int64 (baseFeeMultiplier )))
256+ gasFeeCap .Add (gasFeeCap , gasTipCap )
257+
265258 return gasFeeCap , gasTipCap , nil
266259}
0 commit comments