Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Peatio rounds ETH amounts to 16 decimal points #2851

Open
antonDigitalMagic opened this issue Mar 5, 2021 · 3 comments
Open

Peatio rounds ETH amounts to 16 decimal points #2851

antonDigitalMagic opened this issue Mar 5, 2021 · 3 comments

Comments

@antonDigitalMagic
Copy link

The bug was found using the opendax 2-4-stable branch with eth mainnet.

We've sent deposit to the User's deposit address, the amount received is 20447946344588791 Wei. According to etherscan.

This is 0,020447946344588791 Ether (18 decimal places)

Collection fee daemon logs:
{"level":"WARN","time":"2021-03-05 09:53:03","message":"The deposit was spreaded in the next way: [{:to_address=>"0xb1bf8eaab5d4c7d8608df400938bcba30c91ea0e", :amount=>"0.0204479463445888", :currency_id=>"eth", :status=>"pending"}]"}

Collection daemon logs:
#<Peatio::Wallet::ClientError: Insufficient funds. The account you tried to send transaction from does not have enough funds. Required 20447946344588800 and got: 20447946344588791. (-32010)>"}

As you can see the Deposit amount has been rounded from 18 decimal places (0,020447946344588791) to 16 decimal places (0.0204479463445888) which is incorrect as in ethereum network the decimal limits is 18 NOT 16.

This problem has been caused by the MySQL Database fields configuration which is decimal(32,16) e.g. 16 decimal places.

So in case the number is more than 16 decimal places and it gets round UP, then deposit is uncollectable

The issue should be fixed for both deposits and withdraws

My view of a fix is to bump up all fields with decimal(32,16) to decimal(32,18), and add tests which check that numbers with 18 decimal places in ETH get parsed correctly by the system.

@martianatwork
Copy link

Are you sure that this is fixing the issue? As i believe we have to round the amount down, if you can add a test case that would be great!

@antonDigitalMagic
Copy link
Author

Are you sure that this is fixing the issue? As i believe we have to round the amount down, if you can add a test case that would be great!

The issue is that ETH can have up to 18 decimal points and DB currently allows only 16.

I want to add some tests cases, but its hard for me to stratup peatio tests locally on a MAC. If you’re willing to contribute some test cases, feel free to do so.

@martianatwork
Copy link

@antonDigitalMagic I think you are missing a point, yes your patch partially fixes the issue but not a proper solution. I believe almost all exchanges use ETH with 8 decimals, the problem is not about the storing the value but about the rounding.

Peatio will round the deposit while collecting and this is where 0.0204479463445888 will become 0.02044795 when it should have been 0.02044794

I hope this explains, i will submit a PR to fix this probably in the next week

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants