-
Notifications
You must be signed in to change notification settings - Fork 37
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
Get token list for self-sell task on Gnosis Chain #82
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor nit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for implementing this so quickly. 🚀
Just nits, overall the rounding issues probably shouldn't cause problems but if it's easy enough to use bigints it should probably be done.
parseFloat(token.exchange_rate) * | ||
(parseInt(value) / Math.pow(10, parseInt(token.decimals))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Parsing the value
and 10**decimals
can both overflow the safe integer number range so the numbers would get converted to floats resulting in rounding issues.
Could we use BigInts
here instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think I can avoid a conversion to float anywhere here. I don't know the precision of exchange_rate
, so the best I can do is saying it's a float, which still offers some decent precision. Once this is a float, everything will need to be converted to float and so parsing as BigInt doesn't really help for precision. At first I tried to replace everything with Number(BigInt(value) / 10n ** BigInt(token.decimals))
, which I realized was just going to create much worse issues!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True. Unless we have something like a BigRational
indeed the best option would be to use floats here. Doesn't look like ethers has something like that.
Also IIRC we end up getting quotes for all these tokens which should be more accurate anyway so the worst thing that could happen is that some of the tokens should get drained but doesn't. But then it will probably be drained the next time if the buffers keep accumulating that token.
274d433
to
def777c
Compare
Pull Request Test Coverage Report for Build 8702820726Details
💛 - Coveralls |
This fixes (at least on Gnosis Chain) issue #74.
Adds support for fetching the token lists on Gnosis Chain/xdai. Api source is blockscout, see docs here.
Test Plan
Try the script on xdai. Note the updated parameters.
Output
Notice that the tokens that the script suggests to withdraw are consistent with those on Gnosisscan (and the ignored tokens are next in the row).