Skip to content

Commit

Permalink
feature: Optimize GasEstimate method03
Browse files Browse the repository at this point in the history
  • Loading branch information
DevDynamo2024 committed Feb 22, 2024
1 parent 9bab5f8 commit 032ab27
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import (
const (
estimateGasErrorRatio = 0.015
gasBuffer = uint64(120)
bufferPercentage = 90
)

// EthereumAPI provides an API to access Ethereum related information.
Expand Down Expand Up @@ -1247,7 +1248,13 @@ func DoEstimateGas(ctx context.Context, b Backend, args TransactionArgs, blockNr
}
}

allowance := new(big.Int).Div(available, feeCap)
// allowance := new(big.Int).Div(available, feeCap)
// Calculate the maximum value that can be used to pay for gas fees, based on the dynamic buffer ratio.
maxGasPayment := new(big.Int).Mul(available, big.NewInt(bufferPercentage))
maxGasPayment.Div(maxGasPayment, big.NewInt(100))

// Calculate gas limit based on buffer.
allowance := new(big.Int).Div(maxGasPayment, feeCap)

// If the allowance is larger than maximum uint64, skip checking
if allowance.IsUint64() && hi > allowance.Uint64() {
Expand Down

0 comments on commit 032ab27

Please sign in to comment.