Compound V3 Book by RareSkills
Compound Finance is the most forked DeFi lending protocol.
By learning the Compound Finance codebase and tokenomics in depth, you will be able to understand dozens of other lending protocols and be able to navigate their codebases more efficiently.
The RareSkills Compound V3 book is a line-by-line examination of the Compound V3 protocol. We explain the tokenomics, architecture, and the code in great detail — down to the number of decimals certain variables have.
Our hope is for you to gain an understanding of the protocol with a depth comparable to if you had written it yourself.
Even if you develop on non-EVM blockchains or layer 2s, what you learn here will still be relevant.
How to read this book
Imagine a protocol engineer sat down with you and walked you through the codebase and design decisions. That is what this book is like.
We do not shy away from difficult subjects in our code walkthroughs, so don’t try to cram the information. This resource makes this process as simple as possible, but no matter how you slice it, this is still a big undertaking. Have realistic expectations for how many new ideas you can learn in one session. Compound was groundbreaking when it launched, so mastering the whole thing in 3 days isn’t realistic at all.
On the other hand, if you understand the building blocks of Compound V3, the codebase is not as complex as its line count would suggest. We do not simply provide screenshots of each line and explain the code — we provide a mental framework about how all the high level ideas fit together.
Make sure you are familiar with each of the prerequisites, then read the chapters of the Compound V3 book in order.
About Compound V3
Compound only lends out one kind of asset, which it calls the “base” asset
Unlike Compound V2 (and AAVE) where the borrower can borrow from a menu of assets, in Compound V3, borrowers can only borrow a single asset (and lenders can only lend a single asset) — per “market.” At this time of writing, there is a market for borrowing (and lending) USDC and a market for borrowing and lending ETH.
The available markets are shown on the “Compound V3 markets” page which we provide a screenshot of below. As you can see, it is only possible to borrow USDC or ETH depending on the chain.
Because USDC is the most common asset to borrow and lend, we will refer to the base asset as USDC throughout this series. Collateral does not earn interest in Compound V3.
Compound V3 refers to itself by the codeword “Comet.” Sometimes, the word “Comet” may refer to the “core lending smart contract” and “Compound V3” referring to the entire system of smart contracts. Other times, “Comet” and “Compound V3” are used interchangeably, but don’t worry, it will be very clear from the context.
You need to have the following background knowledge to understand Compound V3. Feel free to skip sections you are already familiar with.
It is common for a privileged actor to configure DeFi applications or change their parameters — but instead of being a multisignature wallet, it is a governance smart contract. This contract initiates transactions on the basis of a programmable democracy. We will refer to “governance” throughout this series — read this article first if you aren’t already familiar.