hey @BitcoinAlchemist. yeah i can try to give some points on what I know. This actually seems like an intresting course on the academy that i have not yet take. might get around to it at some point.
Ok so in real world scenarios i guess there are a few cases that we can use flashloans such as arbitrage, colletoral swapping and self liquidation. The main or most popular use case is probably arbitrage. For example making an arbitrage bot to maximise profit on token pair price mistmatches using flashloans. Arbitrage is sually executed using automated scripts hence the term “arbitrage bots” and can fall into a few different categories. We have regular arbitrage bots, liquidation bots and sniper bots and more. you can ook them up if your curious
I guess in terms of assessing risk here for considering to use a flashloan for a regualr arb bot there really isnt much. This is the beauty of flashloans. Since the ethereum protocol is atomic in nature if we have a transaction that someone executes and at some opint the code faisl then the entire transaction will revert as if nothing ever happened. This whole premise is used in flash loans
So a flahsloan it its simplest for is a loan that can be borrowed from blockhain AMM poopl or other or liquidiuy pools no questions asked. The only clause is that the loan must be paid back in the same transaction that it was borrowd in. And heres the beautiful part. For non programmers here, on the ethereum BC you can write smart contracts that execute multiple transactions in one. Another way of saying this is you can bundle up many transactions into one. So in terms of flashloans what this means is you could write a function to borrow the loan, then in the same transaction you could define logic to send thr loan to some dex smart contract then use the money to swap some tokens then send the money back to the contrct where you took out the loan, then pay back then loan and boom. Thats like 5 different transcations bundles up into one. so here we have successfully taken out a flahsloan and paid it back in the same transaction
So why is this risk free? Well as I mentioned since ethereum transactions get revered if any piece of logic code fails then if we take the case above say we take out a loan for 100 daibon uniswap, then we trade 100 dai for 110 dai worth of ether on uniswap, then we take this 110 dai worth of eth and send it to suishi swap to trade it back to dai. But say there is a worse rate on sushi swap so that whn we trade the eth back to dai we only now have 90 dai. Therefore we dont have enough dai to pay back the flashloan so our transaction will get revereted and uniswap wont loose money and neither will we.
So this is the beautiful thing about flashloans is that they are pretty much risk free. now i say nearly because we will still have to account for trader fees which i think is 0.03% on uniswap and also gas fees we could potentially find a real oportunutiy which makes us profit from arbitraging a token pait on two exchages but if the gas for the trade is more than the profit then well loose money. This is the only way we can loose money using flash loans really.
Arbitrage is one thing that I have studied quite well so if you have any other questions let me know. As for things like self liquiddation of colleroral swapping im not as insightful on so if thats what your intrested in i suggest you do your own research incase i say smothing from from what i do know
EDIT
In terms of the uniswapV2 protocol. many of the functions that you would use to help for various calculation sin arbitrage such as max profit etc take into account the 0.03% fee so specifically for uniswap many time syou can leave this calculation out as uniswap handle it for you. The only thing you would need to estimate is gas and you can do this simply using web3.js on any contract function by calling “estimatedGas = contractInstance.methods.NameOfFunction().estimateGas()”
I have not played around with flashloans from Aave which i know are the popular choice amoungst a lot of people so im not sure what way their SC’s work i will surely look into this for you and let you knoe. But yes i some cases you will need to calculate things like fee estimatio yourslf as Carlos mentions and the best way to go about this is to go to the github of the flashloan provider you rusing and to read their smart contract and documentation directly where you will be able to figure all of this stuff out