Lets hack Flash Loans | Flash loan assignment/discussion

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:

  1. 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).

  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.

  1. 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.

5 Likes

Thanks for your detailed post, mate!

Looks like all Kovan Testnet faucets are cooked, and this is the only testnet available on AAVE: can’t get assets on mumbai :frowning: sad days!

If anyone’s feeling particularly generous to share with me the apparently scarce resourse of Kovan ETH, I would be eternally grateful! I wanna try this out!
xx
0x7CF3a20BC2daE456Dc6469aeED1070251323532f

1 Like

If we have a pool of Token0 and Token1 on two exchanges Exchange and Exchange1. Let us assume that there is an arbitrage opportunity between the two pools on both exchanges. I am trying to look for a nice mathematical formula to tell me how much of Token0 I can borrow from a flash loan without breaking the arbitrage opportunity between the two exchanges because of price slippage. So far I have found out that we can calculate the number of tokens that we get from a pool using the formula Y = Token0Reserves - (Token0Reserves*Token1Reserves)/(Token1Reserves+(1-fee)X). Where :
Y = amount of Token 0 we receive after trade
fee = fee on the exchange (e.g on uniswap it equals 0.003)
X = amount of Token1 we deposit

Been bashing my head over this all summer and came to no conclusion :frowning: pls help

I cannot access the kovan faucet :frowning: , Ill try to follow the course along but it would be great if I could solve this in order to practice correctly.

1 Like

Check this :nerd_face:

https://forum.ivanontech.com/t/faq-how-to-get-kovan-eth-from-app-mycrypto-com/35389/2

Carlos Z

1 Like

Would we be able to specify the amount of KETH we can get from this link?

I tried the Kovan Faucet chat - https://gitter.im/kovan-testnet/faucet

  • drop address and get KETH, problem is the amount sent would be dependent on the contributions you made. Since I haven’t made any contributions yet, I received 0.000105 KETH :sweat_smile:

I don’t think this is enough to follow along with the flashloans.

I think there was an announcement to update the DeFi courses? maybe you can try on the Rinkeby Network (easier to get test ETH)? and a different protocol instead of AAVE? (cause I think AAVE does not support Rinkeby)

Thanks!!

Hi, I’m still getting this gas error even after I sent DAI to the FlashLoan contract address (sent double the amount within the lecture)

image

Thanks for the help :slight_smile:

Hi,

I tried the code, it deployed well but during transacting for flashloan, a warning shows up for high gas needed even with 0.01KETH.

Kindly advice

Amazing course! can’t wait for the new updates to go through DeFi again :100:

Just a question: How come the arbitrage for DAI and BAT worked when the contract in Remix is redeployed for MKR and DAI? It happened on the “Program an Arbitrage FL part 2” part of this course. I’m just wondering if that’s a remix error or something. Thanks :slight_smile:

1 Like

Hey @CryptoXyz, hope you are ok.

Sorry but I did not understand your question, I did not see any redeployment of the contract with MKR and DAI, or i just miss something?

Carlos Z

1 Like

Hey man,

It’s on the 12-minute mark of “Create your own arbitrage opportunity part 2” section (I made a mistake on the part where I found it, sorry for that)

It’s the one that Amadeo referred to as “weird”. Thanks again

1 Like

Great course Amadeo. But as a non programmer, I found the last section a little difficult to follow. Unfortunately I couldn’t access the Kovan faucet or the Aave testnet. On the latter, the website seems to keep redirecting to the main net. I understand how the flash loans and arbitrage work, might try a small arbitrage on mainnet if gas fees not too much.

Just an observation about the common way people traditionally do arbitrage: the usual idea is to buy on one exchange, transfer the coins to the second exchange, then sell higher. But of course the time required for this will often defeat the opportunity. But what if you took 2 exchanges where price differentials often occur, and have both tokens (or a token and fiat) on both exchanges? Then you can perform both transactions virtually simultaneously (providing that the fees are not too high) and then settle between your two different accounts later. Just a thought. Any ideas about this?

Hi Amadeo,

I have a question about focusing effort on either Hedgefund or Flashloan. Should you choose one over the other, which would you pick to gain more income?

Thanks

Hi,
I Have Two major Doubts in Flash Loan Arbitrage

https://faucet.kovan.network/
The above link is not working for getting test eth

How can I get some Test ETH???

My Kovan Test Network Address:
0x7135C5f07bfCC9EfC1C4c865b6FfB90EE3F0c609

Can I execute Arbitrage from other exchange like crypto.com and coinx
If so, Where can I Find the exchange’s Address???

A couple of things. I see there are some problems on the developement part for flashloans and I think the info is a bit outdated.

As suggested in the first class I did some other courses before (eth programming 101 and 201 for example) yet I still can´t get how to do ir well.

On the oher hand as ETH is ultra expensive to transact, could you suggest some ways to interact with other networks like polygon or bsc?

Thanks for putting the course together Amadeo…I did learn a lot from the course. It was maybe not what I expected when I started it, but just understanding that there are tools like, Furucombo, Github, Remix, Kovan testnet, Aave faucet, forks of Uniswap and a complete testing environment to learn and get a better understanding how to program smart contracts was worthwhile. I’m sure this will definitely come in handy in the future as this space evolves. I have not started any other programming courses yet so I did find it at times hard to follow, but I was obviously missing some basic programming knowledge that I am sure is covered in another course (Eth programming probably?)
I will come back to this area again once I feel that I have a better understanding of the programming basics (Github and Remix) but I was able to grasp more than I thought I would and do more than I thought I was capable of understanding.

Thanks Amadeo, what a great course you put together. This a bit more technical than DEFI 101, at times difficult to follow becuase I lack the programming skills, but I do understand the economics behind it. Now with the GAS war prices in the ETH network, I do not think is that profitable anymore right?

Hi, has anyone attempted to compile and deploy the ‘myfirstflashloan.sol’ code?

Running into warnings that I’m not sure how to resolve, hoping to get some help.

Thanks

Late post, but I’m having the same problems. This was written in Solidity 0.5.0 (now on 0.8.9), and I think some of this will have to be rewritten. The solidity docs are fantastic though.

Goal 1: complete a successful flash loan tx.
Goal 2: complete a successful flash arbitrage
Goal 3: learn solidity design patters
Goal 4: build. build. build. :slightly_smiling_face:

1 Like