Skip to content

Commit

Permalink
Merge pull request #5147 from bithyve/testnet-fee
Browse files Browse the repository at this point in the history
Testnet: fee threshold
  • Loading branch information
Parsh authored Sep 12, 2024
2 parents e2e01ee + edcc2d7 commit ea12b90
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/services/wallets/operations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import ElectrumClient from 'src/services/electrum/client';
import { isSignerAMF } from 'src/hardware';
import idx from 'idx';
import RestClient, { TorStatus } from 'src/services/rest/RestClient';
import { hash256 } from 'src/utils/service-utilities/encryption';
import ecc from './taproot-utils/noble_ecc';
import {
AverageTxFees,
Expand All @@ -43,10 +44,10 @@ import {
import { Signer, Vault, VaultSigner, VaultSpecs } from '../interfaces/vault';
import { AddressCache, AddressPubs, Wallet, WalletSpecs } from '../interfaces/wallet';
import WalletUtilities from './utils';
import { hash256 } from 'src/utils/service-utilities/encryption';

bitcoinJS.initEccLib(ecc);
const ECPair = ECPairFactory(ecc);
const TESTNET_FEE_CUTOFF = 10;

const validator = (pubkey: Buffer, msghash: Buffer, signature: Buffer): boolean =>
ECPair.fromPublicKey(pubkey).verify(msghash, signature);
Expand Down Expand Up @@ -435,21 +436,21 @@ export default class WalletOperations {
// high fee: 10 minutes
const highFeeBlockEstimate = 1;
const high = {
feePerByte: 50,
feePerByte: 5,
estimatedBlocks: highFeeBlockEstimate,
};

// medium fee: 30 mins
const mediumFeeBlockEstimate = 3;
const medium = {
feePerByte: 25,
feePerByte: 3,
estimatedBlocks: mediumFeeBlockEstimate,
};

// low fee: 60 mins
const lowFeeBlockEstimate = 6;
const low = {
feePerByte: 12,
feePerByte: 1,
estimatedBlocks: lowFeeBlockEstimate,
};
const feeRatesByPriority = { high, medium, low };
Expand Down Expand Up @@ -479,6 +480,11 @@ export default class WalletOperations {
estimatedBlocks: lowFeeBlockEstimate,
};

if (config.NETWORK_TYPE === NetworkType.TESTNET && low.feePerByte > TESTNET_FEE_CUTOFF) {
// working around testnet fee spikes
return WalletOperations.mockFeeRates();
}

const feeRatesByPriority = { high, medium, low };
return feeRatesByPriority;
} catch (err) {
Expand Down Expand Up @@ -530,6 +536,11 @@ export default class WalletOperations {
estimatedBlocks: lowFeeBlockEstimate,
};

if (config.NETWORK_TYPE === NetworkType.TESTNET && low.feePerByte > TESTNET_FEE_CUTOFF) {
// working around testnet fee spikes
return WalletOperations.mockFeeRates();
}

const feeRatesByPriority = { high, medium, low };
return feeRatesByPriority;
} catch (err) {
Expand Down

0 comments on commit ea12b90

Please sign in to comment.