DEFI FINANCIAL MATHEMATICS AND MODELING

Building Dynamic Borrowing Models for Decentralized Finance

9 min read
#DeFi #Smart Contracts #Liquidity Pools #DeFi Lending #Risk Assessment
Building Dynamic Borrowing Models for Decentralized Finance

Introduction

Decentralized finance has turned borrowing and lending into a programmable activity that can be executed on a public blockchain without intermediaries. Behind the user interfaces that show a “borrow” button or a “lending pool” is a sophisticated mathematical engine. The engine must decide how much a user can borrow, how much interest to charge, and when a collateral position should be liquidated. Building a dynamic borrowing model requires a blend of financial theory, probability, and smart‑contract engineering.

This article walks through the key components that enable such a model, from interest‑rate determination to liquidation penalty and bonus structures. It is aimed at practitioners who want to design or audit a borrowing protocol that can adapt to market conditions while protecting the system from exploits.

Foundations of Borrowing Mechanics

A borrowing protocol can be thought of as a set of rules that map the state of the system—prices, user balances, and time—to the next state. The simplest form is a static collateral ratio that never changes. Real‑world protocols evolve this ratio over time to reflect volatility, liquidity, and governance decisions.

The core variables that any dynamic model must handle are:

  • Principal (P) – the amount borrowed.
  • Collateral (C) – the asset(s) pledged to secure the loan.
  • Collateral Value (Vₜ) – the market value of collateral at time t.
  • Collateral Ratio (CRₜ) – the fraction of collateral value that covers the principal, CRₜ = Vₜ / P.
  • Maintenance Ratio (MR) – the minimum collateral ratio required to avoid liquidation.
  • Liquidation Ratio (LR) – the ratio at which the protocol triggers a partial or full liquidation.

In a dynamic setting, MR and LR become functions of market variables, such as the volatility of the collateral token or the health of the overall protocol.

Modelling Interest Rates in DeFi

Interest rates in DeFi are typically floating, changing in response to supply and demand. The two dominant approaches are:

1. Algorithmic Market‑Based Rates

These rates follow a target utilization curve. Let U be the utilization of the pool:

U = TotalBorrowed / (TotalBorrowed + TotalSupplied)

The protocol defines a function f(U) that maps U to an annual percentage rate (APR). Common shapes are convex, increasing steeply as U approaches 100 %. This mechanism keeps borrowing incentives aligned with liquidity provision.

Example

If a pool has a target utilization of 80 % and a utilization of 90 %, the APR might jump from 5 % to 15 %. The smart contract updates the rate each block to reflect the new U.

2. External Oracle‑Driven Rates

Some protocols expose a single interest rate to all borrowers and lenders, sourced from an off‑chain oracle (e.g., an aggregated index of AMM rates). The advantage is transparency; the disadvantage is susceptibility to oracle manipulation if the oracle is not secure.

In practice, many DeFi platforms combine both approaches: a base rate from an oracle and a dynamic adjustment that captures pool supply‑demand imbalance.

Dynamic Collateralization

Static collateral ratios are simple but inflexible. A dynamic approach lets the protocol tighten collateral requirements during periods of high volatility or low liquidity. The key building blocks are:

Volatility‑Based Adjustments

Let σ denote the volatility of the collateral token over a rolling window. A high σ signals risk; the protocol can raise MR and LR proportionally.

MRₜ = MR_base + α * σₜ
LRₜ = LR_base + β * σₜ

where α and β are sensitivity coefficients chosen by governance.

Liquidity‑Based Adjustments

When the supply of collateral is low, the risk of a large price drop increases. The protocol can monitor the depth of the collateral pool or the slippage of large trades and adjust ratios accordingly.

MRₜ = MR_base + γ * (1 / Depthₜ)

A shallow depth triggers a higher MR.

Real‑Time Rebalancing

The protocol should rebalance collateral ratios in near real time to avoid lag that could expose users to sudden liquidation. A background worker (or a smart‑contract function called by users) recomputes MRₜ and LRₜ each block or at fixed intervals.

Liquidation Mechanics

Liquidation is the protocol’s safety valve that restores the collateral to cover the principal when a borrower’s collateral ratio falls below LRₜ. The mechanics involve several steps:

  1. Trigger – When CRₜ < LRₜ, the protocol marks the account for liquidation.
  2. Penalty – A penalty is applied to the borrower’s debt. The penalty can be a fixed percentage or a dynamic function of how far the ratio is below LRₜ.
  3. Liquidator Rewards – A liquidator who calls the liquidation function receives a portion of the collateral as a reward.
  4. Covering Debt – The protocol repays the borrower’s debt from the collateral, taking into account the penalty.

Penalty Design

The penalty serves two purposes: it deters risky borrowing and compensates liquidators. Two common penalty structures are:

  • Flat Penalty – A fixed percentage, e.g., 10 %.
  • Progressive Penalty – Increases with the degree of under‑collateralization:
Penalty = p_min + (p_max - p_min) * (1 - CRₜ / LRₜ)

When the ratio is just below LRₜ, the penalty is close to p_min; as the ratio deteriorates, the penalty approaches p_max.

Bonus for Liquidators

Liquidators are incentivized to act quickly. The bonus can be a proportion of the collateral seized, often expressed as a bonus factor:

Bonus = b * SeizedCollateral

where b is a parameter that the protocol’s governance can adjust. A higher bonus encourages faster liquidation, reducing the risk of price slippage for the protocol.

Example Flow

Assume a borrower has borrowed 100 USDC against 200 ETH collateral. The collateral price falls, and the ratio drops to 45 %, below an LRₜ of 50 %. A liquidator calls the contract:

  • Penalty: 15 % of the 100 USDC debt = 15 USDC.
  • Debt Covered: 115 USDC (principal + penalty).
  • Collateral Seized: 115 USDC worth of ETH (≈ 0.575 ETH at the current price).
  • Liquidator Reward: 5 % bonus on 0.575 ETH ≈ 0.02875 ETH.

The remaining collateral is returned to the borrower.

Building the Model

Creating a robust dynamic borrowing model involves translating the above concepts into a coherent system of equations and constraints that a smart contract can enforce. Below is a step‑by‑step guide to building such a model.

Step 1 – Define State Variables

Variable Description
P Principal borrowed
C Collateral token amount
Vₜ Market value of collateral
U Utilization rate
σₜ Volatility of collateral
MRₜ, LRₜ Maintenance and liquidation ratios
APRₜ Annual percentage rate
τ Time elapsed since last update

These variables are stored in the protocol’s storage and updated each block.

Step 2 – Establish Constraints

  1. Collateral Sufficiency

    CRₜ = Vₜ / P  ≥  MRₜ
    
  2. Interest Accrual

    Pₜ₊₁ = Pₜ * (1 + APRₜ * τ / 365)
    
  3. Liquidation Eligibility

    CRₜ < LRₜ  →  eligible for liquidation
    

Step 3 – Implement Interest Accrual

Use a checkpoint pattern: each account records the block number when it last accrued interest. When the user interacts, compute the time delta, calculate the accrued interest, and update P.

accrued = P * APRₜ * (currentBlock - lastCheckpoint) / blocksPerYear
P_new = P + accrued

This approach is gas efficient and scales with many users.

Step 4 – Design the Collateral Ratio Update Function

function updateCollateralRatios() internal {
    σ = getVolatility(collateralToken)
    depth = getDepth(collateralToken)
    MR = MR_base + α * σ + γ * (1 / depth)
    LR = LR_base + β * σ
}

The function is called at the start of each block or before any state change.

Step 5 – Liquidation Procedure

function liquidate(address borrower) external {
    require(CR(borrower) < LR, "Not eligible")
    updateCollateralRatios()
    penalty = computePenalty(borrower)
    debt = principal(borrower) + penalty
    collateralSeized = debt / currentPrice
    reward = collateralSeized * bonusFactor
    transfer(collateralSeized - reward, borrower)
    transfer(reward, liquidator)
    resetBorrowerState(borrower)
}

The function enforces all penalties and rewards automatically.

Step 6 – Governance and Parameter Setting

Parameters such as α, β, γ, MR_base, LR_base, bonusFactor, and p_min/p_max are stored in a governance contract. Token holders can vote to adjust them, ensuring the protocol can adapt to changing market conditions.

Calibration and Validation

A model is only as good as its calibration. Use historical price data and simulated market shocks to test the protocol’s behavior. Key metrics to evaluate:

  • Default Rate – Frequency of liquidations versus user activity.
  • Reserve Coverage – Ratio of available collateral to outstanding debt.
  • Liquidator Incentive – Average reward per liquidation.
  • Borrower Impact – Average penalty paid relative to total debt.

