Skip to content

Commit 8f61ac4

Browse files
OttoAllmendingerllm-git
andcommitted
feat(abstract-utxo): extract default recovery fee rates into constants
Extract hard-coded fee rates into named constants for better maintainability and clarity. Use these constants in the recovery functions to ensure consistent fee calculation. Issue: BTC-2891 Co-authored-by: llm-git <[email protected]>
1 parent 1dd8a18 commit 8f61ac4

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

modules/abstract-utxo/src/recovery/backupKeyRecovery.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ type WalletUnspentJSON = utxolib.bitgo.WalletUnspent & {
3131

3232
const { getInternalChainCode, scriptTypeForChain, outputScripts, getExternalChainCode } = utxolib.bitgo;
3333

34+
// V1 only deals with BTC. 50 sat/vbyte is very arbitrary.
35+
export const DEFAULT_RECOVERY_FEERATE_SAT_VBYTE_V1 = 50;
36+
37+
// FIXME(BTC-2691): it is unclear why sweeps have a different default than regular recovery. 100 sat/vbyte is extremely high.
38+
export const DEFAULT_RECOVERY_FEERATE_SAT_VBYTE_V1_SWEEP = 100;
39+
40+
// FIXME(BTC-2691): it makes little sense to have a single default for every coin.
41+
export const DEFAULT_RECOVERY_FEERATE_SAT_VBYTE_V2 = 50;
3442
export interface FormattedOfflineVaultTxInfo {
3543
txInfo: {
3644
unspents?: WalletUnspentJSON[];
@@ -329,7 +337,9 @@ export async function backupKeyRecovery(
329337
utxolib.bitgo.addXpubsToPsbt(psbt, walletKeys);
330338
const txInfo = {} as BackupKeyRecoveryTransansaction;
331339
const feePerByte: number =
332-
params.feeRate !== undefined ? params.feeRate : await getRecoveryFeePerBytes(coin, { defaultValue: 50 });
340+
params.feeRate !== undefined
341+
? params.feeRate
342+
: await getRecoveryFeePerBytes(coin, { defaultValue: DEFAULT_RECOVERY_FEERATE_SAT_VBYTE_V2 });
333343

334344
// KRS recovery transactions have a 2nd output to pay the recovery fee, like paygo fees.
335345
const dimensions = Dimensions.fromPsbt(psbt).plus(isKrsRecovery ? Dimensions.SingleOutput.p2wsh : Dimensions.ZERO);
@@ -446,7 +456,9 @@ export async function v1BackupKeyRecovery(
446456
throw new Error('invalid recoveryDestination');
447457
}
448458

449-
const recoveryFeePerByte = await getRecoveryFeePerBytes(coin, { defaultValue: 50 });
459+
const recoveryFeePerByte = await getRecoveryFeePerBytes(coin, {
460+
defaultValue: DEFAULT_RECOVERY_FEERATE_SAT_VBYTE_V1,
461+
});
450462
const v1wallet = await bitgo.wallets().get({ id: params.walletId });
451463
return await v1wallet.recover({
452464
...params,
@@ -472,7 +484,9 @@ export async function v1Sweep(
472484

473485
let recoveryFeePerByte = 100;
474486
if (bitgo.env === 'prod') {
475-
recoveryFeePerByte = await getRecoveryFeePerBytes(coin, { defaultValue: 100 });
487+
recoveryFeePerByte = await getRecoveryFeePerBytes(coin, {
488+
defaultValue: DEFAULT_RECOVERY_FEERATE_SAT_VBYTE_V1_SWEEP,
489+
});
476490
}
477491

478492
const v1wallet = await bitgo.wallets().get({ id: params.walletId });

0 commit comments

Comments
 (0)