cardano-serialization-lib icon indicating copy to clipboard operation
cardano-serialization-lib copied to clipboard

Coin Selection doesn't consider the minimum ADA for change

Open abdelkrimdev opened this issue 3 years ago • 8 comments

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

abdelkrimdev avatar Nov 24 '22 09:11 abdelkrimdev

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.

lisicky avatar Nov 24 '22 10:11 lisicky

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.

abdelkrimdev avatar Nov 28 '22 09:11 abdelkrimdev

@lisicky when are you guys planning to fix this issue?

AdamMachera avatar Feb 12 '23 18:02 AdamMachera

@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

lisicky avatar Feb 20 '23 20:02 lisicky

@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

tqueri avatar Apr 19 '23 14:04 tqueri

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.

@lisicky Regarding this workaround: What is the recommended way to remove an output from a TransactionBuilder?

bugii avatar Jul 17 '23 20:07 bugii

@tqueri has it been fixed in version 11.5?

AdamMachera avatar Sep 05 '23 11:09 AdamMachera

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.

BEST-Thanawat avatar Sep 14 '23 23:09 BEST-Thanawat

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.

lisicky avatar Aug 28 '24 04:08 lisicky