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

avoid srcAmount 0 on call to reserve.getConversionRate (handle for token to token trades) #434

Open
ilanDoron opened this issue Sep 11, 2019 · 1 comment
Assignees

Comments

@ilanDoron
Copy link
Contributor

ilanDoron commented Sep 11, 2019

When calling getConversionRate with srcAmount 0, some reserves revert.
On simple trade (not token to token) getExpectedRate modifies srcAmount 0 to 1, to avoid divide by 0.
Token to token trades are run in two steps.
step 1 - token1 to eth.
step 2 - eth to token2.
If srcAmount on Token to eth is small, the Eth result will be 0 when calling step 2 eth to token.
this will cause a revert.

This issue will especially happen for off chain queries. where user doesn't set any srcAmount and uses 0
Expected rate will translate 0 to 1. query token to eth. eth result will usually be 0. and then next call for get rate - eth to token will revert.

this revert happens in permissionless reserve for example. and it will cause the whole call to revert.

@ilanDoron
Copy link
Contributor Author

ilanDoron commented Sep 11, 2019

Currently this revert is handled in get expected rate with assembly code that catches the revert and returns rate 0. so the transaction isn't reverted.
Can fix this issue between step 1 and step 2 of token to token. translate amount 0 to 1. or return 0 rate when Eth amount is 0.

after fix, remove expected rate assembly code...

@ilanDoron ilanDoron changed the title avoid srcAmount 0 on token to token trades avoid srcAmount 0 on call to reserve.getConversionRate (handle for token to token trades) Sep 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants