From 60ae126712d5363bc3ddf5d45769fa468d739ea3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Salgado?= Date: Wed, 3 Aug 2022 19:24:39 +0100 Subject: [PATCH] fix: ETH fees --- lib/plugins/wallet/geth/base.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/plugins/wallet/geth/base.js b/lib/plugins/wallet/geth/base.js index d17878ef..0e9f9cba 100644 --- a/lib/plugins/wallet/geth/base.js +++ b/lib/plugins/wallet/geth/base.js @@ -205,18 +205,20 @@ function generateTx (_toAddress, wallet, amount, includesFee, cryptoCode) { .then(([gas, gasPrice, txCount, baseFeePerGas]) => { lastUsedNonces[fromAddress] = txCount - const toSend = includesFee - ? new BN(amount.times(0.99999).toFixed(0, BigNumber.ROUND_DOWN)).minus(gasPrice.times(gas)) - : amount - const maxPriorityFeePerGas = new BN(web3.utils.toWei('2.5', 'gwei')) // web3 default value - const maxFeePerGas = new BN(2).times(baseFeePerGas).plus(maxPriorityFeePerGas) + const neededPriority = new BN(web3.utils.toWei('2.0', 'gwei')) + const maxFeePerGas = baseFeePerGas.plus(neededPriority) + const newGasPrice = BigNumber.minimum(maxFeePerGas, baseFeePerGas.plus(maxPriorityFeePerGas)) + + const toSend = includesFee + ? new BN(amount).minus(newGasPrice.times(gas)) + : amount const rawTx = { chainId: 1, nonce: txCount, - maxPriorityFeePerGas: web3.utils.toHex(web3.utils.toWei(maxPriorityFeePerGas.toString(), 'gwei')), - maxFeePerGas: web3.utils.toHex(web3.utils.toWei(maxFeePerGas.toString(), 'gwei')), + maxPriorityFeePerGas: web3.utils.toHex(maxPriorityFeePerGas), + maxFeePerGas: web3.utils.toHex(maxFeePerGas), gasLimit: hex(gas), to: toAddress, from: fromAddress,