galacticcouncil / hydration-node

Hydration node - Cross-chain liquidity protocol built with Polkadot-SDK

Home Page:https://hydration.net

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bug: balance check in router fails when providers of account changes during the trade

dmoka opened this issue · comments

Issue:

  • in router we still do the balance check, but only check if the user spent at least the amount we calculate for the trade
  • we use reducible_balance with mode Preservation.Expendable which behaves differently when the system.account.providers of the user account changes
  • during this trade, the number of providers changes, increased by one, leading to a different behaviour for the balance check, namely an off-by-ED error

Fix would be to always use reducible_balance with Preservation.Preserve so the ED is always deducted from balances, resulting in consistent behaviour.

First we need to fix a bug in orml package: open-web3-stack/open-runtime-module-library#986

Cases on prod:

It root cause is coming from other part too:

What happens is that the account of insufficient asset is killed, so the ED (1 HDX) is transferred back to the account. So our ensure_that_user_received_asset_out_at_most balance check fails, as the user have more balance with an ED.

Two solutions I can see:

  • check if the insufficient asset account is killed, so we can incorporate ED in the balance check
  • we discard the post balance checks. This might look easier first, but remember we added it back to prevent any issues like we had with stableswap a few weeks ago

Related: #810