Major flaws of blockchain assets:
- Limited borrowing mechanisms, leading to mispriced assets(e.g. scamcoins).- Negative yield of assets due to storage costs and risks, leading to volatility.
Compound Protocol: Decentralized system for rictionless borrowing of Ethereum tokens without existing flaws, and creating a safe positive-yield approach to storing assets.
Money markets: Pools of assets with algorithmically derived interest rates, based on the supply and demand for the asset, unique to an Ethereum asset.
The protocol aggregates supply of each user, when user supplies asset it becomes a fungible resource, offering more liquidity unless each asset is borrowed, users can withdraw assets anytime without waiting for any a loan to mature.
When a supplier supplies asset to market, in return he is provided cTokens. As the money market recieves interest(function of borrowing demand), cTokens convert into increasing amount of underlying asset.
A user needs to specify a desired asset for borrowing, using cTokens as collateral.
each money market has a floating interest rate, set by market forces, which determines the
borrowing cost for each asset.
Each market has a collateral factor, ranging from 0 to 1, that represents the portion of the underlying asset value that can be borrowed.
User’s borrowing capacity:The sum of the value of an accounts underlying token balances, multiplied by the collateral factors.
Close Factor: The portion of borrowed assets that can be repaid, ranges from 0 to 1. The liquidation process may continue to be called until the user’s borrowing is less than their borrowing capacity.
Interest Rate Earned by supplier: Borrowing Interest Rate_a * U_a
In periods of extreme demand for an asset, the liquidity of the protocol (the tokens available to withdraw or borrow) will decline; when this occur, interest rates rise, incentivizing supply, and disincentivizing borrowing.
Implementation
Each money market - ERC20 token specification smart contract.
Users mint cTokens by supplying assets to market or redeem cTokens for underlying asset.
Interest Rate Index: Captures the history of each interest rate, for each money market, which is calculated each time an interest rate changes, resulting from a user minting, redeeming, borrowing, repaying or liquidating the asset.
Reserves: Portion of received interest that is retained, reserveFactor ranges 0 to 1.
reserves_a = reserves_a, n-1 + totalBorrowBalance_a,n-1 * (r*t*reserveFactor)
Borrower's Balance: ratio of the current index divided by the index when the user’s balance was last checkpointed.
The balance for each borrower address in the cToken is stored as an account checkpoint. An account checkpoint is a Solidity tuple <uint256 balance, uint256 interestIndex> . This tuple describes the balance at the time interest was last applied to that account.
borrow(uint amount) : t. This function call checks the user’s account value, and given sufficient collateral, will update the user’s borrow balance, transfer the tokens to the user’s Ethereum address, and update the money market’s floating interest rate.
Liquidation: If a user’s borrowing balance exceeds their total collateral value (borrowing capacity) due to the value of collateral falling, or borrowed assets increasing in value, the public function liquidate(address target, address collateralAsset, address borrowAsset, uint closeAmount) can be called, which exchanges the invoking user’s asset for the borrower’s collateral, at a slightly better than market price.
Comptroller: Policy layer, validates each function call. Validates collateral and liquidity before allowing user action to proceed.
Questions
How the protocol avoids the risk whenever borrowing amount exceeds borrowing capacity? Had difficulty understanding this,
If the value of an account’s borrowing outstanding exceeds their borrowing capacity, a portion of the outstanding borrowing may be repaid in exchange for the user’s cToken collateral, at the current market price minus a liquidation discount ; this incentives an ecosystem of arbitrageurs to quickly step in to reduce the borrower’s exposure, and eliminate the protocol’s risk.
How does the protocol decides the Interest Rate?
The protocol incentivizes lenders to to lend to the market by giving them cTokens whose value may increase due to the interest rates or market demand but how is it incentivizing the borrowers to borrow from the market?
What does the function repayBorrow(uint amount) do?
When the borrowers assets are liquified due to collateral falling or borrowed assets' value increase, the liquidate function is called. Who calls this function? Does the contract keeps check of this from time to time?
Compound: Money Market Protocol
- Limited borrowing mechanisms, leading to mispriced assets(e.g. scamcoins).
- Negative yield of assets due to storage costs and risks, leading to volatility.
U_a = Borrows_a / (Cash_a + Borrows_a)
Borrowing Interest Rate_a = 2.5% + U_a * 20%
Borrowing Interest Rate_a * U_a
Implementation
mint
cTokens by supplying assets to market orredeem
cTokens for underlying asset.exchangeRate = (underlyingBalance + totalBorrowBalance_a − reserves_a) / cTokenSupply_a
Index_a,n = Inde_a,n-1 * (1 + r*t)
totalBorrowBalance_a,n = totalBorrowBalance_a,(n-1) * (1 + r*t)
reserves_a = reserves_a, n-1 + totalBorrowBalance_a,n-1 * (r*t*reserveFactor)
borrow(uint amount)
: t. This function call checks the user’s account value, and given sufficient collateral, will update the user’s borrow balance, transfer the tokens to the user’s Ethereum address, and update the money market’s floating interest rate.liquidate(address target, address collateralAsset, address borrowAsset, uint closeAmount)
can be called, which exchanges the invoking user’s asset for the borrower’s collateral, at a slightly better than market price.Questions
If the value of an account’s borrowing outstanding exceeds their borrowing capacity, a portion of the outstanding borrowing may be repaid in exchange for the user’s cToken collateral, at the current market price minus a liquidation discount ; this incentives an ecosystem of arbitrageurs to quickly step in to reduce the borrower’s exposure, and eliminate the protocol’s risk.