I just have to say that this has been immensely frustrating. Iâm writing this in the hopes that someone else who is also massively frustrated will read this and maybe get some value from it.
If youâre just a trader and want the easy step-by-step without learning Solidity then youâre pretty screwed with flash loans. Flash loans are the unholy union of Solidity programming and trading, and you have to know more programming than trading in order to make them work. Any flash loan apps that donât require coding (like Furucombo) will almost never procure a profitable opportunity because thereâs always someone faster than you who finds it firstâor rather, itâs their bot that finds it first. Programmers will always beat you in this corner of the DeFi sector because they can create scripts that work 24/7/365 without resting to do the same job 50x faster than you can, so if youâre just a trader and not a programmer then donât bother with flash loans. That, and any flash loan arbitrage bot that is profitable will NEVER be up for sale by its creatorâthe more arbitrageurs exist the less profitable and more competitive arbitrage trading becomes.
If youâre still reading, then carry on. Copying the code verbatim from the videos does not work for three reasons:
-
Aave has v2 now which has more arguments for its flashloan function, and three of those arguments are arrays (I donât know the syntax yet for feeding these arguments). You can still use Aave v1 like the tutorials use, but the Solidity version is outdated in a way that makes it FAR more troublesome to use over v2 (more on that in point 2).
-
All of the interfaces we are using are running OpenZeppelin contracts, which are running Solidity 0.8.0 while Aave v2 is running 0.6.12, and the Uniswap interfaces are running another version as well. These differences in Solidity versions contain breaking changes in the syntax and are entirely incompatible with each other. So, we canât just import the OpenZeppelin, Aave, and Uniswap files via GitHub URLs, instead we have to duplicate the contractsâ code to a local directory and modify the Solidity versions to 0.8.0 for ALL of them. There are 10 contracts in total that have to be copied into the local directory where your flash loan contract is being built, and the import paths must reflect this.
Once that is done, some of the contracts will contain outdated syntax that needs to be brought up to version 0.8.0. One example of this is the following:
uint256 deadline = now + 3000;
This code will throw an error saying ânowâ has been deprecated and to use âblock.timestampâ instead. This is a minor example, there are worse ones you will find and will have to fix as well. Some of them you might as well just delete and fill in with something simpler you can understand.
It needs to be stated that moving everything to 0.8.0 is WAY simpler than moving everything to 0.6.12, as regressing requires performing âsurgeryâ on the OpenZeppelin contracts to make them compatible with 0.6.12 syntax. I attempted to do this myself, and I wasted entire days off from my full-time hourly retail job figuring this out. What a stupid way to lose valuable time.
- The syntax provided by the tutorials for certain sections is straight up wrong.
For example:
ILendingPool public lendingPool;
lendingPool = ILendingPool(
addressesProvider.getLendingPool()
);
is throwing errors like crazy. This is because there is no addressesProvider inside the ILendingPool interface! That, and lendingPool was already declared as a âcontractâ data type, but getLendingPool() returns an âaddressâ data typeâwhich throws an âimplicit type conversionâ error. Delete the whole thing and use the following (or some personalized variation that you like):
address LENDING_POOL = lendingPoolAddresses.getLendingPool();
I didnât know we could declare imported contracts as state variables until this video, so that one was thrown at all of us from nowhere. So, forget whatâs in the video, and try what Iâm suggesting. You might get farther.
Another good example of how the code in the video is straight up wrong is this one:
ERC20 dai = ERC20(DAI_ADDRESS);
Which doesnât work because ERC20.sol was never imported. It doesnât make sense to import it either because we are trying to refer to a specific contract that already exists on the Kovan network, so that means we want the interface for that contract. This means we have to use:
IERC20 dai = IERC20(DAI_ADDRESS);
Doing this will create a variable âdaiâ which refers to the IERC20 contract at address DAI_ADDRESS. At least, I think thatâs how that works (Iâm a noob too, just like you). I could be totally wrong about this implementation, so beware.
Ultimately, I think my point is these tutorials are MASSIVELY outdated by now to the point where you really have to spend entire days fumbling around with them before they stop complaining about errorsâand even then thereâs no guarantee you did it right. You might find better instructions from YouTubers. Merely getting a flash loan contract to function correctly would be a great way to pad a Solidity developer portfolio for those who want developer job opportunities down the road (like myself), but if youâre looking for an easy way to score profits from trading then this is NOT it.