Cipherbase
BTC ETH XMR
DeFi Entry 09 of 20

How to Use Compound Protocol for DeFi Lending and Borrowing

Compound is a foundational DeFi protocol that lets you lend crypto assets to earn algorithmic interest or borrow against your collateral — no intermediaries required. Rates adjust automatically based on supply and demand, all governed by smart contracts on Ethereum. This tutorial covers how Compound works and how to start using it in your yield strategy.

Animated diagram of deposits flowing into a lending pool, a borrower posting collateral and interest flowing back to lenders.
Animated diagram of deposits flowing into a lending pool, a borrower posting collateral and interest flowing back to lenders.
On this page
  1. How Compound Works
  2. Supplying Assets: Step by Step
  3. Borrowing Against Collateral
  4. COMP Token and Governance
  5. Integrating with Compound Programmatically
  6. Compound in the Broader DeFi Ecosystem

Compound is one of the foundational protocols in decentralized finance, letting you lend assets to earn interest or borrow against collateral without a bank or broker in the middle. Unlike traditional lending, rates adjust algorithmically based on supply and demand, and everything runs on smart contracts deployed on Ethereum. This tutorial walks through how Compound works, how to interact with it, and how it fits into broader yield farming strategies.


How Compound Works

Compound operates through liquidity pools, with a separate pool for each supported asset like ETH, USDC, DAI, or WBTC. When you deposit an asset, you receive cTokens (e.g., cUSDC, cDAI) that represent your share of the pool and automatically accrue interest over time.

Supply and Borrow Mechanics

Suppliers deposit assets into a pool and earn the supply APY. Borrowers draw from the same pool and pay the borrow APY. The spread between those two rates is how the protocol stays solvent and builds reserves.

Interest rates aren't fixed. They follow a rate model where utilization — the ratio of borrowed assets to total supplied — pushes rates up or down. High utilization means scarce liquidity, so rates rise to attract more suppliers and slow new borrowing.

Utilization Rate = Total Borrows / Total Supply

Supply APY  = Borrow APY × Utilization Rate × (1 - Reserve Factor)

This self-correcting mechanism means rates can shift significantly within hours during volatile market conditions.

cTokens and Accrued Interest

When you deposit 1,000 USDC, you receive a proportional amount of cUSDC. The exchange rate between cUSDC and USDC increases continuously as interest accrues. You don't receive separate interest payments — your cToken balance stays the same, but each cToken redeems for more USDC over time.

That design makes cTokens composable. You can hold them in a wallet, transfer them, or use them as collateral in other protocols. That last part is central to how yield farming strategies stack returns across multiple platforms.


Supplying Assets: Step by Step

Connecting and Approving

Navigate to app.compound.finance and connect your wallet (MetaMask, Coinbase Wallet, or any WalletConnect-compatible wallet). Before supplying an ERC-20 token, you need to approve the Compound contract to spend it.

// ERC-20 approval — happens via UI or directly via contract call
IERC20(tokenAddress).approve(cTokenAddress, type(uint256).max);

The UI handles this in two transactions: one approval and one supply. ETH skips this step since it's the native asset.

Supplying via the UI

  1. Select the asset from the Supply Markets panel.
  2. Enter the amount and confirm the transaction.
  3. Your wallet will show the cToken balance after confirmation.

Supply transactions typically cost 100,000–200,000 gas units. On mainnet during peak congestion, that gets expensive fast, which is why many users have migrated to Compound deployments on Layer 2 networks like Base or Polygon. You get the same core mechanics at a fraction of the cost.


Borrowing Against Collateral

Collateral Factor and Borrowing Power

Each asset has a collateral factor — the percentage of its value you're allowed to borrow against. USDC might carry a collateral factor of 0.90 (90%), while ETH sits at 0.83 (83%). Riskier or less liquid assets get lower collateral factors.

AssetCollateral FactorTypical Supply APYTypical Borrow APY
USDC90%3–8%4–10%
ETH83%1–3%2–5%
DAI83%3–7%4–9%
WBTC70%0.5–2%1–4%
UNI75%0.1–1%1–3%

APYs shown are approximate historical ranges, not guarantees. Rates shift with market conditions.

“Decentralized finance is the future of money.”

— Unknown

Your total borrowing capacity is the sum of (collateral value × collateral factor) across all supplied assets. Compound calls this your "borrow limit."

Health Factor and Liquidation

If your borrowed assets rise in value or your collateral drops, your borrow usage climbs toward 100% of your limit. Once it hits that ceiling, liquidators can repay part of your debt and claim your collateral at a discount, typically around 8%.

