diff --git a/package.json b/package.json index aac9d57..c97570b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tx-manager", - "version": "0.3.3", + "version": "0.4.0", "description": "", "main": "index.js", "scripts": { diff --git a/src/Transaction.js b/src/Transaction.js index 2878a1d..7d7af30 100644 --- a/src/Transaction.js +++ b/src/Transaction.js @@ -361,15 +361,23 @@ class Transaction { console.log(`Increasing gas price to ${formatUnits(this.tx.gasPrice, 'gwei')} gwei`) } else { const oldMaxFeePerGas = BigNumber.from(this.tx.maxFeePerGas) - const oldMaxPriorityFeePerGas = BigNumber.from(this.tx.maxFeePerGas) + const oldMaxPriorityFeePerGas = BigNumber.from(this.tx.maxPriorityFeePerGas) if (oldMaxFeePerGas.gte(maxGasPrice)) { console.log('Already at max fee per gas, not bumping') return false } - const newMaxFeePerGas = oldMaxFeePerGas.add(minGweiBump) + const newMaxFeePerGas = max( + oldMaxFeePerGas.mul(100 + this.config.GAS_BUMP_PERCENTAGE).div(100), + oldMaxFeePerGas.add(minGweiBump), + ) + const newMaxPriorityFeePerGas = max( + oldMaxPriorityFeePerGas.mul(100 + this.config.GAS_BUMP_PERCENTAGE).div(100), + oldMaxPriorityFeePerGas.add(minGweiBump), + ) + this.tx.maxFeePerGas = min(newMaxFeePerGas, maxGasPrice).toHexString() - this.tx.maxPriorityFeePerGas = oldMaxPriorityFeePerGas.add(minGweiBump).toHexString() + this.tx.maxPriorityFeePerGas = min(newMaxPriorityFeePerGas, this.tx.maxFeePerGas).toHexString() console.log(`Increasing maxFeePerGas to ${formatUnits(this.tx.maxFeePerGas, 'gwei')} gwei`) } @@ -414,8 +422,11 @@ class Transaction { maxPriorityFeePerGas = null if (block && block.baseFeePerGas) { - maxPriorityFeePerGas = BigNumber.from('3000000000') - maxFeePerGas = block.baseFeePerGas.mul(125).div(100).add(maxPriorityFeePerGas) + maxPriorityFeePerGas = parseUnits(this.config.PRIORITY_FEE_GWEI.toString(), 'gwei') + maxFeePerGas = block.baseFeePerGas + .mul(100 + this.config.BASE_FEE_RESERVE_PERCENTAGE) + .div(100) + .add(maxPriorityFeePerGas) } return { maxFeePerGas, maxPriorityFeePerGas } } diff --git a/src/TxManager.js b/src/TxManager.js index 2280e80..29bdb4b 100644 --- a/src/TxManager.js +++ b/src/TxManager.js @@ -15,6 +15,8 @@ const defaultConfig = { ESTIMATE_GAS: true, THROW_ON_REVERT: true, BLOCK_GAS_LIMIT: null, + PRIORITY_FEE_GWEI: 3, + BASE_FEE_RESERVE_PERCENTAGE: 50, } class TxManager {