Skip to content

@armada/sdk / index / computeBalances

Function: computeBalances()

computeBalances(txos, spentNullifiers, nullifyingKey, options, pendingSpends?): TokenBalance[]

Defined in: src/sync/balances.ts:109

Aggregate a wallet's TXOs into per-token spendable/pending balances.

  • A TXO is spent (contributes to nothing) iff its tree-scoped nullifier (txo.tree, getNullifier(nullifyingKey, txo.position)) appears in spentNullifiers.
  • A TXO with an optimistic in-flight spend (its nullifier in pendingSpends, but NOT yet confirmed-spent) contributes to pendingSpent — kept out of spendable/pending.
  • An otherwise-unspent TXO is spendable once it has at least finalityThreshold confirmations (blockNumber <= currentBlock - finalityThreshold), otherwise pending.

Pure and deterministic: output is sorted by tokenHash.

Parameters

txos

readonly TXO[]

spentNullifiers

readonly SpentNullifier[]

nullifyingKey

bigint

options

BalanceOptions

pendingSpends?

readonly PendingSpend[] = []

Returns

TokenBalance[]