-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UTXO Consolidation Helpers #3645
Comments
This is a great sketch. As mentioned, enabling this behavior by default can be tricky since it could result in multiple transactions being submitted upfront. Providing this functionality through additional parameters is a good approach, as it allows users to control when and how consolidation occurs. |
@nedsalk Let's focus on the helper methods first - did you think about a simple API to get started? const account = new Account(ADDRESS, provider);
account.consolidateCoins()
account.splitCoin() |
@arboleya below is the full consolidation workflow for both base and non-base assets. UTXO consolidationflowchart TD
Start["Consolidate coins"] -->
|Select asset id| get_all_coins("Get coins (all pages)") -->
more_coins_than_max_inputs(count >= max_inputs?) -->
|No| is_base_asset("Consolidating base asset?") -->
|No| get_resources_for_less("Call getResourcesToSpend to fund tx with one base input, all non-base inputs, and two outputs") -->
fill_up_all("Combine received base asset resources and as many non-base asset coins as possible") -->
at_least_two_non_base("There are at least two non-base inputs in the combination?") -->
|Can't consolidate one coin, too many base asset dust coins, consider first consolidating them| throw
at_least_two_non_base -->
|Yes| verify_resources_can_fund("Verify resources can still fund tx after they have been added") -->
|No| refund_tx("Call getResourcesToSpend to fund this updated tx") -->
fill_up_all
verify_resources_can_fund -->
|Yes| prepare_script_tx("Prepare tx with coins, check validity (amount > maxFee)")
is_base_asset -->
|Yes| select_all_coins("Select all coins") -->
prepare_script_tx
more_coins_than_max_inputs -->
| Yes| is_base_asset_2("Consolidating base asset?") -->
|No| get_resources_two_outputs("Call getResourcesToSpend to fund tx that has max fake inputs and two outputs") -->
fill_up_max("Combine funding resources and consolidation coins until max_inputs reached")
is_base_asset_2 -->
|Yes| get_resources_one_output("Call getResourcesToSpend to fund tx that has max fake inputs and one output") -->
fill_up_max("Combine resources for funding and consolidation coins until max_inputs reached") -->
prepare_script_tx
prepare_script_tx -->
|Invalid| throw
prepare_script_tx -->
|Valid| send_tx("Send transaction and await")
send_tx --> |Success| coins_remaining{"Remaining unconsolidated coins > 1?"}
send_tx --> |Failure| throw("Throw, put results of previous transactions on error")
send_tx --> |SqueezedOut| throw
coins_remaining --> |Yes| more_coins_than_max_inputs
coins_remaining --> |No| return_to_user(Return transactions and coins to user)
|
Problem
N
inputsN
coinsActionable Items
We need to think about two phases:
split
andconsolidation
Provide an automated flow to consolidate coins on the fly during transaction funding/submissionAutomatic UTXO Consolidation
Because UTXO consolidation will use gas, it's tricky to enable it by default.
However, we could..
..offer an extra submission method or add parameters to the existing one.
The idea is to have the flow available, but it should be opt-in.
Here's a first sketch:
The text was updated successfully, but these errors were encountered: