DEFI FINANCIAL MATHEMATICS AND MODELING

On Chain Performance Indicators for DeFi Protocols and User Groups

8 min read
#On-Chain Metrics #Blockchain Data #DeFi Performance #Protocol Analytics #User Segmentation
On Chain Performance Indicators for DeFi Protocols and User Groups

Introduction

Decentralized finance (DeFi) has moved beyond simple token swaps to become an ecosystem of complex protocols that offer lending, borrowing, staking, and insurance.
Because DeFi is built on public blockchains, every interaction is recorded on‑chain. This transparency turns the protocol and its users into a rich data source that can be mined for insights advanced DeFi analytics.
On‑chain performance indicators (OPIs) quantify how well a protocol operates and how its users behave. By examining these metrics, investors, developers, auditors, and regulators can assess risk, spot trends, and drive product improvements.
This article introduces the core OPIs for both protocols and user groups, explains how to compute them, and shows how cohort analysis can turn raw numbers into actionable knowledge.


Protocol‑Level Indicators

Indicator Why it matters Typical calculation
Total Value Locked (TVL) Measures overall capital commitment; proxy for trust and liquidity Sum of all assets deposited in the protocol, converted to USD or native token price
Liquidity Determines slippage and capacity for large trades Total token reserves available for instant swaps or withdrawals
Borrow‑to‑Deposit Ratio (BDR) Indicates leverage risk Total borrowed value ÷ Total deposited value
Net Protocol Revenue (NPR) Shows profitability Interest earned + protocol fees – any payouts or losses
Annual Percentage Yield (APY) Reward attractiveness for liquidity providers (Total rewards earned ÷ Capital locked) × 100
Slippage Reflects market efficiency Ratio of price impact to trade size
Impermanent Loss (IL) Risk for liquidity providers Difference between the value of the LP’s holdings after a price move and the value if the funds were held separately
Gas Cost per Transaction Operating expense and incentive alignment Total gas spent ÷ number of transactions
Daily Active Protocol Addresses (DAPAs) Gauges network activity Count of distinct addresses interacting with the protocol per day
Protocol Upgrade Frequency Signals governance agility Number of code deployments over a period

These metrics give a snapshot of a protocol’s financial health, user engagement, and technical efficiency. They are usually reported in dashboards such as DeFiLlama, Dune Analytics, or custom GraphQL endpoints.


User‑Group Indicators

User behavior in DeFi can be segmented into functional cohorts—depositors, borrowers, liquidity providers, and traders behavioral segmentation. Each group exhibits distinct on‑chain patterns.

Cohort Key metrics What they reveal
Depositors Average deposit size, frequency of deposits, duration of holdings Risk appetite, liquidity supply trends
Borrowers Average loan size, loan term, LTV ratio, default rate Leverage usage, credit risk
Liquidity Providers (LPs) Average LP fee earned, IL, time in pool Provider satisfaction, pool health
Traders Trade volume, trade frequency, average trade size, slippage Market depth, volatility
DApp Users Number of interactions per day, session length Adoption, feature usage

Aggregating these metrics allows protocol operators to target incentives, adjust fee structures, or identify emerging user segments.


Cohort Analysis

Cohort analysis dissects user behavior over time by grouping users based on a common attribute, such as the block in which they first interacted with the protocol or the token they first deposited.
Typical cohort steps:

  1. Define Cohort Criteria – e.g., users who made their first deposit in a given month.
  2. Track Metrics Over Time – measure retention, lifetime value, or churn at monthly intervals.
  3. Compare Across Cohorts – identify whether changes in incentives, upgrades, or market conditions influence user behavior.

Example: Loyalty of Liquidity Providers

Suppose a protocol introduces a new reward program in January. By creating a cohort of LPs who joined before January and another cohort that joined afterward, you can calculate:

  • Retention Rate: % of LPs who remain active after 3, 6, 12 months.
  • Average IL: Compare IL for the two cohorts to see if the new rewards mitigate impermanent loss.
  • Fee Earned per LP: Determine if the incentive improves overall profitability.

The resulting insight might be that early LPs show higher retention, implying that onboarding processes and community support are critical.


Data Sources and Retrieval

On‑chain data is publicly available, but extracting meaningful metrics requires efficient querying:

Source Access Method Strengths
Etherscan API REST Simple, comprehensive
Covalent GraphQL Multi‑chain, rich metadata
The Graph (Subgraphs) GraphQL Real‑time, indexed
Dune Analytics SQL Powerful aggregation
Alchemy, Infura Web3 Providers Full node access

