Skip to main content

consolidate

export function consolidate(props: {
  excludeAssets: AssetClass[]
  includeAssets: AssetClass[]
  maxUtxos??: number
}): <SC extends SpendingCredential = SpendingCredential>(
  utxos: TxInput<SC>[],
  amount: Value
) => [TxInput<SC>[], TxInput<SC>[]]

First select the smallest utxos that contain only includeAssets (ignoring pure-ADA UTXOs if it ADA isn't in includeAssets)

  • simple use the selectSmallestFirst algorithm for this, filtering out UTxOs that contain asset classes that aren't in includeAssets nor in amount
  • if the first selection fails (eg. due to dirty UTxOs), retry by only filtering out UTxOs that contain asset classes in excludeAssets

Keep adding utxo for the left-over list (without additional sorting) until maxUtxos is reached

All UTxOs contain some lovelace, so require special treatment:

  • pure lovelace UTxOs are treated as containing the lovelace assetClass
  • UTxOs that contain lovelace in addition to other assetClasses are treated as containing those other assetClasses (but not lovelace)

Arguments

1. props

props: {
  excludeAssets: AssetClass[]
  includeAssets: AssetClass[]
  maxUtxos??: number
}

Returns

<SC extends SpendingCredential = SpendingCredential>(
  utxos: TxInput<SC>[],
  amount: Value
) => [TxInput<SC>[], TxInput<SC>[]]