INTRODUCTION

Hello everyone, recently flashloan has emerged as an extremely hot keyword with a series of attacks on defi – decentralized finance projects with estimated losses of up to millions of dollars.

Actually flashloan is a very powerful and versatile financial instrument, one can use it for so many purposes, both good and bad.

To avoid people having the aversion that every flashloan will be bad, in this article we will go through the good side of it – flashloan the good points.

Because I am not a person in the financial industry, the examples in this article may not be modeled properly compared to the reality of the bank, so I would like to ask for advice from experts if there are any mistakes.

1. Borrowing in a traditional bank

Before we get into flashloan, we’ll need to know how the traditional lending model works, and how it gets on the blockchain:

Alice has a house and she wants borrow $100K to do business.

Alice goes to the bank to borrow, and take the house as a mortgage

The bank will appraise, the house is worth $200K, the bank can lend up to 70% of the house value

Alice borrowed $100K

When Alice pays off the principal and interest, Alice gets back the house.

In case Alice is no longer able to repay the debt (due to Covid, due to playing coins), or the value of the house drops, Alice’s loan can be liquidated, Alice loses the house.

We are not talking about “trust”, because on the blockchain no one “trusts” anyone, it’s trustless.

2. Defi lending

When put on the blockchain, these lending models work similarly:

Bob has 100 ETH, equivalent to a present value of $200,000, Bob plans to take $100,000 to do business. At this point Bob has two options:

  1. Bob would sell ​​50 ETH for $100,000 for his business plan.
  2. B noticed that the price of ETH was still increasing, so he did not sell, but instead, B deposited 100 ETH into AAVE platform as a pledge, borrowed $ 100,000 to do his plan. 2 years later B pays both principal and interest of $120,000 to get back 100 ETH, the price of 100 ETH is now $400,000. It means that B pays off but still has a profit of $180,000 compared to the original (400 – 200 – 20). Unfortunately, that is in the case of ETH price rising, and if in the opposite case ETH price falls, the value falls below 150,000 ETH, Bob’s loan can be liquidated, and Bob loses everything.

The second model is the lending model of the blockchain, where ETH is the house, AAVE is the bank.

The convenience here compared to the traditional is that everything is automatic, no procedures, no appraisal, loans with no term, super attractive interest rates, various types of collateral and borrowed assets. That’s why Defi became so groundbreaking and has such rapid development.

3. Flashloan

In the above loan models, to get a loan, you need to have collateral. If you don’t have collateral, you can’t borrow, completely understandable.

So is there a way for the poor who do not have much collateral to borrow a large amount of money to use?

Yes, that’s flashloan – hot loan without collateral.

Flashloan allows us to do the following “in a transaction” borrow a large amount of money to do anything with that money

and return the borrowed amount + flashloan fee (eg 0.3% with AAVE)

Why does flashloan dare to lend a large amount of money to users in advance without fear of running away?

We know that, in Ethereum, transactions are atomic, which is the smallest unit of execution, which means that in a transaction, it either completely succeeds, or completely fails. There is never a case where a transaction that runs half of the logic is then blocked or pending due to a network drop.

Flashloan is done in 1 transaction, so if successful, all the above steps are done, the user will either return the full amount + interest in the last step, or do nothing at all. Apparently the user cannot run away without pay.

That is the unique feature of blockchain. In traditional finance, who would give $1 million to an unknown person?

However, there is one point to emphasize here, that everything happens “in one transaction” (hot loan). We may wonder, what can only 1 transaction do? But surprisingly, it does a lot of things, of which the following applications are the most used (the good of Flashloan):

  • Arbitrage between Decentralized Exchanges
  • Liquidation of loan contracts without penalty (Self-Liquidation)
  • Move debt from one place to another with better interest rates (Refinancing Crypto Loans)
  • Swap Collateral

FLASHLOAN THE GOOD

1. Arbitrage between Decentralized Exchanges

We see that the ETH/USDT pair on Uniswap is 2000 USDT/ETH, while on SushiSwap it is 2300 USDT/ETH. We can proceed to make money with flashloan as follows:

  • Make a flash loan of 100k USDT
  • buy 50ETH on Uniswap
  • Deposit it to Sushi Swap and sell it for 115k USDT
  • Pay flashloan 100k + 0.3% fee

Result: Profit of nearly 15k USDT but in hand only need about 300$ to pay flashloan fee + a little transaction fee.

In reality, there is hardly such a large price difference between platforms, and since the AMM mechanism buys more, the price increases, so it is unlikely that we will be able to buy the large quantities at the good prices as we are seeing, and finally well, there are arbitrage bot systems running around the clock, so making money from flashloan arbitrage is not as easy as above, folks. Of course, opportunities always exist.