Run Monte‑Carlo simulations that inject random price drops, liquidity shocks, and oracle delays to assess robustness. Adjust sensitivity coefficients until the desired balance of safety and liquidity is achieved.

Practical Example: A Stablecoin Borrowing Protocol

Consider a protocol that allows users to borrow a synthetic stablecoin sUSD by locking up wrapped ETH (wETH) as collateral. The protocol implements the dynamic model described above.

Parameters

  • MR_base = 1.3
  • LR_base = 1.1
  • α = 0.5
  • β = 0.2
  • γ = 0.3
  • APR_base = 3 %
  • p_min = 5 %
  • p_max = 15 %
  • bonusFactor = 0.02

Scenario

  1. A user locks 10 wETH (~ $20,000) to borrow 10 sUSD.
  2. wETH price drops 25 %, reducing the collateral value to $15,000.
  3. Volatility rises, triggering σ to 0.4.
  4. MRₜ increases to 1.3 + 0.5*0.4 = 1.5.
  5. The user’s ratio falls below MRₜ but above LRₜ (1.1 + 0.2*0.4 = 1.18).
  6. The user is flagged for liquidation.
  7. The protocol executes liquidation:
    • Penalty: 5 % of 10 sUSD = 0.5 sUSD.
    • Debt Covered: 10.5 sUSD.
    • Collateral Seized: 10.5 sUSD worth of wETH ≈ 0.52 wETH.
    • Liquidator Reward: 0.02 * 0.52 wETH = 0.0104 wETH.

The borrower receives no collateral back, and the protocol recovers its exposure.

Risk Management Considerations

Dynamic borrowing models expose the protocol to new attack vectors. Key risk areas include:

  • Oracle Manipulation – Sudden price swings can trigger false liquidations.
  • Front‑Running – Liquidators may profit by front‑running price drops.
  • Parameter Abuse – Poorly chosen sensitivity coefficients can over‑penalize or under‑protect users.

Mitigation strategies:

  • Use multiple oracles with median or weighted aggregation.
  • Require a minimum delay between price update and liquidation trigger.
  • Set upper and lower bounds on MR and LR that cannot be exceeded even during extreme volatility.

Conclusion

Dynamic borrowing models elevate DeFi protocols from static lending pools to responsive financial engines that can weather market turbulence. By continuously adjusting collateral ratios, interest rates, and liquidation incentives, these models protect the protocol’s solvency while offering users flexible borrowing terms. Building such a system demands careful mathematical modeling, rigorous simulation, and thoughtful governance. When implemented correctly, the result is a resilient, transparent, and user‑friendly borrowing platform that can thrive in an ever‑evolving blockchain ecosystem.


End of article.

Sofia Renz
Written by

Sofia Renz

Sofia is a blockchain strategist and educator passionate about Web3 transparency. She explores risk frameworks, incentive design, and sustainable yield systems within DeFi. Her writing simplifies deep crypto concepts for readers at every level.

Discussion (8)

MA
Marco 3 months ago
For sure, if you’re going to trust any dynamic model, you better double‑check the assumption that asset prices follow a Brownian motion. That’s never true for crypto. In practice, we need jumps.
AL
Alexander 3 months ago
Agreed, Marco. Jump diffusions would be better. But for a short‑term model, plain BM might pass the backtest.
EL
Elena 3 months ago
Honestly, the article is a bit too theoretical. I’d love to see a concrete implementation in Solidity for how they compute the interest curve. Where’s the repo?
BO
Boris 3 months ago
Elena, maybe the authors are lazy or just keep it closed for now. Or maybe they plan a hackathon.
RI
Rina 3 months ago
The article reminds me of the old V2P projects. They promised dynamic borrowing but failed because of poor risk modelling. Learning from history.
IV
Ivan 2 months ago
This article feels like a textbook. My problem is still liquidity risk when the market goes sideways. They talk about liquidation triggers but ignore how slippage can explode debt ratios.
SO
Sofia 2 months ago
I think they’re onto something. The dynamic borrowing model can reduce capital costs if you’re a vault manager. But again, we need real data to back that claim.
LU
Lucia 2 months ago
Real data? They already used a dataset from 2024. That’s decent. The only thing: how do you handle oracle failure? The paper briefly mentions it but not in depth.
LU
Luca 2 months ago
I think the authors nailed it. The framework for pricing collateral and dynamic borrowing is solid, but they gloss over the stochastic model assumptions. Sure, they mention probability distributions but not how sensitive the model is to parameter shifts. It’s a lot of math for little impact in the real world. Still, good read.
AL
Alex 2 months ago
Luca, chill. We all know that risk aversion is baked in. Maybe the dynamic aspect is more about governance, not the math.
MA
Marin 2 months ago
Yeah, Alex. The real value is in the feedback loops. The model’s 95% confidence intervals are nice, but what about the 99? They skip over that.
MA
Marta 2 months ago
On the other hand, the dynamic borrowing could be the game changer that lets us hedge in real time. Their linear regression approach to collateral valuation can adapt faster than fixed AMM rates.
LY
Lydia 2 months ago
Marta, you are optimistic. Those regression models are usually unstable. Anyone wants to test them under load? The paper doesn’t cover robustness.
AN
Ana 2 months ago
Lydia, it’s just the front‑end. Back‑end is fine. We set the thresholds. Plus the paper uses a rolling window to mitigate shocks.
DA
David 2 months ago
I’m gonna try to implement the core algorithm. Will post a pull request soon. If anyone wants a quick overview, I’ll share minimal code in the comments.
NI
Nicholas 2 months ago
Nice, David. We might need a simulation tool to test your repo. That would clarify assumptions.
DA
David 2 months ago
Will do. Meanwhile, anyone has a dataset for historical collateral ratios? That would be a good start.

