Skip to content

Instadapp/fluid-solana-programs

Repository files navigation

Jupiter Lend Solana Program

A two layer modular architecture that enhances capital efficiency, scalability, and risk management.

Table of Contents

Architecture

Jupiter Lend implements a two-layer modular architecture that separates liquidity management from user-facing operations, enabling unified liquidity across multiple protocols.

Architecture Diagram

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                          User Layer                             β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”              β”‚
β”‚  β”‚   Wallets   β”‚  β”‚    dApps    β”‚  β”‚ Liquidators β”‚              β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜              β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
          β”‚                 β”‚                 β”‚
          β–Ό                 β–Ό                 β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                      Protocol Layer                              β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”               β”‚
β”‚  β”‚  Lending Protocolβ”‚         β”‚  Vaults Protocol β”‚               β”‚
β”‚  β”‚                  β”‚         β”‚                  β”‚               β”‚
β”‚  β”‚  β€’ Deposit       β”‚         β”‚  β€’ Operate       β”‚               β”‚
β”‚  β”‚  β€’ Withdraw      β”‚         β”‚  β€’ Liquidate     β”‚               β”‚
β”‚  β”‚  β€’ Rebalance     β”‚         β”‚  β€’ Rebalance     β”‚               β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜               β”‚
β”‚           β”‚         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                         β”‚
β”‚           β”‚         β”‚     CPI Calls (Cross-Program Invocations)  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
            β”‚         β”‚
            β–Ό         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                      Liquidity Layer                                     β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚          Unified Liquidity Pool (Single Orderbook)                 β”‚  β”‚
β”‚  β”‚                                                                    β”‚  β”‚
β”‚  β”‚  β€’ Operate (Supply, Withdraw, Borrow, Payback)                     β”‚  β”‚
β”‚  β”‚  β€’ Unified liquidity management, token limits and rates management.β”‚  β”‚
β”‚  β”‚  β€’ Atomic transaction execution                                    β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
            β–²                              β–²
            β”‚                              β”‚
     β”Œβ”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”
     β”‚   Oracle    β”‚              β”‚   Flash Loan    β”‚
     β”‚   Program   β”‚              β”‚    Program      β”‚
     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Key Benefits

  • Unified Liquidity: All protocols share the same liquidity pool, maximizing capital efficiency and reducing fragmentation
  • Discrete Risk Framework: Each protocol (Lending, Vaults) maintains a distinct set of risk parameters (CF, LT, etc) while leveraging shared liquidity within set limits
  • Modular Design: New protocols can be added without modifying the core liquidity layer

Repository Structure

fluid-contracts-solana/
β”œβ”€β”€ programs/                       # Solana programs
β”‚   β”œβ”€β”€ liquidity/                  # Core liquidity layer
β”‚   β”œβ”€β”€ lending/                    # Lending protocol
β”‚   β”œβ”€β”€ vaults/                     # Collateralized borrow protocol
β”‚   β”œβ”€β”€ oracle/                     # Oracle that utilizes multiple oracles
β”‚   β”œβ”€β”€ flashloan/                  # Flash loan functionality
β”‚   └── lending_reward_rate_model/  # Reward distribution
β”œβ”€β”€ __tests__/                      # Test suite
β”œβ”€β”€ temp/                           # Build artifacts
└── Anchor.toml                     # Anchor configuration

Dependencies

Required

  • Rust - v1.81.0

    curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
    rustup default 1.81.0
  • Solana CLI - v2.1.0

    sh -c "$(curl -sSfL https://release.anza.xyz/v2.1.0/install)"
    
    # Generate keypair
    solana-keygen new
  • Anchor Framework - v0.31.1

    # Install Anchor Version Manager (AVM)
    cargo install --git https://github.com/coral-xyz/anchor avm --locked --force
    
    # Install Anchor
    avm install 0.31.1
    avm use 0.31.1
  • Node.js - For build scripts and testing

    # Verify installation
    node --version
    npm --version
    
    # Install dependencies
    npm install

Quickstart

1. Clone the Repository

git clone https://github.com/fluid-fi/fluid-contracts-solana.git
cd fluid-contracts-solana

2. Install Dependencies

# Install Node.js dependencies
npm install

# Verify toolchain versions
rustc --version    # Should be 1.81.0
solana --version   # Should be 2.1.0
anchor --version   # Should be 0.31.1

3. Build Programs

# Build all programs
anchor build

# Or build specific program
npm run build:liquidity
npm run build:lending
npm run build:vaults

4. Run Tests

# Run all tests
anchor test

# Or test specific program
npm run test:liquidity
npm run test:lending
npm run test:vaults

Program Overview

Liquidity

