Skip to content
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

Mm2.1 refactor get trade fee #797

Merged
merged 34 commits into from
Feb 1, 2021
Merged

Conversation

sergeyboyko0791
Copy link

  • Add trade_preimage RPC call that returns the most approximated required fees that should be paid per whole swap
  • Refactor max_taker_vol using new get_sender_trade_fee, get_receiver_trade_fee, get_fee_to_send_taker_fee

* Implement the get_sender_trade_fee, get_receiver_trade_fee for UTXO
…er_trade_fee

* Replace can_i_spend_other_payment implementation with get_receiver_trade_fee
…erations

* Refactor max_taker_vol
* Take the trade fee into account on locked_amount called
* Move the check_balance_for_[maker/taker]_swap out into additional check
* Add Traceable trait
* Refactor get_locked_amount, get_locked_amount_by_other_swaps
* Replace TradePreimageValue::Max with TradePreimageValue::UpperBound
* Fix and expand test_max_taker_vol_dynamic_trade_fee (replace into docker_tests::qrc20_tests)
* Fix poisoning of docker_tests
* Replace 'trade_preimage' into lp_swap.rs
* Add 'dust' field to coins config
* Replace trade fees from [Maker/Taker]SwapMut to [Maker/Taker]SwapData
* Add check_base_coin_balance_for_swap
* Separate check_coin_balance_for_swap into check_my_coin_balance_for_swap and check_other_coin_balance_for_swap
* Add prepared trade_fee
Copy link
Member

@artemii235 artemii235 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! It is first review iteration :)

mm2src/coins/utxo/utxo_common.rs Outdated Show resolved Hide resolved
mm2src/coins/utxo/utxo_common.rs Show resolved Hide resolved
mm2src/coins/utxo/utxo_common.rs Outdated Show resolved Hide resolved
mm2src/coins/utxo/utxo_common.rs Outdated Show resolved Hide resolved
mm2src/coins/utxo/utxo_common.rs Outdated Show resolved Hide resolved
mm2src/coins/eth.rs Outdated Show resolved Hide resolved
mm2src/coins/eth.rs Outdated Show resolved Hide resolved
* Change volume within trade_preimage response from BigDecimal to MmNumber
* Replace try_other with try_map within generate_transaction
* Add the test_trade_preimage_fee_includes_change_output_anyway test
* Add UtxoCommonOps::preimage_trade_fee_required_to_send_outputs that encapsulate the change output fee
…onal)

* Replace Address::default() with the declared fee_addr_pub_key
Copy link
Member

@artemii235 artemii235 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review iteration number 2 🙂

mm2src/coins/eth.rs Outdated Show resolved Hide resolved
mm2src/coins/eth.rs Outdated Show resolved Hide resolved
mm2src/coins/eth.rs Outdated Show resolved Hide resolved
mm2src/coins/qrc20.rs Show resolved Hide resolved
Copy link
Member

@artemii235 artemii235 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sergeyboyko0791
Approved. Thanks a lot for your work on this!

@artemii235 artemii235 merged commit 25272e5 into mm2.1 Feb 1, 2021
@artemii235 artemii235 deleted the mm2.1-refactor-get-trade-fee branch February 1, 2021 12:52
@sergeyboyko0791
Copy link
Author

I think the changes have to be tested, because they could break the functionality of the mm2.
The most important cases:

Please note these cases should be tested for both dynamic and fixed transaction fee, also please test it for ETH and QRC20 coins

  • Call max_taker_vol and pass the volume as an argument of the sell/buy requests. It's desirable that the wallet balance become a zero after the swap is finished;
  • setprice with the max: true field should not fail (if the base and rel coin balances are not locked and sufficient for swap). Swap with the max volume should not fail (this must be guaranteed by the balance checking on the setprice RPC call).
  • buy, sell, setprice check the base coin balance correctly (ERC20, QRC20);
  • buy, sell, setprice take into account amount locked by other running swaps;
  • ETH, ERC20, QRC20 coins pay fee to spend other payment, so it will be nice to check if the eg ETH balance is locked by other swap (or is not sufficient to spend other payment), then buy, sell, setprice must fail.

@cipig
Copy link
Member

cipig commented Feb 3, 2021

https://dexapi.cipig.net/public/error.php?uuid=753e7602-fdd0-4e5b-a9ad-893a957cb065
Not sufficient balance: lp_swap:556] The total required KMD amount 22350.78678807672891565175067354475431222440756107137493599289272318350995977730050138146788426429371 is larger than available 22350.78678769
with latest mm2 (12cf6a0) on maker
the price was set with setprice and max:true

@artemii235
Copy link
Member

The swap started with

"maker_amount": "22350.78677807672891565175067354475431222440756107137493599289272318350995977730050138146788426429371"

somehow, it shouldn't have matched.

@sergeyboyko0791 Could you please check how it could happen? I've pushed the https://github.com/KomodoPlatform/atomicDEX-API/tree/mm2.1-fix-setprice-max branch with test_match_and_trade_max where I tried to recreate the problem. I hope it might help a bit.

@sergeyboyko0791
Copy link
Author

trade_preimage in docs PR

@cipig
Copy link
Member

cipig commented Feb 19, 2021

2 new KMD/BTC with maker_swap:298] !check_balance_for_maker_swap maker_swap:1486] Not sufficient balance: lp_swap:558] but on BTC side (makercoin is BTC)... both maker nodes are mine
https://dexapi.cipig.net/public/error.php?uuid=29c913a1-b9d7-4ab6-98b3-6843b994fbdc
https://dexapi.cipig.net/public/error.php?uuid=34143bf0-6576-4cad-8b86-5a20b1d5de7f

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants