Fix interaction with max and unbounded overdraft
Fixes https://github.com/formancehq/ledger/issues/473
Bug explanation:
Each source is associated with an optional fallback account that is used to fund any missing amount from that source.
When using the max source, it will use the OP_TAKE_MAX instruction to cap the subsource's funding.
OP_TAKE_MAX returns the amount missing to max out (or 0), and the amount remaining if it was already maxed out.
When the subsource has no fallback, the amount missing is simply discarded
When the subsource has a fallback, the amount missing should be taken from it unconditionally to max out the funding, which should be done with the OP_TAKE_ALWAYS instruction.
@flemzord hope this bugfix can be merged soon :)
@edwardmp Yes, this PR will be merged into the v2 ledger. However, we need another fix for the v1 ledger.
@flemzord will this still get backported to v1? Thanks