Flashloan Bot on Polygon Part.1
Let’s build a simple flashloan bot on polygon with 1inch API and DODO!
Today I’m going to show you a simple flashloan bot on polygon using 1inch api and DODO.
Flashloan Smart Contract
In the previous story, I talked about how to implement flashloan without flashloan fee. Here is the link of the previous story. You can find the smart contract code used in this flashloan bot.
Detect Arbitrage Opportunities
It’s important to check price data and see if there’s an arbitrage opportunity before executing flashloan because you have to pay transaction fees for even failed transactions.
You can get price data on Defi protocols by executing view functions which costs nearly nothing because Infura and Alchemy have a generous free tier.
But, is there any way I get the best route on polygon easily??
1inch API
With 1inch API, you can get the best route and the price data for free. The flashloan bot gets the prices of each Uniswap fork and implements flashloan when it finds an arbitrage opportunity.
Why only Uniswap forks ?? Why not DODO??
Well I’m going to talk about that !
Easy to Integrate
One of the great things about building a flashloan bot on polygon is that there’s so many Uniswap fork Defi protocols so that you can use the same interface, which is uniswap, for trading using smart contracts.


swapping function on Uniswap fork code
These protocols are a fork of Uniswap V2, so it’s pretty easy to integrate into the flashloan smart contract.
Issues
Swap on DODO
When I look at the trading route on 1inch UI, I noticed that DODO protocol usually offers better prices, so I wanted to integrate it into the trading protocols like the all Uniswap fork protocols.
However, DODO has their own trading interface like this. You cannot just copy & paste the protocol address like Uniswap fork protocols. You need to have a swap function of DODO on your flashloan smart contracts and some logic to calculate a trading direction used in the trading function on somewhere in the flashloan bot code.
Also, you cannot swap on the same pool you borrowed your flashloan from and probably that’s because of a security reason (re-entrancy attack). This increases the complexity of the flashloan bot logic.
For these reasons, I have not integrated DODO into the flashloan bot.
Using Call Data from 1inch API
You get call data from 1inch API which can be used in a trading bot so you can swap tokens with the best route that 1inch calculates off-chain.

I thought of using call data you receive from 1inch API on the flashloan smart contract. That way, the flashloan contract have to only borrow flashloan, execute the call data from 1inch API, and pay back the loan. You don’t have to think about the trading routes or writing each swap function for a specific Defi because 1inch contracts deal with it.
However, the API call for 1inch always fails for some reasons.
I assume 1inch API checks if fromTokenAddress, which is the flashloan contract address in this case, has enough the amount of the fromTokenAddresstoken in the background, and of course, the flashloan contract doesn’t have that amount of the token before calling flashloan function.
If you have enough amount of swapping tokens up front, then what’s the point of flashloan 😂
Hope this helps. Thank you for reading😁
Flahsloan Bot Code | Flashloan Smart Contract Code
Join Coinmonks Telegram Channel and Youtube Channel learn about crypto trading and investing




