UTXOs are grouped by address type (P2PKH, P2SH-P2WPKH, or P2WPKH).
For a group to be considered the total value of the group must be greater or equal to twice the amount being sent.
If a group exists with the same address type as the address that is being spent to it is selected. If the above condition is not met, then a group with a different address type is selected. If a single group isn’t enough to cover the total value requirement, a second group will be selected.
UTXO(s) are selected until the total amount selected is greater or equal to the spend amount.
UTXOs resulting from a same transaction are never used together in a same set.
UTXOs of higher value replace UTXOs of lower value belonging to the same transaction.
All UTXOs from a same address (scriptpubkey) must be consumed within the same set.
Output addresses (scriptpubkeys) must be used exclusively as outputs and only once.
Set A contains the actual spend output and a change output.
Set B contains a “mix” output in the same amount and the same address type as the spend output and a change output.
The change outputs in each set use the same address type as the UTXO(s) for that set. The miner’s fee amount must be an even amount. Each set pays half of the miner’s fee by deducting exactly 50% from each change output.