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.