jamesbachini / DEX-Arbitrage

Example arbitrage trading bot
GNU General Public License v3.0
615 stars 350 forks source link

UNPREDICTABLE_GAS_LIMIT #13

Closed bchpete closed 2 years ago

bchpete commented 2 years ago

Hey, looked through your past issues and modifying the tx to include gasPrice didn't work out(neither did it work with the parameters I would normally use on hardhat with the specific network). const tx = await arb.connect(owner).dualDexTrade(router1, router2, baseToken, token2, amount, { gasPrice: 1000000000003, gasLimit: 500000 }); Do you have any other possible solutions to this error? If no, I'll have a deeper look in the coming days. reason: 'cannot estimate gas; transaction may fail or may require manual gas limit', code: 'UNPREDICTABLE_GAS_LIMIT',

jamesbachini commented 2 years ago

Sometimes you can get errors like that if the transaction will fail and it has nothing to do with gas. Someone else mentioned they had a similar problem when they pasted in a router or token address all in lower case without the correct capitalisation for the checksum. Might be something silly like that.

bchpete commented 2 years ago

Appreciate the fast feedback! I've just doublechecked all the addresses and sadly this was not the case. Here is a link with the changes included https://github.com/bchpete/DEX-Arbitrage/commit/abc8dd8dd336d088c79e2829bd4a0f9cb4e9208d if you'd like to further assist me with a solution. If I find a solution I will be notifying in this issue.

jamesbachini commented 2 years ago

Maybe try taking a look at the failed transaction in tenderly.co and seeing if that provides any more data on where it failed or why

bchpete commented 2 years ago

Decoding the data from the failing transaction gives me { "method": "estimateDualDexTrade", "types": [ "address", "address", "address", "address", "uint256" ], "inputs": [ "5d0bF8d8c8b054080E2131D8b260a5c6959411B8", "b93184fB3eEDb4d32150763578cA305488240c8e", "3743eC0673453E5009310C727Ba4eaF7b3a1cc04", "E1E655BE6F50344e6dd708c27BD8D66492d6ecAf", { "type": "BigNumber", "hex": "0x01cc274bf7984082" } ], "names": [ "_router1", "_router2", "_token1", "_token2", "_amount" ] } This doesn't lead me much closer to a solution as all the data seems to be correctly put in.

jamesbachini commented 2 years ago

There's not really much to go on that I can help you with. Maybe try looking at each address in the transaction in a block explorer to make sure it's correct for that chain.

voltaxvoltax commented 2 years ago

Hey!

I was having the same error, saw this post /https://github.com/ethers-io/ethers.js/discussions/2849" and I've updated ethers to version5.6.7 by doing "npm install --save ethers"

Now It gives another error:

Error: missing revert data in call exception; Transaction reverted without a reason string [ See: https://links.ethers.org/v5-errors-CALL_EXCEPTION ] (data="0x", transaction={"from":"MYADDRESS","to":"MYCONTRACT","data":"DATA","accessList":null}, error={"name":"ProviderError","code":-32000,"_isProviderError":true}, code=CALL_EXCEPTION, version=providers/5.6.7)

reason: 'missing revert data in call exception; Transaction reverted without a reason string', code: 'CALL_EXCEPTION', data: '0x',

Any idea how to fix this?

Thank you!

jamesbachini commented 2 years ago

The transaction is reverting. My best guess as to why this would be and a few things to check:-

  1. There is a wrong token address or it's not formatted with the correct checksum (caps)
  2. There is a wrong router address or correct address for a different chain
  3. The router isn't compatible or a fork of Uniswap v2/Pancakeswap etc. (Main one would be UniV3 which uses different functions)
akships commented 2 years ago

Also maybe the swap you want to make is not possible I guess eg pair not available.

smitch370 commented 2 years ago

As @kcedric mentioned the pair may not be available. I would check the dapp website. on the swap page, see if the token is available for swapping.

if you are trying to integrate a new dex, be sure to inspect the swap function of the router very carefully. for me I was trying to integrate KyberSwap on Fantom. Upon inspection of the SwapExactTokensforTokens function, there is an extra calldata path for the Kyber router contract.

But I was able to completely eliminate this error by carefully rebuilding and testing the routes a few at a time.

hope that helps!!