yuichiroaoki / poly-flashloan-bot

Flashloan Bot on Polygon
https://yuichiroaoki.medium.com/flashloan-bot-on-polygon-part-2-3eae0ac33986?sk=80821da4ca1d0462c7c9ae617df56bdd
MIT License
302 stars 192 forks source link

Fail with error 'SafeERC20: low-level call failed' #93

Closed Sahilkhurana closed 2 years ago

Sahilkhurana commented 2 years ago

Hi,

Have successfully deployed the contract. The bot did spot an opportunity but Tx failed with above error. Any idea what might be wrong?

Thanks

yuichiroaoki commented 2 years ago

Probably because the dodo pool didn't have enough tokens for you to borrow. You should check the loan token balance of dodo pool before the execution of flash loan call.

rinconcsc commented 2 years ago

Hi,

Have successfully deployed the contract. The bot did spot an opportunity but Tx failed with above error. Any idea what might be wrong?

Thanks

Hi @Sahilkhurana

Did you find a profitable arbitrage opportunity? Did you modified anything of the configuration of the flash loan, the gas fee or the token? I am really interested in this project but I have not been successful yet :(

Thanks for your help 👍

Sahilkhurana commented 2 years ago

Thanks @yuichiroaoki I was using ETH/USDC pool which Ideally should have sufficient token balance. Anyways, I updated to a bigger pool which has better token balance. The bot spotted another opportunity but the transaction again failed. https://polygonscan.com/tx/0x11b74a634b4491bf66ec0a472c3a4e44d15467193b92644542b44c34bba3182f Did it get front run by someone?

Hi @rinconcsc , I have modified the configurations in the following way

  1. Added some more token pools from Dodo for flash loan - specifically USDC/USDT pool
  2. Token selection for Arb - I guess its mostly about doing research on coins/token which might be prone to variation and cross checking the exchanges with liquidity on these pools and selecting the right exchange/token combination. Having said that, as I have written here, I am yet to have a successful transaction.
yuichiroaoki commented 2 years ago

@Sahilkhurana I think that USDC/USDT pool is dodo v1 contract and doesn't have the flash loan function, so the tx failed. You can use WMATIC/USDC pool.

Sahilkhurana commented 2 years ago

@yuichiroaoki Thank you ! I didn't realize this and seems to be the issue for above transaction. Now sticking to WMATIC/USDC pool and check if I am able to find another opportunity.

Sahilkhurana commented 2 years ago

@yuichiroaoki I did change the pool and the bot could spot few opportunities post that. One of the opportunities was as big as 3% (USD 300) but all of 3 Txns failed with 'Fail with error 'Not enough amount to return loan'

Too slow?

https://polygonscan.com/tx/0xaac8ab6f48ec1d4b39790b316269462e951dfd667b18e173a7a1c5d184ee4192 https://polygonscan.com/tx/0xad898c4e5832039834a6890b1e8f3eafe9d8359f3a245d938cadc31231cd84a0 https://polygonscan.com/tx/0xd096ff213ac959e5ff4526ab6b732fbf91f31a25ae694f606a278838e262f161

yuichiroaoki commented 2 years ago

Yes. All you can do is increasing gas fee.

Sahilkhurana commented 2 years ago

extraGas variable in flashloan.ts is the best way to handle this? . I had earlier tried playing with gasLimit which led me run into errors.

yuichiroaoki commented 2 years ago

Yes, increasing extraGas might help.

https://github.com/yuichiroaoki/poly-flashloan-bot/blob/4590e267bcb0b4ad8628de283e4fc035ec0693e7/src/flashloan.ts#L46

Sahilkhurana commented 2 years ago

@yuichiroaoki I did try it and it still won't succeed. I noticed that there is a gap of 3-4 blocks in detecting the opportunity and the block # to which the Txn makes its way on MATIC network. I think this duration is enough to lose the arbitrage opportunity due to which the flashloan fails.

rinconcsc commented 2 years ago

@Sahilkhurana so this means that the bot is still not profitable?

Sahilkhurana commented 2 years ago

Yes @rinconcsc .I have been able to spot opportunities but unfortunately all 50+ transactions have failed.