cardano-serialization-lib
cardano-serialization-lib copied to clipboard
Coin Selection doesn't consider the minimum ADA for change
add_inputs_from [LargestFirstMultiasset] doesn't consider the minimum ADA for change output, thus sometimes we don't have enough ADA in a tx's inputs to cover for minimum ADA in change output if we call add_inputs_from then call add_change_if_needed we get Not enough ADA leftover to include non-ADA assets in a change address
Hi @abdelkrimdev! It's a known issue, the current implementation of add_inputs_from doesn't consider a change value. Before we fix it, I suggest adding one more input with only ada for a temporary workaround. Or you can add one output with an expected change and call the add_inputs_from and after that, delete the output.
Yes, I already did that, but it's a hack, and it leads to some potential bugs in the future. I even built a mini coin selection here: https://github.com/MartifyLabs/mesh/blob/main/packages/module/src/core/CIP2.ts but fixing this at the CSL level could be much better.
@lisicky when are you guys planning to fix this issue?
@AdamMachera fix requires small redesign inside tx builder. I would say fix will be in 11.5 release. I will try to make it faster
@AdamMachera fix requires small redesign inside tx builder. I would say fix will be in 11.5 release. I will try to make it faster
Thanks @lisicky if I can help with anything let me know, I have a limited skillset in rust but for testing or anything
Hi @abdelkrimdev! It's a known issue, the current implementation of
add_inputs_fromdoesn't consider a change value. Before we fix it, I suggest adding one more input with only ada for a temporary workaround. Or you can add one output with an expected change and call theadd_inputs_fromand after that, delete the output.
@lisicky Regarding this workaround: What is the recommended way to remove an output from a TransactionBuilder?
@tqueri has it been fixed in version 11.5?
this error "Not enough ADA leftover to include non-ADA assets in a change address" happened to me when I used with_asset_and_min_required_coin which is DEPRECATED so I used with_asset_and_min_required_coin_by_utxo_cost instead.
Fixed by add_inputs_from_and_change function in the CSL 12.0.0, please use add_inputs_from_and_change instead add_inputs_from. Thanks @twwu123 for your implementation.