2. Liquidation of loan contracts without penalty (Self-Liquidation)

For Alice’s case above, when her business is at a loss, the bank seizes the debt, taking away Alice’s house, if it is still not enough, this amount becomes a bad debt.

For Bob’s case above, when his business is at a loss, there is not enough money left to return the system, if the lending system is allowed to seize the debt, there will be a penalty for Bob worth from 3% to 15% of the asset depending on the amount of money. Lending platforms that do that will avoid bad debt, and guarantee never loss. So it’s better than the bank.

For example, if Bob doesn’t use flashloan:

  • He made a loan of $100K with 100ETH as the collateral
  • ETH decreased, the mortgage of 100 ETH was still worth $150k, not enough for 150% of the loan value as the leading system policy, Bob’s deposited asset was liquidated
  • The platform will sell 100 ETH for 150k$, calculate the interest rate, say $20k, 
  • The lending platform also charges an additional 10% loan fee of $10k as the penalty

Result: Bob has only $20k left

Flashloan can help Mr. B avoid such liquidation penalty.

In more details:

  • Bob makes flashloan of $120k
  • Repay $120k principal + interest for the loan he made before
  • Get back the deposited asset of 100 ETH
  • Sell that 100 ETH on DEX (say Uniswap) for $150k
  • Pay flashloan 120k + 0.3% (~ 300$) fee

Result: Bob still has ~29700$ left

So clearly flashloan saved Bob from the visible penalty.

3. Move debt from one place to another with better interest rates (Refinancing Crypto Loans)

Again, for Alice’s case, when she is borrowing from bank V with a very high interest rate, she wants to switch to bank M with a lower interest rate, what she needs to do is:

She repays the debt to bank V, and she is also subject to a penalty for early payment

Then she takes back the house

Go to the bank M

Mortgage the house and then borrow again at a lower interest rate

With Bob’s case, it’s similar

Paying debt to V platform, it’s more convenient here that you can pay any time without an early-prepayment penalty

He gets back 100 ETH

Deposit it to the platform M as a collateral and then borrow again

In both cases above, there is one thing in common: they must have money to pay the debt first (100k principal + interest), then take the asset/collateral wherever they go.

However, Flashloan can help Bob to transfer debt simply without needing so much money.

In more details:

  • He makes $100k flashloan for repayment of the previous loan
  • Then he pays off the platform V (interest rate 20%/year)
  • He gets back ETH
  • Deposit the 100 ETH to the M platform as as the collateral and then borrow another $100k at an interest rate of 5%/year
  • flashloan debt repayment is $100k + 0.3% fee

Result: Bob only costs 0.3% flashloan fee (ie 300 USD) + interest + transaction fee to transfer the debt from platform V with interest rate of 20%/year to platform M with interest rate of 5%/year. Too good, isn’t it?

4. Swap Collateral

Listening to the financial advisor, Alice wants to swap the bank mortgage from her own house to her using luxury car. Alice needs to go to the bank to do the paperwork to change the bank mortgage. The luxury car needs to be re-evaluated, and if the bank agrees then Alice will be able to change the contract, but obviously Alice needs a lot of time consuming procedures. Or Alice can pay the debt to get the house back and then take the car as a mortgage later. But back to the problem that Alice must have money to pay the debt first.

Realizing that ETH price fluctuations are too large, Bob wants to change from ETH to USDT stable coin as collateral for safety:

  • He pays 120k (principal + interest) to get back 100 ETH
  • He then swaps 100 ETH to USDT on Uniswap, for example
  • He takes USDT as a mortgage & borrow again

The problem is, where does Bob get the money of $120K to pay the debt? Flashloan can help him:

  • He make a flashloan of $120k including the principal + interest
  • He gets back 100 ETH
  • He then swaps 100 ETH to USDT on Uniswap
  • He takes USDT as a mortgage & borrow another $100k
  • Finally, he pays the flashloan of $120k

Result: Bob only costs 0.3% flashloan fee + interest + transaction fee to convert debt assets from ETH to USDT.

CONCLUSION

Flashloan is very good, it helps the poor can also play big games. With large amounts of money, one can create a lot of different outcomes. Grom the good ones like the above, to the price manipulation attack – is known as flashloan attack.

Limitations: currently flashloan is still new and not widely supported, so in order to use it, we have to write scripts – ie know a little programming

Some platforms that support Flashloan:

Dydx: Solo Margin

AAVE: Flashloan

Uniswap: Flashswap

PancakeSwap: Flashswap

In the next article we will talk about bad scenarios – or flashloan attack