From c6652baa7c681137335f1736282514e201d48065 Mon Sep 17 00:00:00 2001 From: poma Date: Fri, 3 Sep 2021 16:09:26 +0300 Subject: [PATCH] inline _estimateFees() --- package.json | 2 +- src/Transaction.js | 34 ++++++++-------------------------- 2 files changed, 9 insertions(+), 27 deletions(-) diff --git a/package.json b/package.json index c97570b..7c0feef 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tx-manager", - "version": "0.4.0", + "version": "0.4.1", "description": "", "main": "index.js", "scripts": { diff --git a/src/Transaction.js b/src/Transaction.js index 7d7af30..5b4b418 100644 --- a/src/Transaction.js +++ b/src/Transaction.js @@ -409,28 +409,6 @@ class Transaction { return this._wallet.getTransactionCount('latest') } - /** - * Fetches baseFee from chain and calculate fee params - * - * @returns {Promise} - * @private - */ - async _estimateFees() { - const block = await this._provider.getBlock('latest') - - let maxFeePerGas = null, - maxPriorityFeePerGas = null - - if (block && block.baseFeePerGas) { - 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 } - } - /** * Choose network gas params * @@ -438,15 +416,19 @@ class Transaction { * @private */ async _getGasParams() { - const { maxFeePerGas, maxPriorityFeePerGas } = await this._estimateFees() - const maxGasPrice = parseUnits(this.config.MAX_GAS_PRICE.toString(), 'gwei') + const block = await this._provider.getBlock('latest') // Check network support for EIP-1559 - if (maxFeePerGas && maxPriorityFeePerGas) { + if (block && block.baseFeePerGas) { + const maxPriorityFeePerGas = parseUnits(this.config.PRIORITY_FEE_GWEI.toString(), 'gwei') + const maxFeePerGas = block.baseFeePerGas + .mul(100 + this.config.BASE_FEE_RESERVE_PERCENTAGE) + .div(100) + .add(maxPriorityFeePerGas) return { maxFeePerGas: min(maxFeePerGas, maxGasPrice).toHexString(), - maxPriorityFeePerGas: maxPriorityFeePerGas.toHexString(), + maxPriorityFeePerGas: min(maxPriorityFeePerGas, maxGasPrice).toHexString(), type: 2, } } else {