DeXter-on-Radix / website

Community built order book dex on Radix.
https://dexteronradix.com/
6 stars 14 forks source link

Specifying MAX for non-XRD inputs lead to insufficient funds #383

Closed dcts closed 3 weeks ago

dcts commented 3 weeks ago

When we add max on a non-XRD input field with high precision, we get an "insufficient balance" error inside the wallet (with approximately 50% probability). This is most likely caused by adex.createExchangeOrderTx.

To Reproduce

  1. buy some test DEXTR tokens (on stokenet)
  2. ensure you have a high decimal amount in your balance, if you want to reproduce, ensure you have exactly 1238.5599423734525 DEXTR in your wallet (you can send the difference to another wallet)
  3. Go to DEXTR/XRD -> SELL -> specify MAX by clicking the Available: 1238.55 label
  4. Send transaction
  5. This error should apper: image

We are sending the full balance to adex.createExchangeOrderTx but for some reason the amount is then rounded in a weird way to ...38 instead of ...37.

To fix this we can simply truncate the amount we send to adex.createExchangeOrderTx to the 8th decimal (truncate, NOT round).

dcts commented 3 weeks ago

To reproduce this error, we used those inputs to adex.createExchangeOrderTx:

[
  'component_tdx_2_1crs8ud8rr680krgtlskauye7qnns5zdawdlspvcqceder6tysu884p',
  'MARKET',
  'SELL',
  'resource_tdx_2_1thrn8vw7lrxpej7enxmhd84mqd9f3cp97rf5qyy8jxa7gpxcnxr5uu',
  1238.5599423734525,
  -1,
  9999,
  4,
  'account_tdx_2_128t0tnge6cvufl8rc2nj6ushlamuk4fcl4ll889v4fhv57algulas9',
  'account_tdx_2_128t0tnge6cvufl8rc2nj6ushlamuk4fcl4ll889v4fhv57algulas9'
]