@exodus/bitcoin-api 5.2.1 → 5.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,15 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [5.2.2](https://github.com/ExodusMovement/assets/compare/@exodus/bitcoin-api@5.2.1...@exodus/bitcoin-api@5.2.2) (2026-11-26)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * **bitcoin-api:** include own pending change in spendable balances ([#9450](https://github.com/ExodusMovement/assets/issues/9450)) ([4d55ad2](https://github.com/ExodusMovement/assets/commit/4d55ad2e48c20ba66b6f51f511affc1882808e73))
12
+
13
+
14
+
6
15
  ## [5.2.1](https://github.com/ExodusMovement/assets/compare/@exodus/bitcoin-api@5.2.0...@exodus/bitcoin-api@5.2.1) (2026-11-26)
7
16
 
8
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exodus/bitcoin-api",
3
- "version": "5.2.1",
3
+ "version": "5.2.2",
4
4
  "description": "Bitcoin transaction and fee monitors, RPC with the blockchain node, other networking code.",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -60,5 +60,5 @@
60
60
  "type": "git",
61
61
  "url": "git+https://github.com/ExodusMovement/assets.git"
62
62
  },
63
- "gitHead": "93bdf266e3882ed6f2ca7ed5ccee3fd31e98dbe7"
63
+ "gitHead": "ee68ceadf6392aa8c2ff2a8ae2c6a7d7600e9ad7"
64
64
  }
package/src/balances.js CHANGED
@@ -1,13 +1,9 @@
1
1
  import { getUnconfirmedSentBalance } from '@exodus/asset-lib'
2
2
  import assert from 'minimalistic-assert'
3
3
 
4
+ import { findUnconfirmedSentRbfTxs } from './tx-utils.js'
4
5
  import { getUnconfirmedTxAncestorMap } from './unconfirmed-ancestor-data.js'
5
- import {
6
- getConfirmedOrRfbDisabledUtxos,
7
- getUnconfirmedUtxos,
8
- getUsableUtxos,
9
- getUtxos,
10
- } from './utxos-utils.js'
6
+ import { getSpendableUtxos, getUnconfirmedUtxos, getUsableUtxos, getUtxos } from './utxos-utils.js'
11
7
 
12
8
  export const getBalancesFactory = ({
13
9
  feeData: defaultFeeData,
@@ -38,9 +34,9 @@ export const getBalancesFactory = ({
38
34
  unconfirmedTxAncestor,
39
35
  })
40
36
 
41
- const spendableUtxos = getConfirmedOrRfbDisabledUtxos({
42
- asset,
37
+ const spendableUtxos = getSpendableUtxos({
43
38
  utxos: usableUtxos,
39
+ replaceableTxs: findUnconfirmedSentRbfTxs(txLog),
44
40
  allowUnconfirmedRbfEnabledUtxos,
45
41
  })
46
42
 
@@ -3,7 +3,7 @@ import lodash from 'lodash'
3
3
  import assert from 'minimalistic-assert'
4
4
 
5
5
  import { getChangeDustValue } from '../dust.js'
6
- import { getConfirmedOrRfbDisabledUtxos, getConfirmedUtxos } from '../utxos-utils.js'
6
+ import { getConfirmedUtxos, getSpendableUtxos } from '../utxos-utils.js'
7
7
  import { getExtraFee } from './fee-utils.js'
8
8
 
9
9
  const { sortBy } = lodash
@@ -47,6 +47,7 @@ export const selectUtxos = ({
47
47
  asset,
48
48
  utxosDescendingOrder,
49
49
  usableUtxos,
50
+ spendableUtxos,
50
51
  replaceableTxs,
51
52
  amount,
52
53
  feeRate,
@@ -224,25 +225,15 @@ export const selectUtxos = ({
224
225
 
225
226
  if (!spendUtxos) spendUtxos = UtxoCollection.createEmpty({ currency })
226
227
 
227
- // We can still spend our rbf utxos, but put them last
228
- let ourRbfUtxos = UtxoCollection.createEmpty({ currency })
229
- if (replaceableTxs) {
230
- for (const tx of replaceableTxs) {
231
- if (!tx.data.internalOutputs?.length && !tx.data.changeAddress) continue
232
- const internalUtxos = usableUtxos.getTxIdUtxos(tx.txId)
233
- ourRbfUtxos = ourRbfUtxos.union(internalUtxos)
234
- }
235
- }
236
-
237
- const spendableUtxos = getConfirmedOrRfbDisabledUtxos({
238
- asset,
228
+ spendableUtxos ??= getSpendableUtxos({
239
229
  utxos: usableUtxos,
230
+ replaceableTxs,
240
231
  allowUnconfirmedRbfEnabledUtxos,
241
232
  })
242
233
 
243
234
  const utxosArray = _toPriorityOrderedArray({
244
235
  utxosDescendingOrder,
245
- utxos: spendableUtxos.union(ourRbfUtxos),
236
+ utxos: spendableUtxos,
246
237
  })
247
238
 
248
239
  if (isSendAll) {
@@ -267,7 +258,7 @@ export const selectUtxos = ({
267
258
  )
268
259
  const remainingUtxosArray = _toPriorityOrderedArray({
269
260
  utxosDescendingOrder,
270
- utxos: spendableUtxos.union(ourRbfUtxos).difference(spendUtxos),
261
+ utxos: spendableUtxos.difference(spendUtxos),
271
262
  })
272
263
 
273
264
  while (selectedUtxosValue.lte(amount) && remainingUtxosArray.length > 0) {
@@ -330,6 +321,11 @@ export const getUtxosData = ({
330
321
  taprootInputWitnessSize,
331
322
  changeAddressType,
332
323
  }) => {
324
+ const spendableUtxos = getSpendableUtxos({
325
+ utxos: usableUtxos,
326
+ replaceableTxs,
327
+ allowUnconfirmedRbfEnabledUtxos,
328
+ })
333
329
  const {
334
330
  selectedUtxos,
335
331
  replaceTx,
@@ -337,6 +333,7 @@ export const getUtxosData = ({
337
333
  } = selectUtxos({
338
334
  asset,
339
335
  usableUtxos,
336
+ spendableUtxos,
340
337
  replaceableTxs,
341
338
  amount,
342
339
  feeRate,
@@ -358,13 +355,7 @@ export const getUtxosData = ({
358
355
 
359
356
  const replaceUtxos = replaceTx ? usableUtxos.getTxIdUtxos(replaceTx.txId) : empty
360
357
 
361
- const spendableUtxos = getConfirmedOrRfbDisabledUtxos({
362
- asset,
363
- utxos: usableUtxos,
364
- allowUnconfirmedRbfEnabledUtxos,
365
- }).union(replaceUtxos)
366
-
367
- const spendableBalance = spendableUtxos.value
358
+ const spendableBalance = spendableUtxos.union(replaceUtxos).value
368
359
 
369
360
  const extraFeeCpfp = selectedUtxos?.size
370
361
  ? asset.currency.baseUnit(
@@ -10,7 +10,7 @@ import { selectUtxos } from '../fee/utxo-selector.js'
10
10
  import { createPsbtWithMetadata } from '../psbt-builder.js'
11
11
  import { findUnconfirmedSentRbfTxs } from '../tx-utils.js'
12
12
  import { getUnconfirmedTxAncestorMap } from '../unconfirmed-ancestor-data.js'
13
- import { getUsableUtxos, getUtxos } from '../utxos-utils.js'
13
+ import { getSpendableUtxos, getUsableUtxos, getUtxos } from '../utxos-utils.js'
14
14
  import { authenticateReplacement } from './authenticate-replacement.js'
15
15
  import { createInputs, createOutput, getBlockHeight, getNonWitnessTxs } from './tx-create-utils.js'
16
16
 
@@ -399,8 +399,13 @@ const transferHandler = {
399
399
 
400
400
  const { processedAddress, useCashAddress } = processAddress({ asset, toAddress })
401
401
 
402
- // Get replaceable transactions
402
+ // Chaining spends existing change; only replacing the parent requires authentication.
403
403
  let replaceableTxs = findUnconfirmedSentRbfTxs(context.txSet)
404
+ const spendableUtxos = getSpendableUtxos({
405
+ utxos: context.usableUtxos,
406
+ replaceableTxs,
407
+ allowUnconfirmedRbfEnabledUtxos,
408
+ })
404
409
 
405
410
  if (authenticateReplacementTransactions) {
406
411
  const authenticated = []
@@ -450,6 +455,7 @@ const transferHandler = {
450
455
  } = selectUtxos({
451
456
  asset,
452
457
  usableUtxos: context.usableUtxos,
458
+ spendableUtxos,
453
459
  replaceableTxs,
454
460
  amount: utxoParams.sendAmount,
455
461
  feeRate: utxoParams.feeRate,
@@ -6,8 +6,9 @@ import assert from 'minimalistic-assert'
6
6
 
7
7
  import { setBtcErrorCode, toBtcSendError } from '../errors.js'
8
8
  import { selectUtxos } from '../fee/utxo-selector.js'
9
+ import { findUnconfirmedSentRbfTxs } from '../tx-utils.js'
9
10
  import { getUnconfirmedTxAncestorMap } from '../unconfirmed-ancestor-data.js'
10
- import { getUsableUtxos, getUtxos } from '../utxos-utils.js'
11
+ import { getSpendableUtxos, getUsableUtxos, getUtxos } from '../utxos-utils.js'
11
12
 
12
13
  const DUST_VALUES = {
13
14
  P2WPKH: 294,
@@ -48,6 +49,11 @@ export const getCreateBatchTransaction = ({
48
49
  const { selectedUtxos, fee } = selectUtxos({
49
50
  asset,
50
51
  usableUtxos,
52
+ spendableUtxos: getSpendableUtxos({
53
+ utxos: usableUtxos,
54
+ replaceableTxs: findUnconfirmedSentRbfTxs(txSet),
55
+ allowUnconfirmedRbfEnabledUtxos,
56
+ }),
51
57
  amount,
52
58
  feeRate: feeData.feePerKB,
53
59
  receiveAddresses,
@@ -225,6 +225,16 @@ export function getConfirmedOrRfbDisabledUtxos({ utxos, allowUnconfirmedRbfEnabl
225
225
  return utxos.filter((utxo) => utxo.confirmations > 0 || !utxo.rbfEnabled)
226
226
  }
227
227
 
228
+ // Our pending outgoing transactions can still be chained.
229
+ export function getSpendableUtxos({ utxos, replaceableTxs, allowUnconfirmedRbfEnabledUtxos }) {
230
+ let spendableUtxos = getConfirmedOrRfbDisabledUtxos({ utxos, allowUnconfirmedRbfEnabledUtxos })
231
+ for (const tx of replaceableTxs ?? []) {
232
+ if (!tx.data.internalOutputs?.length && !tx.data.changeAddress) continue
233
+ spendableUtxos = spendableUtxos.union(utxos.getTxIdUtxos(tx.txId))
234
+ }
235
+ return spendableUtxos
236
+ }
237
+
228
238
  function filterDustUtxos({ utxos, feeData }) {
229
239
  if (feeData.utxoDustValue) {
230
240
  return utxos.filter((utxo) => utxo.value.toBaseNumber() > feeData.utxoDustValue)