Defi 101 - basic concepts explained

Defi projects exploded in 2019, the annual total value locked has increased 137.23%* in 2019 alone. 1 in every 37.12 ETH* is now locked in Defi Protocols. There are different categories of Defi protocols such as lending protocols, stablecoins, exchanges, security tokens, insurance platforms, etc. Since lending protocols such as Compound have arguably received the most attention, we will focus on these platforms to fully understand their concepts, common patterns and the risks involved to use them. Note these concepts not only apply to lending protocols but also similar products from other categories such as options protocol Opyn. We will be discussing these as non-technically as we can to make it friendly for new users.

What are Defi lending protocols

Lending protocols are basically platforms to link lenders and borrowers in a decentralized manner. On one hand, it allows borrowers to borrow crypto from the platform or other users for interest, on the other hand, it allows lenders to deposit crypto-assets into the platform to make interest. The interest goes to lenders come from the interest borrowers pay. Defi lending protocols offer much better interest compared to the banks’ savings accounts, at the time of writing for example, Compound is offering 7.58% interest per year for lending Dai to the protocol, while current savings rate from banks are extremely low globally, some of them are even negative.

On the other hand, borrowers pay an interest to borrow from these lending protocols, at the time of writing, Compound charges 8% per year to borrow Dai from the protocol. This is also a pretty high cost to borrow.

So it is basically P2P lending?

Not really. These Defi lending protocols usually operate on a pool based structure. For example, when you deposit DAI into Compound, your money goes into a pool instead of to a specific borrower. Borrowers then borrow from the whole pool instead of a specific lender. This design has a few advantages:

Lenders do not need to wait for a counterpart borrower to be matched in order to participate (e.g. earning interest) It allows the protocol to balance supply and demand through different incentives, for example when the borrowing demand is low, it might have an effect on the lending interest. It allows the protocol to even out the risk, so a lender is not 100% tied to the specific risk of their borrower.

Why are people paying high interest to borrow assets from lending protocols?

The answer could be for anything but a common one is traders leveraging on existing assets for trading purposes. Leverage is a very simple concept, it basically means borrowing money to invest. For example, I have a bunch of BAT tokens I believe the value will increase, but I also want to buy some REP because I think REP will also increase in value. But I don’t want to sell my BAT to buy REP. I can then use these lending protocols to borrow some Ether using my BAT as collateral, then I can buy some REP with the Ether I borrowed. In this case, I am basically holding both BAT and REP, all I need is to pay the yearly interest of borrowing Ether. If the price of REP increases, I can sell my REP and get Ether back, then pay back the protocol the Ether I borrowed, hopefully, with a lot of Ether left as profit.

Collateral

Collateral is a very basic concept in the financial industry, it just means something you put up as a guarantee when borrowing money. If you can’t pay back, your collateral will be used to pay your debt. An easy example is when you take a house loan from a bank, the house you bought will be the collateral, if you can’t pay back your loan, the bank will take your house.

It is exactly the same in Defi, if you want to borrow some assets from the protocol, you will need to give the protocol some other assets as collateral, if you don’t pay back your loan, the protocol will not give you back your collateral. Since we are talking decentralized finance here, the acceptable collateral are usually crypto-assets.

Loan-to-collateral ratio, over collateralized loans and why?

Since crypto value changes often, it is risky to use crypto as a collateral because when the value of collateral drops, it might not be enough to cover the loan value. For example, let’s assume today both BAT and REP are $1 each, I borrowed 1 REP from a lending protocol using my 1 BAT as collateral. Tomorrow, the price of BAT drops to $0.5, but REP is still $1, now if I don’t pay my debt, the protocol will end up losing $0.5 as they try to sell my BAT to cover the 1 REP I borrowed.

That’s why most protocols requires an over collateralized loan, basically means you can only borrow up to a percentage (less than 100%) of your collateral’s value. The protocol often describes this as a loan-to-collateral ratio, and it is a common requirement to control the risk exposure to the protocol. Now when you borrow assets, you can only borrow up to maybe 75% of your collateral value, which will leave a 15% buffer for price changes.

Since price volatility is relatively unique to each asset, it is common to set the loan-to-collateral ratio individually for different asset pairs. For example Compound calls the loan-to-collateral ratio the Collateral Factor and it is set differently according to different assets.

Protocol tokens and Underlying asset

It is common to see protocols issuing their own tokens to users during the process. For example when you deposit into Compound, you will get cTokens back like cEther, cDAI. These are usually standard ERC20 tokens that play an important part of the protocol’s function. In Compound’s case, it represents the Ether or DAI you deposit which are now called underlying assets. These cTokens works like a receipt, that you can redeem for your deposit back in the future, it also keeps track of the interest you made on your deposit. So if you transfer these cTokens to someone else, you are giving away your deposit receipt to someone, they can then redeem your underlying asset. So be very careful with it.

One thing worth noticing in Compound is, when you use your deposit as collateral to borrow other assets, the cToken you are issued will not be transferable anymore. This is understandable, when used as collateral, your underlying assets are locked down until your debt is paid off. It will be problematic if cTokens are transferrable during this period because the receiver might not even know the underlying asset of these cTokens are used as collateral until the moment they try to redeem it.