To stay safe, keep your borrow limit usage below 70–75%. On-chain bots watch for undercollateralized positions around the clock — there's no grace period, no warning email, nothing.

// Check account liquidity using Compound's Comptroller
const [error, liquidity, shortfall] = await comptroller.getAccountLiquidity(userAddress);
// liquidity > 0 means you have borrowing room
// shortfall > 0 means you are eligible for liquidation

COMP Token and Governance

Compound distributes COMP tokens to both suppliers and borrowers as a protocol incentive. It was one of the first implementations of liquidity mining and helped kick off the yield farming era, where users started optimizing for total return including token rewards rather than just base interest.

COMP holders can propose and vote on protocol changes — adjusting collateral factors, adding new assets, modifying rate models, or upgrading contracts. Each COMP token equals one vote, and proposals require a minimum quorum to pass.

Governance is fully on-chain. Proposals are submitted as calldata encoding the exact contract calls that execute if the vote passes. That means you can audit exactly what a proposal will do before casting a single vote.


Integrating with Compound Programmatically

Developers regularly integrate Compound into DeFi applications, aggregators, and bots. The core interfaces are pretty straightforward.

Supplying and Redeeming via Smart Contract

interface ICErc20 {
    function mint(uint256 mintAmount) external returns (uint256);
    function redeem(uint256 redeemTokens) external returns (uint256);
    function redeemUnderlying(uint256 redeemAmount) external returns (uint256);
    function exchangeRateCurrent() external returns (uint256);
    function balanceOfUnderlying(address account) external returns (uint256);
}

// Supply 1000 USDC
IERC20(USDC).approve(address(cUSDC), 1000e6);
uint256 err = cUSDC.mint(1000e6);
require(err == 0, "mint failed");

// Check underlying balance including interest
uint256 balance = cUSDC.balanceOfUnderlying(address(this));

Return values of 0 indicate success in Compound V2. Non-zero values map to error codes defined in the protocol's ErrorReporter contract.

Fetching Rates Off-Chain

const { ethers } = require("ethers");
const provider = new ethers.JsonRpcProvider(RPC_URL);
const cUSDC = new ethers.Contract(CUSDC_ADDRESS, CERC20_ABI, provider);

// supplyRatePerBlock in mantissa (1e18 scale)
const ratePerBlock = await cUSDC.supplyRatePerBlock();

// Approximate APY assuming ~7160 blocks/day on Ethereum
const blocksPerYear = 7160 * 365;
const supplyAPY = (Math.pow((Number(ratePerBlock) / 1e18) + 1, blocksPerYear) - 1) * 100;
console.log(`Supply APY: ${supplyAPY.toFixed(2)}%`);

This is exactly how aggregators like Yearn Finance and DeFi dashboards pull live rate data to compare across protocols including Aave and dYdX.


Compound in the Broader DeFi Ecosystem

Compound doesn't exist in isolation. Its cTokens are building blocks that show up across the DeFi stack. Yield farming strategies often supply assets to Compound, then use the received cTokens

Frequently Asked Questions

What is Compound and how does it work?

Compound is a decentralized lending protocol on Ethereum that lets you earn interest by supplying crypto assets, or borrow assets by putting up collateral. When you supply tokens, you receive cTokens in return, which represent your deposit and automatically accrue interest over time. No sign-ups or intermediaries are involved — it all runs on smart contracts.

How do I start earning interest on Compound?

To get started, connect a Web3 wallet like MetaMask to the Compound app at app.compound.finance, then supply a supported asset such as USDC, ETH, or DAI. Once supplied, your balance starts earning interest immediately, and you can withdraw your funds plus accrued interest at any time.

What happens if my borrowed position gets liquidated?

Liquidation occurs when your collateral value drops too close to your borrowed amount, breaching the protocol's collateral factor threshold. At that point, a third party can repay part of your loan and claim your collateral at a discount as a penalty. To avoid this, keep your borrow balance well below your borrowing limit and monitor your account health regularly.

Video Resources

Sources & Further Reading

  • Compound Docs — Documentation for the Compound money market protocol.
  • DeFi Llama — Total value locked and protocol analytics across chains.
  • Ethereum.org: DeFi — Official introduction to decentralised finance on Ethereum.
  • Uniswap Docs — Protocol documentation for the leading automated market maker.
  • Aave Docs — Lending protocol documentation, risk parameters and governance.
  • Finematics — Educational explainers on DeFi mechanisms with diagrams.
  • Lido Docs — Liquid staking protocol documentation.