Tutorial: Build a Flash Loan Arbitrage Bot on Infura

In this post, we go over the main concepts behind building a flash loan arbitrage bot: arbitrage, contract-based Ethereum transactions and optimistic transfer.

We then walk through how to structure a program with Infura that can watch for and execute on profitable arbitrage trades!

Let us know your thoughts and what you’d like us to show you next!

4 Likes

Hello, maybe I’m wrong, but I believe the code in part ii is incorrect.
An example where we borrow WETH on Uni to swap for DAI on Sushi.
The path is set so that we go from borrowed => not borrowed (WETH => DAI).
amountRequired calls getAmountsIn which gives us the input amount given an output amount and path passed in params. The code provided gets us the amount of WETH required given the amount of WETH borrowed. It should be getting the amount of DAI required given the amount of WETH borrowed. (DAI => WETH as path).
Also, not sure why amountRequired is passed into the output amount of amountReceived (this would just mean that you never profit).

3 Likes

Hey @0xdavinchee, and welcome to the Infura community! Thanks for the feedback - we’re checking into it and will update the blog post accordingly!

1 Like

Yes, what is the latest here? Also, I’m very new so I have a couple of questions.

In the .env what goes with FLASH_LOANER=? Where do you get that variable?

1 Like

hey, how are you, thanks for highlighting this issue, has anyone gotten back to you with regards to this issue?

hey - hope you are doing well, has anything been done with regards to this? also where can I learn more about the Building flash loan arbitrage with Infura, because if your code is for demonstration and is written wrong or has mistakes to stop users from profitting then is there a place to learn more and make sure I can correct the code. Thanks.

1 Like

hey, the FLASH_LOANER= variable should be the smart contract you’ve deployed to execute the arbitrage

1 Like

We’ve updated the articles to reflect that the immense amount of MEV almost certainly eliminates the possibility of actually running a successful arbitrage. The articles are educational around the concept rather than showing a specific way to code.

1 Like

Hey there :slight_smile:
May anyone can tell me more about
const spread = Math.abs((priceSushiswap / priceUniswap - 1) * 100) - 0.6;
i mean, how is it calculated and why “-0.6” operation at the end?

Thanks.

Pls someone tell me why - 0.6 at the end, is it a margin? why subtract 0.6 at the diff percentage?

I´m also having a similar issue in that whenever I perform getAmountsIn, the amountRequired ALWAYS supersedes the amountReceived via swapXXX function. Any ideas as to why is this happening?
Thank you

I really like to learn more about flash loan as a beginner. Thank your for this post :heart_eyes: