fix(TPU): correct dexfee in check balance to prevent swap failures#2600
fix(TPU): correct dexfee in check balance to prevent swap failures#2600
Conversation
* dev: improvement(`static mut`s): `static mut` removal (#2590) fix(orders): set subscription on kickstart and skip GC of own pubkeys (#2597) fix(ordermatch): ignore loop-back; clear on null root; reject stale keep-alives (#2580) fix(clippy): fix clippy warnings for #2565 (#2589) fix(Trezor): fix utxo and eth calls due to firmware changes (#2565) fix(utxo): calculate min_trading_vol based on fixed tx fees (#2564) feat(protocol): [0] solana support (#2586) fix(utxo): fix header deserialization; guard AuxPoW (#2583) chore(rust 1.89): make CI clippy/fmt pass (wasm32, all-targets) (#2581) fix(utxo): deserialize sapling root for PIVX block headers (#2572) improvement(dep-stack): security bumps (#2562) fix(utxo): correct block header deserialization for AuxPow and KAWPOW coins (#2563) feat(wallet-connect): impl BTC (UTxO) activation via WalletConnect (#2499) feat(utxo): add new fixed txfee option for DINGO-like coins (#2454) ci(pull-requests): review notification bot (#2468) improvement(walletconnect): return the `pairing_topic` in `new_connection` response (#2538) bless clippy (#2560) refactor(toolchain): use latest available stable compiler (#2557) feat(wallet): implement unified offline private key export API (#2542) chore(release): v2.3.0-beta (#2284) # Conflicts: # mm2src/mm2_main/tests/docker_tests/eth_docker_tests.rs
mariocynicys
left a comment
There was a problem hiding this comment.
Thanks for the fixes!
the last section of test_v2_eth_eth_kickstart_impl isn't straight forward to understand. maybe we can add some comments here and there.
| // add some tolerance | ||
| let (low_tol, high_tol) = if !is_token { | ||
| ( | ||
| // txfee with tolerance | ||
| BigDecimal::from_f64(0.0001).unwrap(), | ||
| BigDecimal::from_f64(0.0005).unwrap(), | ||
| ) | ||
| } else { | ||
| ( | ||
| // no fee, only tolerance | ||
| BigDecimal::from_f64(-0.0001).unwrap(), | ||
| BigDecimal::from_f64(0.0001).unwrap(), | ||
| ) | ||
| }; |
There was a problem hiding this comment.
what are the choice of these numbers based on?
There was a problem hiding this comment.
Those numbers mean that "amount + gas fee" for the swap are okay in some interval.
I did not want to calculate the exact amount (because we have other tests for that purpose)
so I just picked values from this test results and rounded them up and down to create a tolerance interval, to have some rough check.
My idea was to catch hard errors when swaps totally broken and swap produced obviously incorrect amounts.
There was a problem hiding this comment.
I am open to other suggestions regarding this check, btw
| if action == "sell" { | ||
| let low_diff = &volume + &low_tol; | ||
| let high_diff = &volume + &high_tol; | ||
| assert!(bal_0 - bal_1 >= low_diff, "{} >= {}", bal_0 - bal_1, low_diff); | ||
| assert!(bal_0 - bal_1 <= high_diff, "{} <= {}", bal_0 - bal_1, high_diff); | ||
| } else { | ||
| let low_diff = &volume - &high_tol; | ||
| let high_diff = &volume - &low_tol; | ||
| assert!(bal_1 - bal_0 >= low_diff, "{} >= {}", bal_1 - bal_0, low_diff); | ||
| assert!(bal_1 - bal_0 <= high_diff, "{} <= {}", bal_1 - bal_0, high_diff); | ||
| } | ||
| }; |
There was a problem hiding this comment.
let's document why we minus or plus these tolerance values in each case.
There was a problem hiding this comment.
Refactored this code and added comments: 95acde1
|
@dimxy both |
… to removed 1 gwei limit in increase_by_percent fn)
Fixed the tests (I had to change the check gas fee interval due to the fix in which we removed the 1 gwei gas_price minimum) |
* dev: fix(TPU): correct dexfee in check balance to prevent swap failures (#2600) fix(tests): fix/remove kmd rewards failing test (#2633) chore(ci): bump CI container image to debian bullseye-slim to match dev (#2641) chore(release): add changelog entries for v2.5.2-beta (#2639) chore(release): bump mm2 version to 2.5.2-beta (#2638) feat(ci): add macos universal2 build (#2628) fix(metrics): remove memory_db size metric (#2632) chore(rust 1.90): make CI clippy/fmt pass Revert "fix(ordermatch): ignore loop-back; clear on null root; reject stale keep-alives (#2580)" Revert "fix(orderbook): validate roots before commit (#2605)"
* dev: fix(TPU): correct dexfee in check balance to prevent swap failures (#2600) fix(tests): fix/remove kmd rewards failing test (#2633) chore(ci): bump CI container image to debian bullseye-slim to match dev (#2641) chore(release): add changelog entries for v2.5.2-beta (#2639) chore(release): bump mm2 version to 2.5.2-beta (#2638) feat(ci): add macos universal2 build (#2628) fix(metrics): remove memory_db size metric (#2632) fix(zcoin): exact-anchor witnesses in wasm get_spendable_notes (#2629) fix(evm-swapv2): no mempool inclusion required for maker payment validation (#2618) chore(rust 1.90): make CI clippy/fmt pass Revert "fix(ordermatch): ignore loop-back; clear on null root; reject stale keep-alives (#2580)" Revert "fix(orderbook): validate roots before commit (#2605)"
…2600) This corrects the platform coin in the params for check balance function which caused ETH swaps failures. It also removes extra dexfee from the taker volume in check balance function which caused TPU swaps with max volume failures.
Two fixes for dexfee to prevent TPU swaps failures:
Also updates TPU swap contracts and ABI byte code to fix TPU docker tests
TODO: add a test to validate spending max volume for TPU
TODO: maybe we should refactor check_balance_for_taker_swap for TPU because it was developed for legacy swaps: assumes legacy dex fee transaction but no TPU funding transaction.