Skip to content

Commit 56b62cc

Browse files
committed
feat(core): using feeRate from bria service
1 parent 03c773a commit 56b62cc

File tree

7 files changed

+32
-8
lines changed

7 files changed

+32
-8
lines changed

core/api/src/app/wallets/get-on-chain-fee.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,14 +164,14 @@ export const getMinerFeeAndPaymentFlow = async <
164164
const address = await builder.addressForFlow()
165165
if (address instanceof Error) return address
166166

167-
const minerFee = await onChainService.estimateFeeForPayout({
167+
const estimateRes = await onChainService.estimateFeeForPayout({
168168
amount: proposedBtcAmount,
169169
address,
170170
speed,
171171
})
172-
if (minerFee instanceof Error) return minerFee
172+
if (estimateRes instanceof Error) return estimateRes
173173

174-
return builder.withMinerFee(minerFee, speed)
174+
return builder.withMinerFee(estimateRes.fee, estimateRes.feeRate, speed)
175175
}
176176

177177
export const getOnChainFeeForBtcWallet = async <S extends WalletCurrency>(

core/api/src/domain/bitcoin/onchain/index.types.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ interface IOnChainService {
135135
}): Promise<PayoutId | OnChainServiceError>
136136
estimateFeeForPayout(
137137
args: EstimatePayoutFeeArgs,
138-
): Promise<BtcPaymentAmount | OnChainServiceError>
138+
): Promise<EstimateFeeForPayoutRes | OnChainServiceError>
139139
listPayoutQueues(): Promise<PayoutQueue[] | OnChainServiceError>
140140
}
141141

core/api/src/domain/payments/index.types.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ type OPFBWithAmount<S extends WalletCurrency, R extends WalletCurrency> = {
328328
type OPFBWithConversion<S extends WalletCurrency, R extends WalletCurrency> = {
329329
withMinerFee(
330330
minerFee: BtcPaymentAmount,
331+
feeRate: number,
331332
speed: PayoutSpeed,
332333
): Promise<OnChainPaymentFlow<S, R> | ValidationError | DealerPriceServiceError>
333334
withoutMinerFee(): Promise<

core/api/src/domain/payments/onchain-payment-flow-builder.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,7 @@ const OPFBWithConversion = <S extends WalletCurrency, R extends WalletCurrency>(
425425

426426
const withMinerFee = async (
427427
minerFee: BtcPaymentAmount,
428+
feeRate: number,
428429
speed: PayoutSpeed,
429430
): Promise<OnChainPaymentFlow<S, R> | ValidationError | DealerPriceServiceError> => {
430431
const state = await stateFromPromise(statePromise)
@@ -440,7 +441,7 @@ const OPFBWithConversion = <S extends WalletCurrency, R extends WalletCurrency>(
440441
minerFee,
441442
amount: state.btcProposedAmount,
442443
speed,
443-
feeRate: 5,
444+
feeRate,
444445
})
445446

446447
// Calculate amounts & fees

core/api/src/domain/wallets/withdrawal-fee-calculator.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ export const OnChainFees = ({
2020
}) => {
2121
const satoshis = Number(amount.amount)
2222

23+
if (feeRate <= 0) {
24+
return {
25+
totalFee: calc.add(minerFee, ZERO_SATS),
26+
bankFee: ZERO_SATS,
27+
}
28+
}
29+
2330
const dynamicRate = calculateDynamicFeeRate(satoshis, speed, feeRate)
2431
const baseMultiplier = calculateBaseMultiplier(speed, feeRate)
2532
const bankCost = calculateCostToBank(satoshis, speed, feeRate)

core/api/src/services/bria/index.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ export const OnChainService = (): IOnChainService => {
439439
address,
440440
amount,
441441
speed,
442-
}: EstimatePayoutFeeArgs): Promise<BtcPaymentAmount | OnChainServiceError> => {
442+
}: EstimatePayoutFeeArgs): Promise<EstimateFeeForPayoutRes | OnChainServiceError> => {
443443
const estimate = async ({
444444
speed,
445445
address,
@@ -448,7 +448,7 @@ export const OnChainService = (): IOnChainService => {
448448
speed: PayoutSpeed
449449
address: OnChainAddress
450450
amount: BtcPaymentAmount
451-
}): Promise<BtcPaymentAmount | BriaEventError> => {
451+
}): Promise<EstimateFeeForPayoutRes | BriaEventError> => {
452452
try {
453453
const queueName = queueNameForSpeed(speed)
454454
if (queueName instanceof Error) return queueName
@@ -460,10 +460,19 @@ export const OnChainService = (): IOnChainService => {
460460
request.setSatoshis(Number(amount.amount))
461461

462462
const response = await estimatePayoutFee(request, metadata)
463-
return paymentAmountFromNumber({
463+
464+
const estimateFee = paymentAmountFromNumber({
464465
amount: response.getSatoshis(),
465466
currency: WalletCurrency.Btc,
466467
})
468+
if (estimateFee instanceof Error) {
469+
return new UnknownOnChainServiceError(estimateFee)
470+
}
471+
472+
return {
473+
fee: estimateFee,
474+
feeRate: response.getFeeRate(),
475+
}
467476
} catch (error) {
468477
return new UnknownOnChainServiceError(error)
469478
}

core/api/src/services/bria/index.types.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ type UtxoSettled = {
5050
address: OnChainAddress
5151
blockNumber: number
5252
}
53+
54+
type EstimateFeeForPayoutRes = {
55+
fee: BtcPaymentAmount
56+
feeRate: number
57+
}
58+
5359
type PayoutSubmitted = {
5460
type: "payout_submitted"
5561
id: PayoutId

0 commit comments

Comments
 (0)