Introduction
This tutorial provides a comprehensive walkthrough for deploying Compound Protocol to create a decentralized lending platform.
Environment Specifications:
- Operating System: macOS 10.15.6
- Blockchain Network: BSC Testnet
- Tools: Remix IDE, MetaMask
- Contract Source: Compound Protocol GitHub
Pro Tip: Enable optimization during compilation in Remix for better performance.
Core Modules Breakdown
1. COMP Token Module
The incentive asset contract uses a standard ERC20 implementation.
Deployment Steps:
- Deploy COMP contract (address:
0x1fe7FF222D59B6648D640090046661313A1CF0a2) - Configure ComptrollerG7.sol with your COMP address
function getCompAddress() public view returns (address) {
return 0x1fe7FF222D59B6648D640090046661313A1CF0a2;
}2. Comptroller Module
The core governance system consisting of:
- Unitroller.sol (proxy contract)
- ComptrollerG7.sol (logic contract)
Deployment Results:
- Unitroller:
0x268e3eF4380DA46e55B77a6263810910722a875E - ComptrollerG7:
0x67006E2110119Abfd40b2A743A85b4d3bF8967b9
3. Price Oracle Module
SimplePriceOracle.sol deployment: 0x5991199a9aB1801A229a2E49a042471eDE997a21
Configuration Process
Binding and Initialization
- Proxy Binding
Call_setPendingImplementationin Unitroller.sol
Call_becomein ComptrollerG7.sol Parameter Settings
- Close Factor: 50% (500000000000000000)
- Liquidation Incentive: 8% (1080000000000000000)
- Oracle: Set to SimplePriceOracle address
Interest Rate Model
Deploy JumpRateModelV2.sol with parameters:
- Base Rate: 0
- Multiplier: 7% (70000000000000000)
- Jump Multiplier: 3x (3000000000000000000)
- Kink: 75% (750000000000000000)
Deployment Addresses:
- For ERC20:
0x8A517DA790929D2aC3527210f9472E2822424180 - For ETH:
0x0cca4ccD1ED542B5D7F3Ebbcf49D92DCB0a8D04e
Token Deployment
ERC20 Implementation
- Deploy sample USDT contract:
0xBEA207ec294BCe7a866C3a598195A61Bb7E8D599 - Deploy CErc20Delegate:
0xc176eD65274b2a2d422126d597Be715fc97d2e98 - Deploy CErc20Delegator with 1:1 exchange rate
ETH Implementation
Deploy CEther.sol with parameters:
- Exchange Rate: 1:1
- Symbol: cETH
- Decimals: 18
Market Operations
Price Configuration
Set underlying prices via SimplePriceOracle:
- cUSD: 1.0 (1000000000000000000)
- cETH: 2000.0 (2000000000000000000000)
CToken Configuration
Set Reserve Factors:
- cUSD: 10%
- cETH: 20%
- Add markets via
_supportMarket - Set Collateral Factor to 60%
COMP Rewards System
Configure compSpeed (wei per block) for markets:
function _setCompSpeed(CToken cToken, uint compSpeed) public {
require(adminOrInitializing(), "only admin can set comp speed");
setCompSpeedInternal(cToken, compSpeed);
}👉 Learn advanced COMP distribution strategies
Testing Framework
Core Functionality Tests
- Deposit (Mint)
Verify cToken minting against underlying assets - Borrow
Test collateral verification and debt accrual - Repay
Validate debt reduction mechanics - Withdraw (Redeem)
Test liquidity checks and cToken burning - Liquidation
Verify underwater position handling
Frontend Integration
Key contract methods for DApp integration:
// Deposit
function mint(uint mintAmount) external returns (uint);
// Withdraw
function redeem(uint redeemTokens) external returns (uint);
function redeemUnderlying(uint redeemAmount) external returns (uint);
// Borrow/Repay
function borrow(uint borrowAmount) external returns (uint);
function repayBorrow() external payable;
function repayBorrowBehalf(address borrower) external payable;👉 Complete API reference for developers
FAQ Section
Q: How is interest calculated in Compound?
A: Interest accrues continuously per block based on utilization rates using the configured InterestRateModel.
Q: What's the difference between Unitroller and Comptroller?
A: Unitroller is the upgradeable proxy while Comptroller contains the actual logic implementation.
Q: How often should price oracles update?
A: For production environments, consider using Chainlink or other decentralized oracle solutions with regular price feeds.
Q: Can I change parameters after deployment?
A: Most parameters can be updated by governance, but some core settings are immutable.
Q: How do liquidations work?
A: When account liquidity becomes negative, liquidators can repay portions of debt to receive discounted collateral.
Q: What's the minimum deployment requirement?
A: At minimum you need: COMP token, Comptroller, Price Oracle, and at least one money market (cToken).