Borrow Millions In DEFI With NO COLLATERAL? FLASH LOANS Explained (Aave, dYdX)

so what are flash loans all about and how can 
they be used to borrow millions of dollars worth   of crypto with no collateral you'll find answers 
to these questions in this video before we begin   if you want to learn more about decentralized 
finance make sure you subscribe to my channel   a flash loan is a feature that allows you 
to borrow any available amount of assets   from a designated smart contract pool with 
no collateral flash loans are useful building   blocks in d5 as they can be used for things like 
arbitrage swapping collateral and self-liquidation   flash loans although initially introduced by the 
marble protocol were popularized by ave and dydx   so what's the catch a flash loan has to be 
borrowed and repaid within the same blockchain   transaction the concept of a transaction on 
a blockchain such as ethereum is no different   to the traditional definition of 
a transaction in computer science   a transaction represents a set of operations 
that must be executed in an atomic way   either all the steps are executed 
or the transaction is rolled back   and none of the steps take place let's take 
a simple database transaction as an example   if you're already familiar with this concept feel 
free to skip this part imagine a database table   that represents user's balances alice's balance is 
1 000 and bob's balance is 500 ali sends bob 500   dollars in this case we of course have to subtract 
500 from alice's balance and add 500 dollars   to bob's balance so we start writing our 
database update statements the first update   statement subtracts 500 from alice's balance the 
second statement adds 500 dollars to bob's balance   this is cool but what happens if the first update 
executes but the second one fails for some reason   maybe id2 is not present in the system and 
we made a mistake thinking it's bob's id   if this happens we would end up in an inconsistent 
state with alice's balance equal to 500 dollars   and bob's balance also equal to 500 dollars 
to avoid situations like this we have to use   transactions in the above situation in sql we just 
need to wrap both statements with begin and commit   keywords once we do that we can safely assume 
that either both statements are executed correctly   or none of them are leaving alice's and 
bob's balances untouched we often say   that if different steps are a part of the same 
transaction they are atomic hence indivisible   all or nothing when it comes to ethereum 
every common operation such as sending it   sending erc20 tokens and interacting with smart 
contracts are executed within a transaction scope   transactions are grouped together and included 
in ethereum blocks we can easily see all the   transactions that were included in a particular 
block on any popular block explorers such as   etherscan one ethereum transaction can 
consist of multiple steps for example   you could supply heath and borrow dye on compound 
swap half of you borrow die for usdc on curve and   provide liquidity to die usdc pool on uniswap 
all in one single ethereum transaction of course   if any of these steps result in an error the whole 
transaction will be rolled back and none of the   steps will take place remember you will still pay 
gas fees even for failed contract executions the   number of steps in a single transaction is only 
bounded by the gas cost so although in theory you   could create a valid transaction with thousands 
of steps realistically it would be rejected   because of the max gas cost limit per block now 
let's dive a little bit deeper into flash loans   first of all the most important part of 
executing a flash loan is to find a flash   loan provider projects such as other or dydx 
developed smart contracts that allow defy users   to borrow different coins from a designated pool 
under the condition that they are repaid within   the same ethereum transaction there is usually 
a fixed cost associated with using flash loans   other contracts for example require the borrower 
to return the initial amount plus an extra   0.09 percent of the borrowed amount the fee is 
split between depositors who provide the funds   that can be borrowed and integrators who 
facilitate the use of aves flash loan api   a part of this fee is also swapped to other 
tokens and burned once the amount is borrowed   from the landing pool it can be used for any 
other arbitrary actions assuming that at the   end of the chain of different steps the initial 
flash loan is repaid because the loan has to be   repaid within one transaction there is no risk 
of borrowers not repaying their borrowed amount   the only risk is the always present smart contract 
and platform risk flash loans are becoming   more and more popular with some of the users 
borrowing as high as 14 million die on the other   there are three most common use cases for flash 
loans arbitrage flash loans can magnify the profit   of executing a successful arbitrage opportunity 
let's imagine that there is a price discrepancy   in the die usdc pulls between uni swap and curve 
you can trade one dive for one usdc on curve but   you only need 0.99 die to buy one usdc on uni swap 
now you can try to execute the following arbitrage   borrow 100 000 die from ava via flash loan swap 
100 000 die for usdc on uni swap and receive 100   and 1010 usdc swap 100 and 1000 ten usdc for 
one hundred one thousand and ten die on curve   repay initial one hundred thousand die plus zero 
point zero nine percent fee equals *100 090 profit   *920 die this looks nice but we have to 
take a few extra things into consideration   network fees arbitrage transactions with 
multiple steps can be quite expensive   always take transaction fees into 
account when calculating your profits   price slippage always calculate how much price 
slippage you'll experience while executing your   order a hint it depends on the size of your order 
and the liquidity present in the liquidity pool   front running there is a high chance that someone 
else will spot the same opportunity and will   manage to get their transaction mind ahead of 
you on top of that bots that monitor the mempool   can pick up your profitable arbitrage opportunity 
and send the same transaction with a higher gas   fee profiting them instead of you 
basically stealing your arp opportunity   the next use case for flash loans is a collateral 
swap let's say you have borrowed dye from compound   with it as collateral you can swap your collateral 
from eath too for example but in the following way   take a flashlight in dye to cover 
the amount of dye that was borrowed   repay your compound loan with borrowed 
dye withdraw your eat swap your eat   for bad on uni-swap supplied bath as collateral 
on compound borrow die against your bad collateral   repay flash loan with borrowed die plus fees 
congrats you just swapped your collateral from   heath to bat and paid 0.09 percent of the borrowed 
amount for this the last but not least example is   self-liquidation imagine the following scenario 
you have a loan in die on compound with east as   collateral the east price keeps going down and 
you're approaching the liquidation level you also   don't have to or don't want to deposit more ease 
to increase your liquidation level and you also   don't have the die required to repay the loan 
now instead of allowing the maker dollar contract   to liquidate your collateral and charge you the 
liquidation fee you can take the following steps   take a flash loan for the amount of diet that 
you owe repay your die loan and withdraw your   eat swap enough heat to die in order to repay the 
flash loan plus fees keep the rest of your eath   these were the three most common use cases 
for flash loans of course the concept of   flash loans is quite new and there are still a 
lot of use cases to be discovered in the future   flash loans similarly to crypto can be used for 
both good and bad when it comes to the latter   flash loans were used in most of the recent 
defy hacks and allowed hackers to magnify   their potential profits as they do not require any 
upfront funds one of the most famous hacks was the   bcx hack where a flash loan was used to manipulate 
the uni swap oracle price as usual the problem   was not in the use of flash loans but rather in 
some incorrect assumptions when it comes to using   uniswop as a price oracle events like this are 
sometimes costly for the people affected by them   but they are usually result in the strengthening 
of the whole defy ecosystem making it more and   more antifragile in the future although flash 
loans are predominantly used by developers   it is also possible to use them without doing 
any coding projects such as collateral swap   defy saver fury combo make it possible in 
the description box below i have included   links to our guides on how to code a flash loan 
with ava and how to use fury combo so no matter   if you're familiar with coding or not 
you can find something that works for you   so what do you think about flash loans have you 
ever used them and do you think they are good   for the defy ecosystem comment down below and 
as always if you enjoyed this video smash the   like button subscribe to my channel and check out 
cinematics on patreon to join our defy community

You May Also Like