Skip to content

Commit

Permalink
chore: cleanup getFeeRate function and remove temporary test
Browse files Browse the repository at this point in the history
  • Loading branch information
Polybius93 committed Dec 16, 2024
1 parent d5236ae commit b31390f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
14 changes: 8 additions & 6 deletions src/functions/bitcoin/bitcoin-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 0 additions & 6 deletions tests/unit/bitcoin-functions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit b31390f

Please sign in to comment.