So have you ever been wondering how lending and borrowing works in DeFi? How are the supply and borrow rates determined? And what is the main difference between the most popular lending protocols such as Compound and Aave? We’ll answer all of these questions in this article.
What is Lending and Borrowing
Let’s start with what lending and borrowing is.
Lending and borrowing is one of the most important element of any financial system. Most people at some point in their life are exposed to borrowing, usually by taking a student loan, a car loan or a mortgage.
The whole concept is quite simple. Lenders a.k.a. depositors provide funds to borrowers in return for interest on their deposit. Borrowers or loan takers are willing to pay interest on the amount they borrowed in exchange for having a lump sum of money available immediately.
Traditionally, lending and borrowing is facilitated by a financial institution such as a bank or a peer-to-peer lender.
When it comes to short term lending & borrowing, the area of traditional finance that specializes in it is called the money market. The money market provides access to multiple instruments such as CDs (certificates of deposits), Repos (repurchase-agreements), Treasury Bills and others.
Lending and Borrowing in Crypto
In the cryptocurrency space, lending and borrowing is accessible either through DeFi protocols such as Aave or Compound or by CeFi companies, for instance, BlockFi or Celsius.
CeFi or centralized finance operates in a very similar way to how banks operate. This is also why sometimes we call these companies “crypto banks”. BlockFi, for example, takes custody over deposited assets and lends them out to either institutional players such as market makers or hedge funds or to the other users of their platform.
Although the centralized lending model works just fine, it is susceptible to the same problems as centralized crypto exchanges – mainly losing customer deposits by either being hacked or other forms of negligence (bad loans, insider job etc.).
You can also argue that the CeFi model basically goes against one of the main value propositions of cryptocurrencies – self-custody of your assets.
This is also where DeFi lending comes into play.
Lending and Borrowing in DeFi
DeFi lending allows users to become lenders or borrowers in a completely decentralized and permissionless way while maintaining full custody over their coins.
DeFi lending is based on smart contracts that run on open blockchains, predominantly Ethereum. This is also why DeFi lending, in contrast to CeFi lending, is accessible to everyone without a need of providing your personal details or trusting someone else to hold your funds.
Aave and Compound are two main lending protocols available in DeFi. Both of the protocols work by creating money markets for particular tokens such as ETH, stable coins like DAI and USDC or other tokens like LINK or wrapped BTC.
Users, who want to become lenders, supply their tokens to a particular money market and start receiving interest on their tokens according to the current supply APY.
The supplied tokens are sent to a smart contract and become available for other users to borrow. In exchange for the supplied tokens, the smart contract issues other tokens that represent the supplied tokens plus interest. These tokens are called cTokens in Compound and aTokens in Aave and they can be redeemed for the underlying tokens. We’ll dive deeper into their mechanics later in this article.
It’s also worth mentioning that in DeFi, at the moment, pretty much all of the loans are overcollateralized. This means that a user who wants to borrow funds has to supply tokens in the form of collateral that is worth more than the actual loan that they want to take.
At this point, you may ask the question – what’s the point of taking a loan if you have to supply tokens that are worth more than the actual amount of the loan taken. Why wouldn’t someone just sell their tokens in the first place?
There are quite a few reasons for this. Mainly, the users don’t want to sell their tokens but they need funds to cover unexpected expenses. Other reasons include avoiding or delaying paying capital gain taxes on their tokens or using borrowed funds to increase their leverage in a certain position.
So, is there a limit on how much can be borrowed?
Yes. The amount that can be borrowed depends on 2 main factors.
The first one – how much funds are available to be borrowed in a particular market. This is usually not a problem in active markets unless someone is trying to borrow a really big amount of tokens.
The second one – what is the collateral factor of supplied tokens. Collateral factor determines how much can be borrowed based on the quality of the collateral. DAI and ETH, for example, have a collateral factor of 75% on Compound. This means that up to 75% of the value of the supplied DAI or ETH can be used to borrow other tokens.
If a user decides to borrow funds, the value of the borrowed amount must always stay lower than the value of their collateral times its collateral factor. If this condition holds there is no limit on how long a user can borrow funds for.
If the value of the collateral falls below the required collateral level, the user would have their collateral liquidated in order for the protocol to repay the borrowed amount.
The interest that lenders receive and the interest, that borrowers have to pay are determined by the ratio between supplied and borrowed tokens in a particular market.
The interest that is paid by borrowers is the interest earned by lenders, so the borrow APY is higher than the supply APY in a particular market.
The interest APYs are calculated per Ethereum block. Calculating APYs per block means that DeFi lending provides variable interest rates that can change quite dramatically depending on the lending and borrowing demand for particular tokens.
This is also where one of the biggest differences between Compound and Aave comes in. Although both protocols offer variable supply and borrow APYs, Aave also offers stable borrow APY. Stable APY is fixed in a short-term, but it can change in the long-term to accommodate changes in the supply/demand ratio between tokens.
On top of stable APY, Aave also offers flash loans where users can borrow funds with no upfront collateral for a very short period of time – one Ethereum transaction. More on the flash loans here.
To better understand how the DeFi lending protocols work, let’s dive into an example.
How Does It Work
Let’s dive deeper into the mechanics of Compound and cTokens.
In our example, a user deposits 10 ETH into Compound. In exchange for 10 ETH, Compound issues cTokens in this case cETH.
How many cETH tokens will the user receive? This depends on the current exchange rate for a particular market, in this case, ETH. When a new market is created the exchange rate between cTokens and underlying tokens is set to 0.02. This is an arbitrary number, but we can assume that each market starts at 0.02. We can also assume that this exchange rate can only increase with each Ethereum block.
If the user supplied 10 ETH when the market was just created they would’ve received 10/0.02=500 cETH. Because the ETH market has been operating for a while we can assume that the exchange rate is already higher. Let’s say it is 0.021.
This means that the user would receive 10/0.021=~476.19 cETH. If the user decided to immediately redeem their ETH, they should receive roughly the same amount as it was deposited, which is around 10 ETH.
Now, here is when the magic happens. The user holds their cETH. This is just another ERC20 token and can be sent anywhere. The main difference is that cETH is necessary to redeem the underlying ETH from Compound. On top of that, cETH keeps accumulating interest, even if it is sent from the original wallet that initiated the deposit to another wallet.
With each Ethereum block, the exchange rate would increase. The rate of the increase depends on the supply APY which is determined by the ratio of supplied/borrowed capital.
In our example, let’s say that the exchange rate from cETH to ETH increases by 0.0000000002 with each block. Assuming that the rate of increase stays the same for a month we can easily calculate the interest that can be made during that time.
Let’s say on average we have 4 blocks per minute. This gives us the following numbers.
0.0000000002*4*60*24*30=0.00003456. Now we can add this number to the previous exchange rate. 0.021+0.00003456=0.02103456.
If the user decides to redeem their ETH they would receive 476.19*0.0213456=~10.0165 ETH. So the user just made 0.0165 ETH in a month which is around 0.16% return on their ETH. It’s worth noting that the original amount of cETH that the user received hasn’t changed at all and only the change in the exchange rate allowed the user to redeem more ETH than was initially deposited.
Aave uses a similar model with interest being accumulated every single block. The main difference is that aTokens’ value is pegged to the value of the underlying token at a 1:1 ratio. The interest is distributed to aToken holders directly by continuously increasing their wallet balance. aToken holders can also decide to redirect their stream of interest payments to another Ethereum address.
When it comes to borrowing, users lock their cTokens or aTokens as collateral and borrow other tokens. Collateral earns interest, but users cannot redeem or transfer assets while they are being used as collateral.
As we mentioned earlier the amount that can be borrowed is determined by the collateral factor of the supplied assets. There is also a smart contract that looks at all the collateral across user’s account and calculates how much can be safely borrowed without getting liquidated immediately. To determine the value of collateral Compound uses its own price feed that takes prices from several highly liquid exchanges. Aave on the other hand relies on Chainlink and falls back to their own price feed if necessary.
If a user decides to repay the borrowed amount and unlock their collateral, they also have to repay the accrued interest on their borrowed assets. The amount of accrued interest is determined by the borrow APY and it is also increased automatically with each Ethereum block.
Risks
DeFi lending, although reducing a lot of risks associated with centralized finance, comes with its own risks.
Mainly the ever-present smart contract risks, but also quickly changing APYs. For example, during the last yield farming craze, the borrow APY on the BAT token went up to over 40%. This could cause unaware users who were not tracking Compound interest rates daily to get liquidated by having to repay more than expected in the same period of time.
So what do you think about lending and borrowing in DeFi? What is your favourite platform?
If you enjoyed reading this article you can also check out Finematics on Youtube and Twitter.