tradingstrategy-ai/web3-ethereum-defi

Get revert reason of any tx and especially for failed trades

miohtama opened this issue · 3 comments

Uniswap trade analyzer should be able to tell why the trade failed

  • Too much slippage
  • Some internal Uniswap error
  • (There should be no other reasons if the tokens are not scam tokens)

As a bonus, trade analyzer should able to tell if the trade was reverted because of slippage. Though not sure how we can pick up this from the transaction receipt, I believe is going to be quite hard. The ”real” EVM nodes do not store the revert reason for very long time (few hundreds of blocks) and one might need to replay the transaction.

https://snakecharmers.ethereum.org/web3py-revert-reason-parsing/

This would be a research task of doing some little trades with Ganache and see what kind of data we can get out of JSON-RPC for the revert reason -if any. And then do the transaction replay trick.

Also Geth and Erigon behave differently. The latter might have much better JSON-RPC support for extracting revert reasons. Erigon only supported Ethereum mainnet and BSC though.

Ganache and Ethereum Tester unit tests should support this, so at least we can use this feature for internal testing even though we would need to look up the actual revert reasons on Etherscan on production.

Added in the master.