fix: use eth_maxPriorityFeePerGas
This commit is contained in:
parent
eaaa54b7f9
commit
c1c6079745
@ -1,5 +1,5 @@
|
|||||||
const ethers = require('ethers')
|
const ethers = require('ethers')
|
||||||
const { parseUnits, formatUnits, hexValue } = ethers.utils
|
const { parseUnits, formatUnits } = ethers.utils
|
||||||
const BigNumber = ethers.BigNumber
|
const BigNumber = ethers.BigNumber
|
||||||
const PromiEvent = require('web3-core-promievent')
|
const PromiEvent = require('web3-core-promievent')
|
||||||
const { sleep, min, max } = require('./utils')
|
const { sleep, min, max } = require('./utils')
|
||||||
@ -429,25 +429,21 @@ class Transaction {
|
|||||||
* @returns {Promise<BigNumber>}
|
* @returns {Promise<BigNumber>}
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
async _estimatePriorityFee(blockNumber) {
|
async _estimatePriorityFee() {
|
||||||
const feeHistoryBlocks = 1
|
const defaultPriorityFee = parseUnits(this.config.DEFAULT_PRIORITY_FEE.toString(), 'gwei')
|
||||||
const feeHistoryPercentile = 50
|
|
||||||
const defaultPriorityFee = parseUnits(this.config.PRIORITY_FEE_GWEI.toString(), 'gwei')
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { reward } = await this._provider.send('eth_feeHistory', [
|
const estimatedPriorityFee = await this._provider.send('eth_maxPriorityFeePerGas', [])
|
||||||
hexValue(feeHistoryBlocks),
|
|
||||||
hexValue(blockNumber),
|
|
||||||
[feeHistoryPercentile],
|
|
||||||
])
|
|
||||||
|
|
||||||
const historyPriorityFee = reward[0][0]
|
if (!estimatedPriorityFee || isNaN(estimatedPriorityFee)) {
|
||||||
|
return defaultPriorityFee
|
||||||
if (historyPriorityFee) {
|
|
||||||
return max(BigNumber.from(historyPriorityFee), defaultPriorityFee)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return defaultPriorityFee
|
const bumpedPriorityFee = BigNumber.from(estimatedPriorityFee)
|
||||||
|
.mul(100 + this.config.PRIORITY_FEE_RESERVE_PERCENTAGE)
|
||||||
|
.div(100)
|
||||||
|
|
||||||
|
return max(bumpedPriorityFee, defaultPriorityFee)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('_estimatePriorityFee has error:', err.message)
|
console.error('_estimatePriorityFee has error:', err.message)
|
||||||
return defaultPriorityFee
|
return defaultPriorityFee
|
||||||
@ -466,7 +462,7 @@ class Transaction {
|
|||||||
|
|
||||||
// Check network support for EIP-1559
|
// Check network support for EIP-1559
|
||||||
if (this.config.ENABLE_EIP1559 && block && block.baseFeePerGas) {
|
if (this.config.ENABLE_EIP1559 && block && block.baseFeePerGas) {
|
||||||
const maxPriorityFeePerGas = await this._estimatePriorityFee(block.number)
|
const maxPriorityFeePerGas = await this._estimatePriorityFee()
|
||||||
|
|
||||||
const maxFeePerGas = block.baseFeePerGas
|
const maxFeePerGas = block.baseFeePerGas
|
||||||
.mul(100 + this.config.BASE_FEE_RESERVE_PERCENTAGE)
|
.mul(100 + this.config.BASE_FEE_RESERVE_PERCENTAGE)
|
||||||
|
@ -16,8 +16,9 @@ const defaultConfig = {
|
|||||||
THROW_ON_REVERT: true,
|
THROW_ON_REVERT: true,
|
||||||
BLOCK_GAS_LIMIT: null,
|
BLOCK_GAS_LIMIT: null,
|
||||||
ENABLE_EIP1559: true,
|
ENABLE_EIP1559: true,
|
||||||
PRIORITY_FEE_GWEI: 3,
|
DEFAULT_PRIORITY_FEE: 3,
|
||||||
BASE_FEE_RESERVE_PERCENTAGE: 50,
|
BASE_FEE_RESERVE_PERCENTAGE: 50,
|
||||||
|
PRIORITY_FEE_RESERVE_PERCENTAGE: 10,
|
||||||
}
|
}
|
||||||
|
|
||||||
class TxManager {
|
class TxManager {
|
||||||
|
Loading…
Reference in New Issue
Block a user