diff --git a/lib/blockexplorers/mempool.space.js b/lib/blockexplorers/mempool.space.js index 4ef494d7..389d6727 100644 --- a/lib/blockexplorers/mempool.space.js +++ b/lib/blockexplorers/mempool.space.js @@ -1,8 +1,8 @@ const axios = require("axios"); -const getEstimateFeeBtc = () => { +const getSatBEstimateFee = () => { return axios.get('https://mempool.space/api/v1/fees/recommended') .then(r => r.data.hourFee) } -module.exports = { getEstimateFeeBtc } \ No newline at end of file +module.exports = { getSatBEstimateFee } \ No newline at end of file diff --git a/lib/plugins/wallet/bitcoind/bitcoind.js b/lib/plugins/wallet/bitcoind/bitcoind.js index efb1444d..b27bb478 100644 --- a/lib/plugins/wallet/bitcoind/bitcoind.js +++ b/lib/plugins/wallet/bitcoind/bitcoind.js @@ -1,6 +1,6 @@ const _ = require('lodash/fp') const jsonRpc = require('../../common/json-rpc') -const { getEstimateFeeBtc } = require('../../../blockexplorers/mempool.space') +const { getSatBEstimateFee } = require('../../../blockexplorers/mempool.space') const BN = require('../../../bn') const E = require('../../../error') @@ -56,14 +56,14 @@ function balance (account, cryptoCode, settings, operatorId) { } function estimateFee () { - return getEstimateFeeBtc() + return getSatBEstimateFee() .then(result => BN(result)) .catch(err => { logger.error('failure estimating fes', err) }) } -function calculateFeeDiscount (feeMultiplier = 1) { +function calculateFeeDiscount (feeMultiplier = 1, unitScale) { // 0 makes bitcoind do automatic fee selection const AUTOMATIC_FEE = 0 return estimateFee() @@ -72,7 +72,8 @@ function calculateFeeDiscount (feeMultiplier = 1) { logger.info('failure estimating fee, using bitcoind automatic fee selection') return AUTOMATIC_FEE } - const newFee = estimatedFee.times(feeMultiplier) + // transform from sat/vB to BTC/kvB and apply the multipler + const newFee = estimatedFee.shiftedBy(-unitScale+3).times(feeMultiplier) if (newFee.lt(0.00001) || newFee.gt(0.1)) { logger.info('fee outside safety parameters, defaulting to automatic fee selection') return AUTOMATIC_FEE @@ -86,7 +87,7 @@ function sendCoins (account, tx, settings, operatorId, feeMultiplier) { const coins = cryptoAtoms.shiftedBy(-unitScale).toFixed(8) return checkCryptoCode(cryptoCode) - .then(() => calculateFeeDiscount(feeMultiplier)) + .then(() => calculateFeeDiscount(feeMultiplier, unitScale)) .then(newFee => fetch('settxfee', [newFee])) .then(() => fetch('sendtoaddress', [toAddress, coins])) .then((txId) => fetch('gettransaction', [txId])) @@ -102,7 +103,7 @@ function sendCoins (account, tx, settings, operatorId, feeMultiplier) { function sendCoinsBatch (account, txs, cryptoCode, feeMultiplier) { return checkCryptoCode(cryptoCode) - .then(() => calculateFeeDiscount(feeMultiplier)) + .then(() => calculateFeeDiscount(feeMultiplier, unitScale)) .then(newFee => fetch('settxfee', [newFee])) .then(() => _.reduce((acc, value) => ({ ...acc, @@ -214,7 +215,6 @@ module.exports = { newFunding, cryptoNetwork, fetchRBF, - estimateFee, sendCoinsBatch, checkBlockchainStatus, getTxHashesByAddress, diff --git a/new-lamassu-admin/src/pages/Transactions/DetailsCard.js b/new-lamassu-admin/src/pages/Transactions/DetailsCard.js index 6a0fffef..afd2ad7b 100644 --- a/new-lamassu-admin/src/pages/Transactions/DetailsCard.js +++ b/new-lamassu-admin/src/pages/Transactions/DetailsCard.js @@ -91,7 +91,7 @@ const getCryptoAmount = tx => const getCryptoFeeAmount = tx => { const feeAmount = coinUtils - .toUnit(new BigNumber(tx.cryptoAtoms), tx.cryptoCode) + .toUnit(new BigNumber(tx.fee), tx.cryptoCode) .toNumber() return new BigNumber(feeAmount)