KomodoPlatform / komodo-wallet-desktop

Komodo Wallet Desktop GUI
https://atomicdex.io
GNU General Public License v2.0
236 stars 204 forks source link

[BUG]: not enough balance error when starting swaps #2210

Open cipig opened 1 year ago

cipig commented 1 year ago

Sometimes i get the following error when i want to start swaps: image

I can't reliably reproduce it though... sometimes, after the error shows up, switching pair and then switching back to the initial pair "fixes" the problem. atm i can't get around it, no matter what i do... even entering a different volume shows the same error, which makes no sense, since the resulting amount of JJPY-PLG20 should be totally different... see this second screenshot image trying to buy 444 RTM (instead of 3927 shows the exact same error

the error shows up after clicking on "start swap"

cipig commented 1 year ago

i get this on KMD too

i click on an order in the orderbook to buy a coin (smart chain) with KMD and log shows

[20:14:41] [info] [qt.trading.page.cpp:1207] [3852795]: [determine_fees] trade_preimage answer received: [{"error":"rpc:211] dispatcher_legacy:141] dispatcher_legacy:158] taker_swap:2366] check_balance:75] Not enough KMD for swap: available 10617.45189773, required at least 10617.45189790213127413127413127413127413127413127413127413127413127413127413127413127413127413127413, locked by swaps Some(BigDecimal(\"0\"))"}]

if i then click on "Start Swap" in GUI, i get the same error in GUI and swap does not start, but log shows

[20:17:53] [debug] [main.prerequisites.hpp:87] [3852794]: Getting fees info... 1/50
[20:17:53] [info] [qt.trading.page.cpp:1207] [3852807]: [determine_fees] trade_preimage answer received: [{"result":{"base_coin_fee":{"coin":"DEX","amount":"0.00001","amount_fraction":{"numer":"1","denom":"100000"},"amount_rat":[[1,[1]],[1,[100000]]],"paid_from_trading_vol":true},"rel_coin_fee":{"coin":"KMD","amount":"0.00001","amount_fraction":{"numer":"1","denom":"100000"},"amount_rat":[[1,[1]],[1,[100000]]],"paid_from_trading_vol":false},"taker_fee":{"coin":"KMD","amount":"0.2629343629343629343629343629343629343629343629343629343629343629343629343629343629343629343629343629","amount_fraction":{"numer":"681","denom":"2590"},"amount_rat":[[1,[681]],[1,[2590]]],"paid_from_trading_vol":false},"fee_to_send_taker_fee":{"coin":"KMD","amount":"0.00001","amount_fraction":{"numer":"1","denom":"100000"},"amount_rat":[[1,[1]],[1,[100000]]],"paid_from_trading_vol":false},"total_fees":[{"coin":"DEX","amount":"0.00001","amount_fraction":{"numer":"1","denom":"100000"},"amount_rat":[[1,[1]],[1,[100000]]],"required_balance":"0","required_balance_fraction":{"numer":"0","denom":"1"},"required_balance_rat":[[0,[]],[1,[1]]]},{"coin":"KMD","amount":"0.2629543629343629343629343629343629343629343629343629343629343629343629343629343629343629343629343629","amount_fraction":{"numer":"3405259","denom":"12950000"},"amount_rat":[[1,[3405259]],[1,[12950000]]],"required_balance":"0.2629543629343629343629343629343629343629343629343629343629343629343629343629343629343629343629343629","required_balance_fraction":{"numer":"3405259","denom":"12950000"},"required_balance_rat":[[1,[3405259]],[1,[12950000]]]}]}}]

(i changed the amount to 1 before clicking on start swap, the max amount would have eaten all my balance)

so swap would work fine, but GUI does not let me start it because of the previous determine_fees error with the max amount

the initial error on trade_preimage is when the order would use the entire available balance and likely because GUI works with decimals in max_taker_vol: https://github.com/KomodoPlatform/atomicDEX-Desktop/blob/dev/src/core/atomicdex/pages/qt.trading.page.cpp#L761 but GUI should at least let me start the swap with a lower volume, for which the second determine_fees does not show an error... atm it is stuck with the error when i would buy by using my entire balance, which is not my intention

why is trade_preimage even called when i click on an order in orderbook? is that needed? can we disable it? i see no infos that are shown before clicking on "start swap" and then a new trade_preimage is called anyway it was added here: https://github.com/KomodoPlatform/atomicDEX-Desktop/commit/4b5f594fc23420fd03fb2622bbf5331f65b319f3

smk762 commented 1 year ago

why is trade_preimage even called when i click on an order in orderbook? is that needed? can we disable it? i see no infos that are shown before clicking on "start swap" and then a new trade_preimage is called anyway

@cipig some of the trade_preimage response is used to determine other values like max tradable volume after fees. As it is a slow method to respond, I suspect its race conditions that may cause a problem. There may be some newer API methods like max_maker_vol.

Related discussion at https://github.com/KomodoPlatform/AtomicDEX-mobile-private/pull/1726

During 0.5.8 RC testing we will test this more intensively to determine if issue still present and how it can be replicated.

cipig commented 1 year ago

image trying to sell 345 IRIS out of 360 for LTC and getting this error same error when i try to sell 50% (180 IRIS)

cipig commented 1 year ago

image it happens when you are about to buy a coin that needs spending your entire balance of the other coin (or close to it) error shown in Desktop log: [15:47:55] [info] [qt.trading.page.cpp:1207] [1054554]: [determine_fees] trade_preimage answer received: [{"error":"rpc:211] dispatcher_legacy:141] dispatcher_legacy:158] taker_swap:2398] check_balance:75] Not enough BCH for swap: available 0.01670641, required at least 0.016706817338158, locked by swaps Some(BigDecimal(\"0\"))"}]

it does not always happen, i assume a rounding error and that's also what the error message indicates i assume it happens in 50% of the cases based on price of order

after price changed, i could start the swap image uuid 2101f27e-8f7b-44f8-965a-b445e44f30c6

output in logs: [15:51:06] [info] [qt.trading.page.cpp:1207] [1054552]: [determine_fees] trade_preimage answer received: [{"result":{"base_coin_fee":{"coin":"LBC","amount":"0.0001","amount_fraction":{"numer":"1","denom":"10000"},"amount_rat":[[1,[1]],[1,[10000]]],"paid_from_trading_vol":true},"rel_coin_fee":{"coin":"BCH","amount":"0.00001","amount_fraction":{"numer":"1","denom":"100000"},"amount_rat":[[1,[1]],[1,[100000]]],"paid_from_trading_vol":false},"taker_fee":{"coin":"BCH","amount":"0.0001","amount_fraction":{"numer":"1","denom":"10000"},"amount_rat":[[1,[1]],[1,[10000]]],"paid_from_trading_vol":false},"fee_to_send_taker_fee":{"coin":"BCH","amount":"0.00001","amount_fraction":{"numer":"1","denom":"100000"},"amount_rat":[[1,[1]],[1,[100000]]],"paid_from_trading_vol":false},"total_fees":[{"coin":"BCH","amount":"0.00012","amount_fraction":{"numer":"3","denom":"25000"},"amount_rat":[[1,[3]],[1,[25000]]],"required_balance":"0.00012","required_balance_fraction":{"numer":"3","denom":"25000"},"required_balance_rat":[[1,[3]],[1,[25000]]]},{"coin":"LBC","amount":"0.0001","amount_fraction":{"numer":"1","denom":"10000"},"amount_rat":[[1,[1]],[1,[10000]]],"required_balance":"0","required_balance_fraction":{"numer":"0","denom":"1"},"required_balance_rat":[[0,[]],[1,[1]]]}]}}]

=========================

same error when using USDT-PLG20 i some other try: [16:03:11] [info] [qt.trading.page.cpp:1207] [1054558]: [determine_fees] trade_preimage answer received: [{"error":"rpc:211] dispatcher_legacy:141] dispatcher_legacy:158] taker_swap:2398] check_balance:75] Not enough USDT-PLG20 for swap: available 19.038574, required at least 19.03858033776136888262548262548262548262548262548262548262548262548262548262548262548262548262548263, locked by swaps Some(BigDecimal(\"0\"))"}]

========================

TUSD-PLG20 in a third try (idk why the error message pops up 2 times in a row)

[16:15:58] [info] [qt.trading.page.cpp:1207] [1070075]: [determine_fees] trade_preimage answer received: [{"error":"rpc:211] dispatcher_legacy:141] dispatcher_legacy:158] taker_swap:2398] check_balance:75] Not enough TUSD-PLG20 for swap: available 7.8938062860956194, required at least 7.893806354751101206177606177606177606177606177606177606177606177606177606177606177606177606177606178, locked by swaps Some(BigDecimal(\"0\"))"}]
[16:16:00] [info] [qt.trading.page.cpp:1207] [1070072]: [determine_fees] trade_preimage answer received: [{"error":"rpc:211] dispatcher_legacy:141] dispatcher_legacy:158] taker_swap:2398] check_balance:75] Not enough TUSD-PLG20 for swap: available 7.8938062860956194, required at least 7.893806354751101206177606177606177606177606177606177606177606177606177606177606177606177606177606178, locked by swaps Some(BigDecimal(\"0\"))"}]

with the corresponding error on GUI image

kaks25 commented 8 months ago

I still have this issue running on v0.6.1 image