In a decentralized world , when you are lending money you definitely want to take some collateral, but you can’t take his house as collateral. it has to be something digital.
so suppose I want to borrow 1k DAI, I will give some Eth as colletral and after sometime when I return my DAI with interest, I can get my Eth back.
now a lot of you will be thinking wtf why can’t I just sell my eth and take DAI for it, we will answer this question at the last.
so let’s start with how things really work.
Alice wants to borrow DAI against her ETH.
Step 1: Alice supplies 10 ETH (worth $20,000) to the pool.
She receives 10 sETH in her wallet. The contract now knows she is a lender.
The contract also marks her 10 ETH as collateral.
Step 2: The Contract Calculates Her "Borrowing Power."
The protocol has a set of risk parameters for each asset. For a volatile asset like ETH, the Loan-to-Value (LTV) ratio might be 75%.
This means Alice can borrow up to 75% of the value of her collateral.
Borrowing Power = $20,000 * 0.75 = $15,000.
Step 3: Alice Borrows 10,000 DAI.
She calls the borrow() function, requesting 10,000 DAI.
The contract checks that 10,000 is less than her 15,000 borrowing power. It is.
The contract sends 10,000 DAI from its pool of supplied DAI to Alice's wallet.
The contract now internally records a debt for Alice: Debt = 10,000 DAI. This debt will start accruing interest immediately.
but who supplied this 10k DAI to allice? answer is Lenders. these are people who keep assets into these smart contracts to earn interest over them
Step 4: The Health Factor. The protocol constantly tracks the health of Alice's loan using a single number, the Health Factor.
Formula (Simplified): Health Factor = (Value of Collateral * Liquidation Threshold) / Value of Debt
The Liquidation Threshold is another risk parameter, slightly higher than the LTV. For ETH, it might be 80%.
Alice's Initial Health Factor: ($20,000 * 0.80) / $10,000 = 1.6.
The Rule: If the Health Factor ever drops below 1.0, the position is eligible for liquidation.
3. The Interest Rate Model (The Algorithm)
How are interest rates decided? They are not set by a person. They are determined algorithmically based on the utilization rate of the pool.
Utilization Rate: Utilization = (Total Amount Borrowed) / (Total Amount Supplied)
The Logic:
If utilization is low (e.g., lots of DAI supplied, but few people are borrowing it), the interest rate for both borrowers and lenders will be very low. This encourages borrowing.
If utilization is high (e.g., almost all the supplied DAI has been borrowed), the interest rate will be very high. This encourages new lenders to supply DAI (to capture the high yield) and encourages borrowers to repay their loans (to stop paying the high interest).
The interest rate is a constantly adjusting curve that seeks to find an equilibrium for supply and demand for each asset in the pool.
4. The Liquidation Process (The Automated Failsafe)
This is the most critical part that ensures lenders never lose their money.
The Scenario: The price of ETH crashes. Alice's 10 ETH are now only worth $12,500.
Step 1: The Health Factor Drops.
Let's recalculate Alice's Health Factor:
Health Factor = ($12,500 * 0.80) / $10,000 = $10,000 / $10,000 = 1.0.
Her position is now exactly at the liquidation threshold. If the price of ETH drops by even one more dollar, her Health Factor will dip below 1.0.
Step 2: The Position is Flagged for Liquidation.
- The smart contract's state now shows that Alice's loan is unhealthy. This is public information.
Step 3: A Liquidator Steps In.
A liquidator is any user or bot on the network who is monitoring for unhealthy loans. They are bounty hunters.
The protocol allows a liquidator to repay a portion (e.g., up to 50%) of the unhealthy debt.
A liquidator, let's call him Bob, decides to liquidate Alice's position. He calls the liquidate() function on the smart contract.
Step 4: The Liquidation Transaction. In one atomic transaction, the following happens:
Bob sends $5,000 DAI (50% of Alice's debt) to the smart contract. This repays half of Alice's loan.
The smart contract calculates how much of Alice's ETH collateral Bob is entitled to claim. The protocol gives him a liquidation bonus (e.g., 5%) as a reward. So, he is entitled to claim $5,000 * 1.05 = $5,250 worth of Alice's ETH.
The contract sends Bob $5,250 worth of Alice's ETH. At today's price of $1,250/ETH, this is 5250 / 1250 = 4.2 ETH.
Bob has made an instant, risk-free profit of $250.
The Aftermath
For Alice (The Borrower):
She has lost 4.2 of her ETH.
Her debt is now reduced to 5,000 DAI.
Her collateral is reduced to 5.8 ETH (worth $7,250).
Her Health Factor is now healthy again at 1.16, calculated as:
($7,250 * 0.80) / $5,000 = 1.16.
For the Lenders:
They are completely unaffected.
The protocol's debt was partially repaid, and the risk was eliminated.
The system remains solvent.
the whole system is based on the logic that the value of collateral > value of loan taken allways, so that the lenders never loose their money
now let’s answer the question, why not just sell eth and buy DAI instead of borrowing like this
The Fundamental Difference in One Sentence:
When you sell, you give up all future price exposure (upside and downside) on the asset you sold. When you borrow against an asset, you retain 100% of the price exposure on your full collateral.
The Mathematical Proof
Let's set up a clear scenario with defined variables.
Our Goal: You need $10,000 of liquidity (DAI). You are starting with 10 ETH.
Initial State:
E_initial = 10 ETH
P_initial = $2,000 / ETH
Your Initial Net Worth = 10 * $2,000 = $20,000
D_needed = $10,000 DAI
Let's assume you use this $10,000 for an external purpose (like buying a car or paying rent). Our goal is to see which strategy leaves you with the most final ETH after you have "returned" the $10,000 value to the system.
Let P_final be the price of ETH at the end of the period.
Strategy A: Sell and Re-buy
Get Liquidity: To get $10,000 DAI, you must sell some ETH at the initial price. ETH_sold = D_needed / P_initial = $10,000 / $2,000 = 5 ETH.
Your Portfolio: You now hold 5 ETH and 10,000 DAI. You spend the DAI. Your remaining crypto portfolio is just 5 ETH. You have permanently given up exposure on the 5 ETH you sold.
End State: No matter what happens to the price of ETH, your final position is 5 ETH.
- E_final_A = 5 ETH
Strategy B: Borrow and Repay
Get Liquidity:
You deposit all 10 ETH as collateral in a lending protocol.
You borrow $10,000 DAI.
You spend the DAI.
Your Portfolio: You now have 10 ETH as collateral and a debt of 10,000 DAI. You still have full price exposure to all 10 of your original ETH.
End State: At the end of the period, you must repay your loan to unlock your collateral. Let's assume you paid
200ininterest∗∗,soyourtotaldebtis∗∗200ininterest∗∗,soyourtotaldebtis∗∗
10,200 DAI. To get this DAI, you must sell a portion of your ETH collateral at the new, final price (P_final).
ETH_to_sell_for_repayment = ($10,000 + $200) / P_final = 10,200 / P_final
Your final ETH amount is what's left of your collateral after you've sold some to repay the debt.
E_final_B = 10 ETH - (10,200 / P_final)
The Comparison: Which Strategy Wins?
Now we compare E_final_A (which is always 5 ETH) with E_final_B under different price scenarios.
Scenario 1: The Price of ETH Rises (P_final = $3,000)
Strategy A (Sell): You are left with 5.0 ETH.
Strategy B (Borrow):
You need to sell 10,200 / 3,000 = 3.4 ETH to repay your loan.
Your final ETH is 10 - 3.4 = 6.6 ETH.
Result: Borrowing was vastly better. You ended up with 1.6 more ETH because you retained the upside on all 10 of your original coins.
Scenario 2: The Price of ETH Stays the Same (P_final = $2,000)
Strategy A (Sell): You are left with 5.0 ETH.
Strategy B (Borrow):
You need to sell 10,200 / 2,000 = 5.1 ETH to repay your loan.
Your final ETH is 10 - 5.1 = 4.9 ETH.
Result: Selling was slightly better. The cost of the interest on the loan made the borrowing strategy slightly less profitable.
Scenario 3: The Price of ETH Drops (P_final = $1,500)
Strategy A (Sell): You are left with 5.0 ETH. (Your loss was limited because you held half your value in stable DAI).
Strategy B (Borrow):
You need to sell 10,200 / 1,500 = 6.8 ETH to repay your loan.
Your final ETH is 10 - 6.8 = 3.2 ETH.
Result: Selling was vastly better. Borrowing amplified your losses because you were fully exposed to the downside on all 10 ETH.
Conclusion
follow me for more such “How things really work blog”