ORACLE FOR BORROW/LENDING

Building
Decentralized Lending

This guide covers the different types of borrow/lending services, the nuances of different interest rate models, and how borrow/lending platforms use oracle prices.

What is Borrow/Lending?

Borrowing and lending (or ''borrow/lending'') refers to one of the most popular primitives in decentralized finance. Borrow/lending services enables individuals to lend out their assets and earn interest or borrow assets by providing collateral.

Borrow/lending is an important primitive for decentralized finance as it enables capital efficiency by making idle assets productive and efficient price discovery by allowing users to access liquidity to capitalize on market or arbitrage opportunities.

Borrowing and Lending in Practice

In the borrowing process, users lock up collateral (usually in the form of cryptocurrencies or tokens) into a smart contract. By posting collateral, they can borrow other assets up to a certain value based on the collateral's market worth and the contract's predefined parameters.

On the lending side, users can participate as lenders by depositing their assets into a lending pool managed by a smart contract. These assets are then available for borrowers to use as collateral for their loans.

By borrowing assets, users gain exposure to various digital assets without needing to own them outright. Conversely, lenders have the opportunity to earn interest by lending out their assets to borrowers.

Borrow/lending protocols in DeFi require real-time oracle data to determine the price of assets used as collateral, calculate interest rates, and trigger liquidations when necessary to preserve the 'health' or solvency of the protocol.

You can start building decentralized lending and start requesting oracle price updates right away with Pyth Price Feeds.

Explore our docs to get started.

Borrow/Lending:
How Does It Work?

Borrowing and lending in DeFi involve users locking up cryptocurrency collateral to obtain loans or provide loans, with smart contracts automating interest calculation, repayment enforcement, and collateral management.

Loan Origination

Loan origination refers to the process of creating a new loan within a lending protocol. When a borrower wants to borrow cryptocurrency assets, they interact with the protocol's smart contract to initiate the loan. The smart contract calculates the maximum amount the borrower can borrow based on the value of the collateral they provide.

Collateralization System

Lending platforms need to protect lenders from bad debt. For this reason, a collateralization mechanism is essential for managing risk. A collateralization ratio dictates how much they can borrow. Borrowers must maintain a sufficient collateral-to-loan ratio to avoid liquidation by providing collateral worth more than the borrowed amount.

This collateral acts as a safeguard for lenders, mitigating the risk of default. Margin requirement varies based on the platform and asset involved. Higher volatility assets often necessitate higher margin requirements to account for potential price fluctuations.

Interest Calculation

Interest calculation involves determining the amount of interest that borrowers need to repay on their borrowed funds. The interest rate is usually specified when the loan is originated. The smart contract calculates the interest amount based on the borrowed principal and the interest rate over the loan term.

Liquidation Mechanism

If the value of the collateral falls below a specified threshold, the smart contract can automatically liquidate the borrower's position to protect the lender's funds. To maintain the collateral's value relative to the borrowed asset, decentralized lending platforms implement mechanisms for monitoring loan-to-value (LTV) ratios.

Liquidations are integral to preserving the stability of decentralized lending platforms. When a borrower's collateral value breaches the predetermined LTV ratio, the platform may initiate liquidation by auctioning the borrower's collateral. This allows lenders to recover their funds while minimizing losses. Lenders or arbitrageurs can participate in these auctions and bid on the collateral using platform-native tokens.

Some platforms implement incentivized mechanisms to encourage users to monitor and initiate liquidations when necessary. These users can earn rewards for maintaining the health of the platform and ensuring adequate collateralization.

Interest Rates Models

Borrowers typically pay interest on their loans, which is distributed as earnings to the lenders in the lending pool. The interest rates are dynamically determined by supply and demand dynamics within the lending platform. This section explores the most common models.

Algorithmic Model

Algorithmic interest rates are determined by automated algorithms based on the supply and demand dynamics of the platform. These algorithms take into account factors such as the utilization rate of assets, available liquidity, and market conditions to adjust interest rates dynamically. Algorithmic interest rates aim to maintain balance and stability within the lending and borrowing market.

Order Book Model

Order books match bid and ask orders according to price-time priority and can facilitate the determination of interest rates for borrow/lending transactions. Similar to traditional financial markets, borrowers and lenders submit their desired borrowing or lending terms, such as the desired interest rate and loan duration, to an order book. The matching of borrowers and lenders occurs based on these submitted orders, with interest rates being determined through the interaction of supply and demand.

Governance-Based

Governance-determined rates determine interest rates through decentralized governance mechanisms. Users who hold governance tokens can participate in voting or decision-making processes to set or adjust interest rates. This approach allows the community to collectively determine the rates based on factors such as platform sustainability, market conditions, and user sentiment.

Fixed (Stable) Rates

Fixed or stable rates are often predetermined or pegged to external reference rates. These rates remain constant over a specified period, providing borrowers and lenders with predictability and stability in terms of interest payments and earnings.

Dynamic Rates

Dynamic pricing models for interest rates consider a range of factors such as asset volatility, risk profiles, and supply-demand dynamics. These models determine interest rates based on factors such as asset volatility, liquidity metrics, risk assessment, real-time market data such as trading volume. The calculated interest rate changes according to market conditions and platform parameters.

Shared Pools and Isolated Pools

Borrow/lending protocols can adopt different pool models based on their risk management objectives.

Isolated Pools

In an isolated pool model, each user's collateral and borrowing position are managed separately, creating individualized and isolated pools of assets. The collateral and borrowing of one user do not affect or interact with the collateral and borrowing of other platform users.

Shared Pools

In a shared pool or communal pool model, the collateral and borrowing positions are pooled together, creating a shared pool of assets. In this model, all users' collateral and borrowing interact with each other within the same pool: the assets contributed as collateral by different users are combined, and the borrowing needs of users are fulfilled from the shared pool of assets.

By using a shared pool model, borrow/lending protocols can enhance liquidity, optimize capital utilization, and create potential economies of scale. This model allows for more efficient allocation of assets and a larger pool of available liquidity. However, it also introduces potential risks and complexities related to the shared exposure and interactions among users' positions.

Borrow/Lending Models

There are different categories of DeFi borrow/lending services which generally vary based on the source of yield and how interest rates are calculated.

Money Markets

Money market protocols enable users to lend and borrow various assets by creating liquidity pools on-chain. These platforms allow borrowers to collateralize their assets and borrow other assets from the pool, while lenders supply liquidity by depositing their assets into the pool and earning interest.

Peer-to-Peer (P2P)

Peer-to-peer lending platforms facilitate direct borrowing and lending between individuals. These platforms connect borrowers and lenders, allowing them to negotiate terms such as interest rates, collateral requirements, and loan durations without intermediaries.

Yield Farming

Yield farming platforms provide opportunities for users to earn additional yields by leveraging their existing assets for DeFi activities. Users can deposit their assets into liquidity pools or yield farming protocols, where they are utilized for yield-bearing activities such as providing liquidity or participating in governance. In return, users receive additional rewards for their deposits.

Flash Loans

Flash loan platforms enable users to borrow funds temporarily without collateral, as long as the loan is repaid within the same transaction block. The flexibility of flash loans allow users to exploit arbitrage opportunities or execute complex trading strategies.

Synthetic Borrow/Lending

Synthetic asset platforms offer the ability to create and trade synthetic assets that mirror the value of real-world assets. Users can borrow and lend these synthetic assets, allowing them to gain exposure to traditional financial instruments or unique assets within the DeFi ecosystem.

How Borrow/Lending Services
Use Oracles

This section explores how decentralized borrow/lending protocols rely on price oracles to obtain real-time and accurate price information for the assets involved in lending transactions.

Collateral Valuation

Loan-to-value (LTV) ratios represent the proportion of the loan amount to the value of the collateral provided. Price oracles provide real-time asset prices, which are essential for determining the collateral's value accurately. Borrow/lending protocols utilize these price feeds to calculate the LTV ratio by dividing the loan amount by the current market value of the collateral. This calculation ensures that borrowers maintain sufficient collateralization throughout the loan term.

Liquidation Triggers

Decentralized borrow/lending protocols typically set a predetermined threshold for the LTV ratio. If the LTV ratio exceeds this threshold, indicating a potential risk of default, the protocol triggers a liquidation process. Price oracles play a crucial role in determining when the collateral value falls below the threshold by providing updated asset prices. Once triggered, the protocol initiates the liquidation by auctioning off the collateral to recover the lender's funds.

Interest Rate Determination

Price oracles supply accurate and real-time asset prices that borrow/lending protocols incorporate into their interest rate models. These models consider supply and demand dynamics, asset volatility, and other factors to dynamically adjust interest rates. Price oracles ensure that the protocols have reliable, up-to-date market data to calculate interest rates that accurately reflect the prevailing market conditions. This helps create fair and competitive rates that attract borrowers and incentivize lenders to participate.

Collateral Swaps and Rebalancing

Some borrow/lending protocols allow users to swap or rebalance their collateral during the loan term. Price oracles provide real-time asset prices that enable users to make informed decisions about collateral swaps, ensuring fair exchange rates and adequate collateralization throughout the process. Access to real-time and trustless price data is critical for all of these operations. The accuracy, granularity, and latency of oracle prices are paramount for protocol security, as inaccurate pricing can cause bad debt or wrongful liquidations.

Oracles like Pyth specialize in low-latency price feeds which aggregate across multiple exchanges and liquidity venues to provide a price output reflective of the overall market.

Pyth is also the only oracle which provides confidence intervals, or confidence bands around the reported price which reflect the level of price divergence and volatility across the markets. A wider confidence band (e.g. BTC/USD at $30,000 ± $100 instead of ± $10) indicates greater divergence or “uncertainty” between venues. Borrow/lending platforms can use this confidence data to inform their on-chain operations and adjust protocol parameters to protect users and funds.

Borrow/Lending Glossary

This glossary defines the most common terms in the DeFi borrowing and lending landscape.

Annual Percentage Rate (APR)

The annual interest rate charged on borrowed assets, representing the cost of borrowing.

Borrowing Limit

The maximum amount a borrower can borrow based on their collateral value and the protocol's parameters.

Collateral

Assets provided by borrowers as security for obtaining loans on the platform.

Collateralization Ratio

The ratio of the borrowed amount to the value of the collateral, determining the level of risk for lenders.

Debt Service Coverage Ratio (DSCR)

A measure of a borrower's ability to cover their debt payments, indicating creditworthiness.

Flash Loan

A type of short-term, uncollateralized loan that must be repaid within the same transaction block.

Interest Rate

The percentage charged on borrowed assets, determining the cost of borrowing or the return on lending.

Leverage

The ability to amplify potential returns or losses by borrowing funds to increase the exposure to an asset.

Liquidation

The process of selling collateral to repay a loan when its value falls below the required maintenance level.

Loan-to-Value (LTV) Ratio

The ratio of the loan amount to the value of the collateral, determining the risk for both borrowers and lenders.

Overcollateralization

Requiring borrowers to provide collateral worth more than the borrowed amount to reduce default risks.

Peer-to-Peer (P2P) Lending

Direct lending between individuals on the platform, eliminating intermediaries.

Undercollateralized Loan

Loans where the value of collateral is slightly lower than the borrowed amount, increasing risk.

Yield Farming

A strategy where users earn rewards by providing liquidity to lending protocols.

Discover More Guides

Our guides cover popular DeFi solutions and how developers can leverage price oracles to create a unique, compelling product.

Lending

Borrowing and Lending

DEXs

Perpetual Futures

Derivatives

Options and Structured Product Vaults

Stablecoins

Stablecoins

integratingbg

Integrate Seamlessly

Pyth’s comprehensive suite of APIs solves all your financial data needs. Access to Pyth prices is permissionless and easy—no subscription necessary.

Developers can get started with our documentation, integration resources, and best practice guides. Watch along to learn how Pyth can super-charge your decentralized app.