DeFi Deployment Guide: Building a Decentralized Lending Bank with Compound

·

Introduction

This tutorial provides a comprehensive walkthrough for deploying Compound Protocol to create a decentralized lending platform.

Environment Specifications:

Pro Tip: Enable optimization during compilation in Remix for better performance.

 title=

Core Modules Breakdown

1. COMP Token Module

The incentive asset contract uses a standard ERC20 implementation.

Deployment Steps:

  1. Deploy COMP contract (address: 0x1fe7FF222D59B6648D640090046661313A1CF0a2)
  2. Configure ComptrollerG7.sol with your COMP address
function getCompAddress() public view returns (address) {
    return 0x1fe7FF222D59B6648D640090046661313A1CF0a2;
}

2. Comptroller Module

The core governance system consisting of:

Deployment Results:

3. Price Oracle Module

SimplePriceOracle.sol deployment:
0x5991199a9aB1801A229a2E49a042471eDE997a21

Configuration Process

Binding and Initialization

  1. Proxy Binding
    Call _setPendingImplementation in Unitroller.sol
    Call _become in ComptrollerG7.sol
  2. Parameter Settings

    • Close Factor: 50% (500000000000000000)
    • Liquidation Incentive: 8% (1080000000000000000)
    • Oracle: Set to SimplePriceOracle address

Interest Rate Model

Deploy JumpRateModelV2.sol with parameters:

Deployment Addresses:

  1. For ERC20: 0x8A517DA790929D2aC3527210f9472E2822424180
  2. For ETH: 0x0cca4ccD1ED542B5D7F3Ebbcf49D92DCB0a8D04e

Token Deployment

ERC20 Implementation

  1. Deploy sample USDT contract: 0xBEA207ec294BCe7a866C3a598195A61Bb7E8D599
  2. Deploy CErc20Delegate: 0xc176eD65274b2a2d422126d597Be715fc97d2e98
  3. Deploy CErc20Delegator with 1:1 exchange rate

ETH Implementation

Deploy CEther.sol with parameters:

Market Operations

Price Configuration

Set underlying prices via SimplePriceOracle:

CToken Configuration

  1. Set Reserve Factors:

    • cUSD: 10%
    • cETH: 20%
  2. Add markets via _supportMarket
  3. 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

  1. Deposit (Mint)
    Verify cToken minting against underlying assets
  2. Borrow
    Test collateral verification and debt accrual
  3. Repay
    Validate debt reduction mechanics
  4. Withdraw (Redeem)
    Test liquidity checks and cToken burning
  5. 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).