We talk about the WingCash liquidity algorithm fairly often. It’s time to introduce it properly.
The liquidity algorithm is a bit of software that chooses the best cash to send for a particular transfer. It applies constraints and priorities. The essence of the liquidity algorithm is implemented by this source code:
The Liquidity constructor requires a sender, recipient, and uid_type. Other constraints may be provided for special kinds of transfers. Notably, the constructor does not accept an amount, and it is usually not constrained by currency, because the code is used both for building payment forms and for validating payments.
The liquidity algorithm enforces certain rules; for example, it ensures that closed-loop cash can not be sent to a bank account. It leaves the enforcement of other rules to higher layers such as SendPlan.
Currently, there are up to 8 priority levels. The highest priority is for expiring cash being sent back to its issuer. The lowest priority is for cash being sent as a non-payment. (WingCash includes an ability to send cash for special purposes; the transfer is called a non-payment.)
The liquidity algorithm has been surprisingly effective. It tends to make good choices about what to send, leading to a good user experience with minimal user effort. When paying for things, people are rarely interested in choosing every payment detail.