Join the Discussion

Contents

David I’m gonna try to implement the core algorithm. Will post a pull request soon. If anyone wants a quick overview, I’ll sha... on Building Dynamic Borrowing Models for De... Aug 12, 2025 |
Marta On the other hand, the dynamic borrowing could be the game changer that lets us hedge in real time. Their linear regress... on Building Dynamic Borrowing Models for De... Aug 07, 2025 |
Luca I think the authors nailed it. The framework for pricing collateral and dynamic borrowing is solid, but they gloss over... on Building Dynamic Borrowing Models for De... Aug 05, 2025 |
Sofia I think they’re onto something. The dynamic borrowing model can reduce capital costs if you’re a vault manager. But agai... on Building Dynamic Borrowing Models for De... Aug 03, 2025 |
Ivan This article feels like a textbook. My problem is still liquidity risk when the market goes sideways. They talk about li... on Building Dynamic Borrowing Models for De... Jul 31, 2025 |
Rina The article reminds me of the old V2P projects. They promised dynamic borrowing but failed because of poor risk modellin... on Building Dynamic Borrowing Models for De... Jul 22, 2025 |
Elena Honestly, the article is a bit too theoretical. I’d love to see a concrete implementation in Solidity for how they compu... on Building Dynamic Borrowing Models for De... Jul 21, 2025 |
Marco For sure, if you’re going to trust any dynamic model, you better double‑check the assumption that asset prices follow a... on Building Dynamic Borrowing Models for De... Jul 18, 2025 |
David I’m gonna try to implement the core algorithm. Will post a pull request soon. If anyone wants a quick overview, I’ll sha... on Building Dynamic Borrowing Models for De... Aug 12, 2025 |
Marta On the other hand, the dynamic borrowing could be the game changer that lets us hedge in real time. Their linear regress... on Building Dynamic Borrowing Models for De... Aug 07, 2025 |
Luca I think the authors nailed it. The framework for pricing collateral and dynamic borrowing is solid, but they gloss over... on Building Dynamic Borrowing Models for De... Aug 05, 2025 |
Sofia I think they’re onto something. The dynamic borrowing model can reduce capital costs if you’re a vault manager. But agai... on Building Dynamic Borrowing Models for De... Aug 03, 2025 |
Ivan This article feels like a textbook. My problem is still liquidity risk when the market goes sideways. They talk about li... on Building Dynamic Borrowing Models for De... Jul 31, 2025 |
Rina The article reminds me of the old V2P projects. They promised dynamic borrowing but failed because of poor risk modellin... on Building Dynamic Borrowing Models for De... Jul 22, 2025 |
Elena Honestly, the article is a bit too theoretical. I’d love to see a concrete implementation in Solidity for how they compu... on Building Dynamic Borrowing Models for De... Jul 21, 2025 |
Marco For sure, if you’re going to trust any dynamic model, you better double‑check the assumption that asset prices follow a... on Building Dynamic Borrowing Models for De... Jul 18, 2025 |