From b31390f2c76b1bd92d4af954c2b8283b1c0862b1 Mon Sep 17 00:00:00 2001 From: Polybius93 Date: Mon, 16 Dec 2024 13:26:28 +0100 Subject: [PATCH] chore: cleanup getFeeRate function and remove temporary test --- src/functions/bitcoin/bitcoin-functions.ts | 14 ++++++++------ tests/unit/bitcoin-functions.test.ts | 6 ------ 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/functions/bitcoin/bitcoin-functions.ts b/src/functions/bitcoin/bitcoin-functions.ts index 737cad5..e57551b 100644 --- a/src/functions/bitcoin/bitcoin-functions.ts +++ b/src/functions/bitcoin/bitcoin-functions.ts @@ -220,15 +220,17 @@ export async function getFeeRate( const multiplier = feeRateMultiplier ?? 1; - const currentBlockFeeRate = await getCurrentMempoolBlockFeeRate(bitcoinBlockchainAPIFeeURL); + const [lastTwoBlocksFeeRate, currentBlockFeeRate, estimatedFeeRate] = await Promise.all([ + getLastTwoBlocksFeeRate(bitcoinBlockchainAPIFeeURL), + getCurrentMempoolBlockFeeRate(bitcoinBlockchainAPIFeeURL), + getEstimatedFeeRate(bitcoinBlockchainAPIFeeURL), + ]); + const currentBlockFeeRateMultiplied = Math.ceil(currentBlockFeeRate) * multiplier; - const lastTwoBlocksFeeRate = await getLastTwoBlocksFeeRate(bitcoinBlockchainAPIFeeURL); - const lastTwoBlocksfeeRateAverage = - lastTwoBlocksFeeRate.reduce((a, b) => a + b) / lastTwoBlocksFeeRate.length; - const lastTwoBlocksfeeRateAverageMultiplied = Math.ceil(lastTwoBlocksfeeRateAverage) * multiplier; + const lastTwoBlocksfeeRateAverageMultiplied = + (lastTwoBlocksFeeRate.reduce((a, b) => a + b) / lastTwoBlocksFeeRate.length) * multiplier; - const estimatedFeeRate = await getEstimatedFeeRate(bitcoinBlockchainAPIFeeURL); const estimatedFeeRateMultiplied = estimatedFeeRate * multiplier; return Math.max( diff --git a/tests/unit/bitcoin-functions.test.ts b/tests/unit/bitcoin-functions.test.ts index 10a3375..3c3d0c9 100644 --- a/tests/unit/bitcoin-functions.test.ts +++ b/tests/unit/bitcoin-functions.test.ts @@ -40,12 +40,6 @@ import { import { TEST_VAULT_UUID_1 } from '../mocks/ethereum.test.constants'; describe('Bitcoin Functions', () => { - describe('getFeeRate', () => { - it('should return the fee rate in satoshis per byte', async () => { - const feeRate = await getFeeRate('https://mempool.space'); - console.log(feeRate); - }, 30000); - }); describe('getInputIndicesByScript', () => { it('correctly retrieves one input index by script', () => { const transaction = Transaction.fromPSBT(