DEV Community

Cover image for Flash Loans | Make profit in almost 14 secs - if you are smart enough. People have already started doing it.
a_mature_dev
a_mature_dev

Posted on

Flash Loans | Make profit in almost 14 secs - if you are smart enough. People have already started doing it.

Assumption:
Another one of my quick notes => I assume that you (the reader) understands Blockchain [Ethereum specifically], smart contracts and DeFi (aka decentralised finance). If not, this will be tough to follow and hence, advisable to dig about these first and come back over here.

DeFi - in one sentence (almost):

Traditional financial system of (a) lending, (b) borrowing, (c) doing something with the borrowed money, (d) repaying loans - but only by and for blockchain assets, through smart contracts.

What is a Flash Loan?

A loan (yes, like a very traditional loan) that is taken out and paid out in 1 blockchain transaction [typically in ~14 secs].

Why Flash Loans?

From the lenders' point of view: almost safe (my bet is 100%), principal and interest is received back instantly (well, ~14 secs and interest income.

From the borrowers' point of view: Can borrow a very very high amount, as far as I know what I am doing, no collateral required, no collateral required (again!!!), instant.

How does it work?

Blockchain Transaction:

On the Ethereum blockchain, everything that happens is a transaction. For eg:

  • If Alice sends Bob an Ether (aka ETH) it is a transaction.
  • If I write a smart contract that will the ETH that I give it and transfer it to Alice and Bob in two equal halves, it is a transaction.
  • If a Smart Contract
    • takes ETH,
    • looks up the price of gold on the LSE,
    • buys appropriate amount of Gold Tokens,
    • holds it for 30 mins,
    • relooks at the value of gold on LSE,
    • sells the Gold Tokens,
    • gives out the proceeds back to the user who deposited the ETH,
    • after computing a brokerage and then transferring the brokerage to my account - it is also a transaction (1 Single transaction).

of the above three examples, the last two can be a single transaction or can be broken into multiple transactions; they do not have to be 1 single transaction - it is the manner in which the transaction is defined and designed in a Smart Contract.

Flash Loan Capable Smart Contracts (the core of this entire article / blog post)

So flash loan smart contracts are written up in a manner that anyone (literally anyone; Yes, any darn one!) can (for ease of understanding), submit a transaction which will require some amount to begin with (this is the loan / principal), do something, and pay back the loan (with some interest) at the end of the single transaction.

More simply put, flash loan is an algorithm {loan algo}, to which I will submit my algorithm {my algo}, which will check that units that the loan algo gives (LHS) is equal to the units that it gets back and the end of the execution of my algo (RHS).

Implications

Now that you have some skeleton understanding of what a flash loan is and how it works - let us think and see some use cases / implications:

Eg Use Case You see a potential arbitrage opportunity

  • buy Stock A on local stock exchange in you local currency,
  • transfer stock to a global custodian
  • exchange stock units for its Global Depository Receipt (aka GDR)
  • sell GDR in a foreign market
  • convert foreign currency to local currency
  • make arbitrage gains due to exchange rate difference All executed in a matter of seconds!

could you do this in a traditional financial world? Answer: (if you are like me, a common man and not a highly rich dude and not much of an infrastructure required to execute the above): NO, you cannot.

could you do this on the Ethereum blockchain? Answer: (if you can write a smart contract): Hell YA! You can!

Any restrictions? Answer: No
Any KYC? Answer: No
Any limit on amount? Answer: No (mostly)

Conclusion Answer: I can (you can)(anyone can) do transactions worth MILLIONS of USD!! make gains, faster than it would have take to load an average webpage.

Eg REAL WORLD transactions:
Eg 1: Transaction 1 - click me!
Eg 2: Alt Text
Eg 3: Alt Text

I would like to know what your thoughts are on Flash Loans - are you
Aye or Nay

My Opinion: WOW, this is going to take the financial system to a whole new level! I take this to be in the likes of the Apple iPhone to the mobile-phone universe: things will not be the same ever again!

Written with StackEdit.

Top comments (3)

Collapse
 
ruykxxcc profile image
ruykxxc

sir ! i'm little bit newbie .
my question is , " can we make profit with small price difference like 0.5-1$ ?
as you know in decentralized exchanges, they also charged trading fee of 0.30% .
While doing triangular arbitrage, there should be around 3 trades . So the trading fee (0.30*3) + aave loan fee (0.09) + gas . "

Collapse
 
giorgosk profile image
Giorgos Kontopoulos πŸ‘€

I have heard about it. Is this an exploit or is it intentional behaviour ?

Collapse
 
a_mature_dev profile image
a_mature_dev

There have been 2 recent transactions which were large enough to influence the prices of 2 different coins. Some say back, some say exploit. But honestly the trades were by the book. Didn't hack anything. It was just a smart algo / trade.