Skip to content

Commit ea21bc9

Browse files
committed
check minimum relay fee in bitcoin fee config
1 parent c59109c commit ea21bc9

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

packages/hooks-bitcoin/src/tx/fee.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ import { action, computed, makeObservable, observable } from "mobx";
1313
import { useState } from "react";
1414
import { CoinPretty, Dec } from "@keplr-wallet/unit";
1515
import { InsufficientFeeError } from "./errors";
16-
import { BitcoinQueriesStore } from "@keplr-wallet/stores-bitcoin";
16+
import {
17+
BitcoinQueriesStore,
18+
MIN_RELAY_FEE,
19+
} from "@keplr-wallet/stores-bitcoin";
1720

1821
export class FeeConfig extends TxChainSetter implements IFeeConfig {
1922
@observable
@@ -88,10 +91,20 @@ export class FeeConfig extends TxChainSetter implements IFeeConfig {
8891
return undefined;
8992
}
9093

91-
return new CoinPretty(
92-
this.amountConfig.currency,
93-
this.txSizeConfig.txSize * this.feeRateConfig.feeRate + this.remainder
94+
if (this.txSizeConfig.txSize <= 0) {
95+
return new CoinPretty(this.amountConfig.currency, new Dec(0));
96+
}
97+
98+
const feeDec = new Dec(
99+
Math.ceil(this.txSizeConfig.txSize * this.feeRateConfig.feeRate) +
100+
this.remainder
94101
);
102+
const minRelayFeeDec = new Dec(MIN_RELAY_FEE);
103+
if (feeDec.lt(minRelayFeeDec)) {
104+
return new CoinPretty(this.amountConfig.currency, minRelayFeeDec);
105+
}
106+
107+
return new CoinPretty(this.amountConfig.currency, feeDec);
95108
}
96109

97110
return new CoinPretty(this.amountConfig.currency, this._value);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export const DUST_THRESHOLD = 546;
22
export const BRANCH_AND_BOUND_TIMEOUT_MS = 1000;
3-
export const MIN_RELAY_FEE = 157;
3+
export const MIN_RELAY_FEE = 122;
44
export const MAX_SAFE_OUTPUT = 2 ** 53 - 1;
55
export const MAX_BITCOIN_SUPPLY = 210000000000000;

0 commit comments

Comments
 (0)