The Liquidity program serves as the foundational single-pool architecture that manages all liquidity within the system. It tracks the deposit and borrow positions of integrated programs and enforces program-specific borrowing and withdrawal controls, including rate-limited mechanisms such as debt ceilings and withdrawal limits. Access to this program is permission-based, and end users never interact with it directly. Only whitelisted programs, such as Vaults and Lending, can interact with it through CPIs. All other programs in the ecosystem are built on top of this liquidity infrastructure.

Key Method

  • Operate: The core interaction method that handles all liquidity operations (supply, withdraw, borrow, payback) in a single atomic transaction.

Lending

The Lending program provides a straightforward lending protocol that offers users direct exposure to yield generation. Users can supply assets to earn interest, making it the core yield-bearing mechanism within the protocol suite.

Key Methods:

  • Deposit: Allows users to supply assets into the protocol
  • Withdraw: Enables users to withdraw their supplied assets
  • Rebalance: Synchronizes the protocol's accounting with its actual position on the Liquidity layer, ensuring accurate asset tracking and exchange rates. When rewards are active, rebalance syncs the orderbook to incorporate accrued rewards

Vaults

The Vaults program implements a collateralized debt position (CDP) system. Users deposit collateral assets to borrow debt tokens against them, enabling leverage and capital efficiency. This program handles collateral management, debt issuance, and liquidation mechanisms through a tick-based architecture for efficient risk management.

Key Methods:

  • Operate: Manages collateral and debt positions by interacting with the Liquidity layer, handling deposits, withdrawals, borrows, and paybacks
  • Liquidate: Allows liquidators to repay debt on behalf of risky positions in exchange for collateral at a discount (liquidation penalty). Positions become liquidatable when they exceed the liquidation threshold (e.g., 90% LT). The liquidation mechanism operates on a tick-based system, where positions are liquidated based on their risk level. Positions with ratio above the liquidation max limit (e.g., 95% LML) is automatically absorbed by the protocol
  • Rebalance: Reconciles vault positions with the underlying Liquidity layer to maintain accurate collateral and debt accounting. When rewards are active on the protocol, rebalance syncs the orderbook to account for accrued rewards

Oracle

The Oracle program provides reliable price feeds for the protocol. It supports data sources from multiple providers including Pyth, Chainlink, and Solana-native pools to ensure accurate asset pricing.

Flash Loan

The Flash Loan program provides atomic loans that must be borrowed and repaid within a same transaction. This enables arbitrage, liquidations, and other advanced DeFi operations without requiring upfront capital.

Lending Reward Rate Model

The Lending Reward Rate Model program manages the calculation and distribution of rewards for the Lending protocol, determining reward rates based on protocol parameters and market conditions.

Mainnet Deployments

The following programs are currently deployed on Solana mainnet:

Program Program ID
Liquidity jupeiUmn818Jg1ekPURTpr4mFo29p46vygyykFJ3wZC
Lending jup3YeL8QhtSx1e253b2FDvsMNC87fDrgQZivbrndc9
Lending Reward Rate Model jup7TthsMgcR9Y3L277b8Eo9uboVSmu1utkuXHNUKar
Vaults jupr81YtYssSyPt8jbnGuiWon5f6x9TcDEFxYe3Bdzi
Oracle jupnw4B6Eqs7ft6rxpzYLJZYSnrpRgPcr589n5Kv4oc
Flashloan jupgfSgfuAXv4B6R2Uxu85Z1qdzgju79s6MfZekN6XS

Authority Structure

The protocol implements a multi-tiered authority system with distinct permissions for enhanced security.

Upgrade Authority

  • Purpose: Controls program upgrades on the Solana network.

  • Governance: Managed through a 12-hour timelock multisig wallet jointly controlled by Jupiter and Fluid team signers.

  • Address: 4MsgBB5VPoTrUSp5XnfbViV386C1UnsTdifLBw33ZMSJ

Program Authority

  • Purpose: Manages protocol configuration including rate curves, loan-to-value (LTV) ratios, operational limits, and authority delegation.

  • Governance: Jointly controlled by Jupiter and Fluid team signers.

  • Address: HqPrpa4ESBDnRHRWaiYtjv4xe93wvCS9NNZtDwR89cVa

Init Authority

  • Purpose: Handles initialization operations across all protocol programs, including:

    • Liquidity: Initialize new token reserves and protocol positions
    • Lending: Initialize new lending markets and fToken mints
    • Vaults: Initialize vault configurations and vault states
    • Lending Reward Rate Model: Initialize reward rate models

    This authority is limited to initialization only, without configuration modification privileges e.g., setting limits or change configs.

  • Governance: Controlled by the Fluid team.

  • Address: 3H8C6yYTXUcN9RRRDmcLDt3e4aZLYRRX4x2HbEjTqQAA

Security

  • Audit Reports: Jupiter Documentation
  • Bug Bounty: Contact [email protected] for responsible disclosure
  • Security Best Practices: All programs undergo rigorous testing and multiple security audits before deployment

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published