When designing a data pipeline, consider:

  • Batch vs. Streaming: Batch processing is easier for periodic reports; streaming is better for real‑time dashboards.
  • Caching: Reuse query results for high‑frequency metrics to reduce RPC load.
  • Normalization: Convert all token amounts to a common unit (e.g., wei to ETH, then to USD) to avoid inconsistent reporting.

Calculating Core Metrics

TVL

def calculate_tvl(token_balances, token_prices):
    tvl = 0
    for token, balance in token_balances.items():
        tvl += balance * token_prices[token]
    return tvl

BDR

bdr = total_borrowed_value / total_deposited_value

APY for Liquidity Providers

apy = (rewards_earned / capital_locked) * 100

Impermanent Loss (Simplified)

def impermanent_loss(price_initial, price_final, ratio_initial, ratio_final):
    value_initial = (price_initial * ratio_initial) + (price_initial / ratio_initial)
    value_final = (price_final * ratio_final) + (price_final / ratio_final)
    il = (value_initial - value_final) / value_initial
    return il

Gas Cost per Transaction

gas_cost = total_gas_used * gas_price
cost_per_tx = gas_cost / number_of_transactions

Use Cases

Risk Management

  • Liquidity Shortfall Alerts: Monitor liquidity and slippage to trigger margin calls for traders.
  • Borrowing Heat Map: High BDR and LTV combinations flag potential default risk. For deeper risk quantification, see our work on quantifying DeFi risk.

Product Development

  • Fee Structure Optimization: Compare APY vs. slippage across fee tiers to find equilibrium.
  • Feature Adoption: Track interaction counts of new protocol features over time.

Governance

  • Voting Participation: Measure DAPAs to assess community engagement before proposals.
  • Revenue Distribution: Use NPR to decide on treasury allocations.

Marketing

  • Targeted Incentives: Identify under‑represented user cohorts and tailor rewards.
  • Referral Tracking: Use on‑chain addresses to validate referral claims.

Tools and Platforms

Tool Purpose Highlights
The Graph Indexes on‑chain events Fast, decentralized, open subgraphs
Dune Analytics Custom SQL dashboards Community‑shared templates
Nansen Address tagging & analytics Labelled user accounts
Alchemix Automated data retrieval Custom scripts for daily reports
Chainalysis Compliance & KYC Transaction flow analysis

Combining these tools can deliver end‑to‑end pipelines from raw blocks to interactive dashboards, and the mathematical underpinning of liquidity can be expanded through "modeling liquidity pools with mathematical metrics and on chain signals".


Challenges and Mitigation

Challenge Impact Mitigation
Data Quality Inconsistent event logs, missing metadata Use multiple sources, cross‑validate
Gas Fees Expensive queries on high‑traffic chains Cache, batch requests, use subgraphs
Chain Fragmentation Data spread across EVM and non‑EVM chains Standardize APIs, use cross‑chain aggregators
Privacy Anonymous addresses hinder user profiling Combine on‑chain with off‑chain data (e.g., KYC where available)
Rapid Evolution Protocol upgrades change event signatures Maintain subgraph migrations, version control

Addressing these issues early prevents data drift and analytical inaccuracies.


Best Practices

  1. Normalize Units – Always convert token amounts to a single base unit (e.g., wei) before aggregation.
  2. Timestamp Consistency – Use block timestamps in UTC; avoid local time conversions.
  3. Version Control – Keep scripts and queries under Git to track changes with protocol upgrades.
  4. Metric Documentation – Maintain a living glossary of indicators, formulas, and data sources.
  5. Data Governance – Define data ownership and privacy policies, especially when merging on‑chain with off‑chain data.
  6. Automation – Schedule nightly ETL jobs; use CI/CD pipelines for deployments.

Visual Insight

After establishing the cohort framework, a visual dashboard can quickly reveal patterns. For example:

  • A line chart showing retention of LPs over 12 months for each cohort.
  • A heat map of TVL growth by month.
  • A scatter plot of APY vs. IL for different liquidity pools.

These visualizations turn raw numbers into strategic insights that drive decision‑making.


Conclusion

On‑chain performance indicators provide a quantitative lens through which to evaluate DeFi protocols and their user groups. By dissecting metrics like TVL, APY, IL, and cohort‑specific behaviors, stakeholders can:

  • Quantify risk and reward in real time.
  • Identify high‑value user segments for targeted incentives.
  • Adjust protocol parameters to balance liquidity, yield, and safety.
  • Make data‑driven governance decisions.

The richness of on‑chain data, when combined with rigorous methodology and advanced analytics, turns a permissionless ecosystem into a measurable, optimizable environment. As DeFi continues to mature, mastering these indicators will become essential for developers, investors, auditors, and regulators alike.

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.

Contents