We’ve talked about “What is Compound” and now, we’ll investigate “How Does Compound Work”.
Unlike banks where interest rates are fixed, Compound interest works in a dynamic fashion. The Compound interest keeps changing depending on the balance of a particular liquidity pool. When the total amount of crypto in a liquidity pool is abundantly available, the annual interest is low for lending. However, for a smaller pool with a lesser balance, the Compound Annual Growth Rate is high.
Similarly, the interest rate for borrowing from a larger pool is less since there is sufficient money to borrow. On the contrary, the interest rate is higher when someone borrows from a small liquidity pool.
The principal amount is compounded daily so that your money witnesses exponential growth at an incredibly faster rate. In banks, your savings are locked in for long periods that can be as long as nine years. With the DeFi protocol’s daily compounding interest, you don’t need to wait so long.
In fact, the compounding period is as small as a few seconds. Although the interest rate is displayed for annual terms, Compounding periods are as low as one Ethereum block mine time.
The obvious advantage of such short Compounding periods is that you will be earning interest on a daily compounding basis. This means you don’t need to wait for monthly interests. With a floating interest rate, the returns on your initial investment will also be significantly higher. Overall, compounding interest on your starting amount will give you larger returns on your money.
There are two main contracts in Compound: cToken and Comptroller. Let’s start by exploring them.
The Comptroller
The Comptroller is the risk management layer of the Compound protocol; it determines how much collateral a user is required to maintain, and whether (and by how much) a user can be liquidated. Each time a user interacts with a cToken, the Comptroller is asked to approve or deny the transaction.
As you can understand from its name, The Comptroller is the controller of The Compound. It adds, removes, starts, pauses, etc. cTokens. It is the guardian, accounter, and manager of The Compound. It’s kinda Uniswap v2’s router + factory + some extra shit.
Also, it is upgradable. With the governance token, the community can upgrade the comptroller.
Some of the functions that the Comptroller has:
enterMarkets
: In order to supply collateral or borrow in a market, it must be entered first. So with this function, you can enter any market you want. It takes an address list. This list contains the markets (cTokens) that you want to enter.exitMarket
: Exited markets will not count towards account liquidity calculations. It takes one address as a parameter.
cToken
In Compound if you have some cTokens (cAAVE, cDAI, etc.), that means you have some rights over Compound. Some of the underlying assets of cToken belong to you. You can get it whenever you want.
cTokens are represents the underlying assets. For example, cAAVE represents the AAVE. But they are not 1-1. All cTokens has exchange rate. It is equal to 0.02 at the beginning but it will increase buy time.
Let’s say you supply 1,000 DAI to the Compound protocol, when the exchange rate is 0.020070; you would receive 49,825.61 cDAI (1,000/0.020070).
A few months later, you decide it’s time to withdraw your DAI from the protocol; the exchange rate is now 0.021591:
- Your 49,825.61 cDAI is now equal to 1,075.78 DAI (49,825.61 * 0.021591)
- You could withdraw 1,075.78 DAI, which would redeem all 49,825.61 cDAI
- Or, you could withdraw a portion, such as your original 1,000 DAI, which would redeem 46,315.59 cDAI (keeping 3,510.01 cDAI in your wallet)
Some of the functions that cTokens have:
mint
: The mint function transfers an asset into the protocol, which begins accumulating interest based on the current supply rate for the asset. The user receives a quantity of cTokens equal to the underlying tokens supplied, divided by the current exchange rate.redeem
: The redeem function converts a specified quantity of cTokens into the underlying asset, and returns them to the user. The amount of underlying tokens received is equal to the quantity of cTokens redeemed, multiplied by the current exchange rate. The amount redeemed must be less than the user's account liquidity and the market's available liquidity.borrow
: The borrow function transfers an asset from the protocol to the user, and creates a borrow balance which begins accumulating interest based on the borrow rate for the asset. The amount borrowed must be less than the user's account liquidity and the market's available liquidity.repay borrow
: The repay function transfers an asset into the protocol, reducing the user's borrow balance.liquidate borrow
: A user who has negative account liquidity is subject to liquidation by other users of the protocol to return his/her account liquidity back to positive (i.e. above the collateral requirement). When a liquidation occurs, a liquidator may repay some or all of an outstanding borrow on behalf of a borrower and in return receive a discounted amount of collateral held by the borrower; this discount is defined as the liquidation incentive.