Solana DeFi Lending Protocol Development by mudam abhilashSolana DeFi Lending Protocol Development by mudam abhilash

Solana DeFi Lending Protocol Development

mudam  abhilash

mudam abhilash

Solana DeFi Lending Protocol

This is a production-grade, decentralized lending protocol built on the Solana blockchain using the Anchor framework. The protocol allows users to deposit SPL tokens as collateral, borrow against them, and earn interest, while also providing a mechanism for third-party liquidators to maintain the health of the system.

Features

This smart contract includes a full suite of features for both users and administrators, designed with security and scalability in mind.

User-Facing Features

Deposit: Users can deposit SPL tokens into a secure vault to be used as collateral.
Withdraw: Users can withdraw their deposited collateral, provided it doesn't leave their loan in an unhealthy state.
Borrow: Users can borrow SPL tokens against their collateral, up to a specific Loan-To-Value (LTV) ratio.
Repay: Users can repay their outstanding loans at any time.
Interest Accrual: A simple APR model is implemented to automatically accrue interest on both deposits and borrows.

Protocol & Security Features

Liquidations: A public liquidate function allows anyone to repay the debt of an unhealthy loan (below the liquidation threshold) in exchange for the borrower's collateral at a bonus/discount.
Oracle Integration: Utilizes the Pyth Network oracle to fetch real-time asset prices, ensuring accurate valuation for borrowing and liquidations.
Administrative Controls: A designated authority can manage critical bank parameters, transfer ownership, and pause the protocol.
Circuit Breaker: The protocol can be paused by the authority, immediately halting all major functions (deposit, withdraw, borrow, repay) to protect user funds in an emergency.
On-Chain Events: Emits events for major actions (DepositEvent, BorrowEvent, etc.), allowing off-chain services and UIs to easily track protocol activity in real-time.

Core Accounts

The protocol's state is managed through two primary account types:

Bank Account

This is a singleton account that stores the global configuration and state for a single lending market.
authority: The admin wallet that can change parameters.
token_mint & token_vault: The SPL token being lent and the PDA vault that holds it.
pyth_price_feed: The address of the Pyth oracle price feed for the token.
total_deposits & total_borrows: Protocol-wide accounting.
*_interest_rate: The APR for deposits and borrows.
loan_to_value_ratio: The percentage of collateral value a user can borrow against (e.g., 70%).
liquidation_threshold: The LTV percentage at which a loan is considered unhealthy and can be liquidated (e.g., 80%).
liquidation_bonus: The percentage bonus given to liquidators.
paused: The circuit breaker flag.

User Account

This is a PDA created for each unique user, tracking their personal position within the protocol.
owner: The user's public key.
deposit_balance: The user's total collateral deposited.
borrow_balance: The user's total outstanding debt.

Getting Started

Prerequisites

Rust
Solana Tool Suite
Anchor Framework

Build

To build the smart contract, navigate to the programs/lending-protocol/ directory and run:
anchor build

Test

To run the automated tests for the smart contract, use:
anchor test

Security Notes

This protocol uses on-chain price oracles (Pyth) — ensure price feeds are valid for your deployment.
The authority role has powerful controls; secure the authority key and consider multisig for production.
Always test thoroughly on devnet/testnet before mainnet deployment.
Like this project

Posted Dec 22, 2025

Developed a decentralized lending protocol on Solana using Anchor framework.