smart-contracts
smart-contracts copied to clipboard
avoid srcAmount 0 on call to reserve.getConversionRate (handle for token to token trades)
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.
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...