Price Oracle

Price oracles are a common concept for Defi protocols. When a protocol is dealing with different assets, it often needs to know the current prices of these assets, basically a price oracle simply provides the asset prices to the protocol. Price oracles are a key component of the Defi ecosystem, but often users don’t pay enough attention on how the price oracle operates, which could lead to significant compromise if it is not well designed - after all, if an asset price is hacked, it could mean a fail for the whole Defi protocol.

Currently most Defi protocols uses their own price oracle, it is worth looking into these oracles and understanding how they handle prices before heavily investing in these protocols. However Compound has released an Open Oracle which aims to provides a on-chain solution that sources different prices from trusted reporters and calculates the median price as the asset price. This is a great start for an industry standard solution, it could replace individual price oracles from each Defi protocols, taking the risks away from operating these price oracles.

How does interest work

When it comes to interest in Defi, it is the same concept as from your bank. There are generally two types, Simple interest and Compound interest. However, the way interest is calculated is usually a little bit more complicated technically. Because Ethereum transactions rely on external triggers, Defi protocols usually depend on user actions to calculate the interest. E.g. Compound is supposed to calculate interest every time block, but instead of doing the calculation automatically, it relies on critical user activities like supply, borrow and liquidation to trigger the calculation of the interest. When triggered, the function will take into account of how many blocks has it been since the last interest calculation and apply the latest interest on top of it. In other words, the protocol will not calculate interest if no user actions are taken.

Liquidation

Liquidation basically means when your collateral price drops closer to your debt value or is even unable to support your debt value, the protocol will allow someone else to repay your debt in exchange for your collateral. For example, assume the price of 1 REP equals to 1 BAT, you borrowed 1 REP and put 1.5 BAT as collateral because the protocol requires over collaterlization. After a while BAT price dropped and now 1.3 BAT = 1 REP. This is risky for the protocol because the protocol might become insolvent if BAT keeps dropping, so the protocol will allow other people to come in and provides 1 REP in exchange for your 1.3 BAT. Often, the protocol will provides a bonus for liquidators to encourage liquidation in a timely manner, this is usually called a liquidation bonus or liquidation incentive. It is within the protocol’s interest to make sure liquidation happens before the price changes too far, otherwise it could cause the protocol to be insolvent. It is worth noting once the collateral price drops below the debt price, it makes no sense for the borrower to repay their loan anymore which will cause the protocol to be insolvent.

Does this mean I can make money liquidating people’s loans?

Yes. Defi protocol usually offers an incentive to liquidate loans and keep the protocol healthy and collateralized, you will get a better than market deal from the liquidation process, so technically you could make some profit by monitoring the protocol and liquidate people once it’s allowed. However this process does require constant effort of monitoring the protocol and you will be competing with other liquidators and often bots set up by the protocol to make sure liquidation happens in a timely manner. Also be aware, the collateral you end up with is an asset dropping in price which could be a dangerous thing to hold on to anyway.

General risks in Defi

Defi is hot because it offers a lot of advantages like high returns, flexibile entry and exit, decentralization etc. However there are surely risks coming with these perks, here we discuss some of them.

Potential protocol insolvency due to under collaterlization when asset price drops

Financial product often has built-in risks, collateralized debts is a common example, when the value of underlying asset drops below the debt value, it will push the protocol into insolvency. This is particularly risky for Defi due to the high volatility nature of crypto-assets. Although the protocol can limit risks and cut losses as early as possible with mechanisms like limiting supported asset types, setting loan-to-collateral ratio and enforce close monitoring of the loans with swift liquidation process, it is not possible to completely eliminate these risks.

Our audit report for Compound outlined this risk in details here.

External dependency failure

Defi protocols often operate on some external dependencies, these are very broad concepts from the ERC20 tokens they support to the price oracle they get their asset price from. The protocols usually have no control of these dependencies, which means if any of these become compromised, it will have a direct impact on the protocol operating with them. For example Opyn relies on Compound Price Oracle to get prices for Compound’s cTokens, if the Compound Price Oracle fails, it will cause Opyn to fail to update these asset prices, which could lead to a risky situation of under collateralization.

Compound has released an Open Oracle aiming to be a decentralized Defi price oracle, this is a great move for the Defi industry, however our audit does reveal a few potential issues inside it.

Smart contract vulnerability

The nature of smart contracts means there are always potential undiscovered vulnerabilities inside the code. It is one of the top reasons for major historical hacks within the crypto space. On top of that, technology progress could make originally safe code vulnerable all of a sudden. For example the recent development of Flash Loans opened a brand new attack vector and put a lot of existing projects under risk stress, (see a detailed introduction on Flash Loans by my team mate @Austin-Williams ).

Conclusion

Financial product always has risks, this applies to both the traditional finance sector as well as Defi, we just need to understand these risks and prepare ourselves. I believe we are just at the beginning of the Defi explosion, with the global monetary system uncertainty spiking in recent times, Defi could be a sweet alternative.

*Market Report: 2019 DeFi Year in Review by Lucas Campbell