A flash loan is a feature that allows you to borrow any amount of assets from a specified smart contract pool without having to put up any collateral. Flash loans are useful Decentralized Finance building blocks because they can be used for arbitrage, debt trading, and self-liquidation. While the marble protocol was the first to implement them, AAVE and dYdX made them popular.
The concept of a transaction in computer science is the same as the definition of a transaction on a blockchain, such as Ethereum. A transaction is a series of operations that must be performed in an atomic way; either one of these types must be completed, or the transaction will be rolled back and none of the steps will be completed. When it comes to Ethereum, any typical operation is performed within the transaction spectrum, including sending Ethereum, ERC20 tokens, and communicating with smart contracts. Ethereum blocks are made up of transactions that are clustered together.
Many phases may be used in a single Ethereum contract. On COMPOUND, for example, you might supply Ethereum and borrow DAI. On CURVE, exchange half of your borrowed DAI for USDC to provide liquidity to DAI. If all of these procedures fail, the entire transaction will be rolled back and none of the subsequent steps will be performed. And if a deal isn't done, you'll also have to pay petrol fees.
Finding a flash loan provider is the most critical aspect of the process. DeFi users can borrow various coins from a specified pool using smart contracts created by AAVE and dYdX, as long as they are repaid within the same Ethereum transaction.
When it comes to flash loans, there is usually a set rate. For e.g., AAVE contracts force the creditor to repay the original payment plus an additional 0.09 percent of the borrowed amount. Depositors who supply the lent funds share the fee with integrators who make the AAVE flash loan API easier to use. If the money has been lent from the loan pool, it can be used on anything you want.
Arbitrage flash loans will boost the benefit from a profitable arbitrage transaction. Arbitrage deals involving many phases can be very costly. Often figure in processing costs while estimating earnings, as well as the amount of price slippage you'll face when placing your order. There's a good risk that someone else will have the same potential and will be able to close the deal before you. Furthermore, bots that track the mempool might pick up on your profitable arbitrage opportunity.
Swapping Collateral flash loans. For example, suppose you borrowed DAI from COMPOUND and put Ethereum up as collateral. You will exchange the ETHER collateral for DAI collateral by taking a DAI flash loan to offset the DAI borrowed.
Self-liquidation flash loans. Consider the following scenario: you have a DAI loan with Ethereum as collateral on COMPOUND. The price of Ethereum starts to plummet, and you're reaching the point of liquidation. You either don't have to, or don't want to, add more Ethereum to the liquidation stage. Furthermore, you lack the DAI needed to repay the loan. You will now take a flash loan for the amount of DAI you owe, refund your DAI loan, and withdraw your Ethereum instead of your contract being liquidated.
Image Source: https://coingape.com/defi-flash-loan-crypto-loans-without-collateral/