Skip to content

fix(TPU): correct dexfee in check balance to prevent swap failures#2600

Merged
shamardy merged 15 commits intodevfrom
fix-TPU-dexfee
Oct 7, 2025
Merged

fix(TPU): correct dexfee in check balance to prevent swap failures#2600
shamardy merged 15 commits intodevfrom
fix-TPU-dexfee

Conversation

@dimxy
Copy link
Collaborator

@dimxy dimxy commented Aug 19, 2025

Two fixes for dexfee to prevent TPU swaps failures:

  • correct the platform coin in the params for check balance function (caused ETH swaps failures)
  • remove extra dexfee from the taker volume in check balance function (caused TPU swaps with max volume 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.

dimxy added 5 commits July 28, 2025 11:45
* 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
@dimxy dimxy requested a review from shamardy August 19, 2025 07:54
@dimxy dimxy self-assigned this Aug 19, 2025
@dimxy dimxy added priority: high Important tasks that need attention soon. bug: swap labels Aug 19, 2025
@dimxy dimxy marked this pull request as ready for review August 19, 2025 18:21
Copy link
Collaborator

@mariocynicys mariocynicys 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 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.

Comment on lines 2975 to 2988
// 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(),
)
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

what are the choice of these numbers based on?

Copy link
Collaborator Author

@dimxy dimxy Oct 6, 2025

Choose a reason for hiding this comment

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

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.

Copy link
Collaborator Author

@dimxy dimxy Oct 6, 2025

Choose a reason for hiding this comment

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

I am open to other suggestions regarding this check, btw

Comment on lines 2990 to 3001
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);
}
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

let's document why we minus or plus these tolerance values in each case.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Refactored this code and added comments: 95acde1

@shamardy shamardy marked this pull request as draft September 11, 2025 03:30
@dimxy dimxy marked this pull request as ready for review September 12, 2025 09:57
@shamardy
Copy link
Collaborator

shamardy commented Oct 6, 2025

@dimxy both test_v2_eth_erc20_kickstart and test_v2_erc20_eth_kickstart are failing

@dimxy
Copy link
Collaborator Author

dimxy commented Oct 7, 2025

@dimxy both test_v2_eth_erc20_kickstart and test_v2_erc20_eth_kickstart are failing

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)

@shamardy shamardy merged commit 347d8fc into dev Oct 7, 2025
19 of 25 checks passed
@shamardy shamardy deleted the fix-TPU-dexfee branch October 7, 2025 12:49
dimxy pushed a commit that referenced this pull request Oct 8, 2025
* 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)"
dimxy pushed a commit that referenced this pull request Oct 9, 2025
* 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)"
dimxy pushed a commit that referenced this pull request Oct 15, 2025
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2.6.0-beta bug: swap priority: high Important tasks that need attention soon.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants