From 575dbeabe519edc7bcfcff403722823863bb1b3d Mon Sep 17 00:00:00 2001 From: Rafael Taranto Date: Wed, 24 Jan 2024 17:01:20 +0000 Subject: [PATCH 1/5] fix: correct scale for fee --- lib/plugins/wallet/bitcoind/bitcoind.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/plugins/wallet/bitcoind/bitcoind.js b/lib/plugins/wallet/bitcoind/bitcoind.js index efb1444d..e6fc1f0c 100644 --- a/lib/plugins/wallet/bitcoind/bitcoind.js +++ b/lib/plugins/wallet/bitcoind/bitcoind.js @@ -87,7 +87,10 @@ function sendCoins (account, tx, settings, operatorId, feeMultiplier) { return checkCryptoCode(cryptoCode) .then(() => calculateFeeDiscount(feeMultiplier)) - .then(newFee => fetch('settxfee', [newFee])) + .then(it => { + const newFee = it.shiftedBy(-unitScale).toFixed(8) + return fetch('settxfee', [newFee]) + }) .then(() => fetch('sendtoaddress', [toAddress, coins])) .then((txId) => fetch('gettransaction', [txId])) .then((res) => _.pick(['fee', 'txid'], res)) From d3533c44f0b567ccbc40e41faa7ac71f49a5b573 Mon Sep 17 00:00:00 2001 From: Rafael Taranto Date: Thu, 25 Jan 2024 15:28:17 +0000 Subject: [PATCH 2/5] fix: fee unit and batch fees --- lib/blockexplorers/mempool.space.js | 4 ++-- lib/plugins/wallet/bitcoind/bitcoind.js | 21 +++++++++++---------- 2 files changed, 13 insertions(+), 12 deletions(-) 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 e6fc1f0c..2f9f9c19 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,9 @@ 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) + console.log(newFee.toFixed()) if (newFee.lt(0.00001) || newFee.gt(0.1)) { logger.info('fee outside safety parameters, defaulting to automatic fee selection') return AUTOMATIC_FEE @@ -86,11 +88,8 @@ function sendCoins (account, tx, settings, operatorId, feeMultiplier) { const coins = cryptoAtoms.shiftedBy(-unitScale).toFixed(8) return checkCryptoCode(cryptoCode) - .then(() => calculateFeeDiscount(feeMultiplier)) - .then(it => { - const newFee = it.shiftedBy(-unitScale).toFixed(8) - return fetch('settxfee', [newFee]) - }) + .then(() => calculateFeeDiscount(feeMultiplier, unitScale)) + .then(() => fetch('settxfee', [newFee])) .then(() => fetch('sendtoaddress', [toAddress, coins])) .then((txId) => fetch('gettransaction', [txId])) .then((res) => _.pick(['fee', 'txid'], res)) @@ -105,7 +104,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, @@ -209,6 +208,8 @@ function getTxHashesByAddress (cryptoCode, address) { .then(_.map(({ hash }) => hash)) } +calculateFeeDiscount(1, 8).then(console.log) + module.exports = { balance, sendCoins, From d735b2dc6740eca96085cf865a41b8058a43b352 Mon Sep 17 00:00:00 2001 From: Rafael Taranto Date: Thu, 25 Jan 2024 18:06:47 +0000 Subject: [PATCH 3/5] fix: missing var, removing testing leftovers --- lib/plugins/wallet/bitcoind/bitcoind.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/plugins/wallet/bitcoind/bitcoind.js b/lib/plugins/wallet/bitcoind/bitcoind.js index 2f9f9c19..b27bb478 100644 --- a/lib/plugins/wallet/bitcoind/bitcoind.js +++ b/lib/plugins/wallet/bitcoind/bitcoind.js @@ -74,7 +74,6 @@ function calculateFeeDiscount (feeMultiplier = 1, unitScale) { } // transform from sat/vB to BTC/kvB and apply the multipler const newFee = estimatedFee.shiftedBy(-unitScale+3).times(feeMultiplier) - console.log(newFee.toFixed()) if (newFee.lt(0.00001) || newFee.gt(0.1)) { logger.info('fee outside safety parameters, defaulting to automatic fee selection') return AUTOMATIC_FEE @@ -89,7 +88,7 @@ function sendCoins (account, tx, settings, operatorId, feeMultiplier) { return checkCryptoCode(cryptoCode) .then(() => calculateFeeDiscount(feeMultiplier, unitScale)) - .then(() => fetch('settxfee', [newFee])) + .then(newFee => fetch('settxfee', [newFee])) .then(() => fetch('sendtoaddress', [toAddress, coins])) .then((txId) => fetch('gettransaction', [txId])) .then((res) => _.pick(['fee', 'txid'], res)) @@ -208,8 +207,6 @@ function getTxHashesByAddress (cryptoCode, address) { .then(_.map(({ hash }) => hash)) } -calculateFeeDiscount(1, 8).then(console.log) - module.exports = { balance, sendCoins, @@ -218,7 +215,6 @@ module.exports = { newFunding, cryptoNetwork, fetchRBF, - estimateFee, sendCoinsBatch, checkBlockchainStatus, getTxHashesByAddress, From fc7ef28ece7921c9a6ec73b837076c13911e5644 Mon Sep 17 00:00:00 2001 From: Rafael Taranto Date: Wed, 31 Jan 2024 08:55:27 +0000 Subject: [PATCH 4/5] fix: bitgo using old code --- lib/plugins/wallet/bitgo/bitgo.js | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/lib/plugins/wallet/bitgo/bitgo.js b/lib/plugins/wallet/bitgo/bitgo.js index be169b10..749ee030 100644 --- a/lib/plugins/wallet/bitgo/bitgo.js +++ b/lib/plugins/wallet/bitgo/bitgo.js @@ -1,6 +1,6 @@ const _ = require('lodash/fp') -const BitGo = require('bitgo') +const { BitGoAPI } = require('@bitgo/sdk-api') const { toLegacyAddress, toCashAddress } = require('bchaddrjs') const BN = require('../../../bn') @@ -11,19 +11,29 @@ const pjson = require('../../../../package.json') const userAgent = 'Lamassu-Server/' + pjson.version const NAME = 'BitGo' -const SUPPORTED_COINS = ['BTC', 'ZEC', 'LTC', 'BCH', 'DASH'] + +const BITGO_MODULES = { + BCH: require('@bitgo/sdk-coin-bch'), + BTC: require('@bitgo/sdk-coin-btc'), + DASH: require('@bitgo/sdk-coin-dash'), + LTC: require('@bitgo/sdk-coin-ltc'), + ZEC: require('@bitgo/sdk-coin-zec'), +} +const SUPPORTED_COINS = _.keys(BITGO_MODULES) const BCH_CODES = ['BCH', 'TBCH'] -function buildBitgo (account) { +const getWallet = (account, cryptoCode) => { + const accessToken = account.token.trim() const env = account.environment === 'test' ? 'test' : 'prod' - return new BitGo.BitGo({ accessToken: account.token.trim(), env, userAgent: userAgent }) -} + const walletId = account[`${cryptoCode}WalletId`] -function getWallet (account, cryptoCode) { - const bitgo = buildBitgo(account) - const coin = account.environment === 'test' ? `t${cryptoCode.toLowerCase()}` : cryptoCode.toLowerCase() + const bitgo = new BitGoAPI({ accessToken, env, userAgent }) + BITGO_MODULES[cryptoCode].register(bitgo) - return bitgo.coin(coin).wallets().get({ id: account[`${cryptoCode}WalletId`] }) + cryptoCode = cryptoCode.toLowerCase() + const coin = env === 'test' ? `t${cryptoCode}` : cryptoCode + + return bitgo.coin(coin).wallets().get({ id: walletId }) } function checkCryptoCode (cryptoCode) { From b7341352d488ccfc16cf5dd617818a5d9eb97711 Mon Sep 17 00:00:00 2001 From: Rafael Taranto Date: Wed, 31 Jan 2024 18:29:04 +0000 Subject: [PATCH 5/5] fix: using cryptoAtoms instead of fee --- new-lamassu-admin/src/pages/Transactions/DetailsCard.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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)