in-solana by Supanode

marginfi — Program ID & Overview

MFv2hWf31Z9kbCa1snEPYctwafyhdvnV7FZnsebVacA

marginfi is a lending and borrowing protocol on Solana. Users deposit assets to earn yield and borrow against their collateral. marginfi uses a risk-tiered system to manage protocol solvency.

Program ID

MFv2hWf31Z9kbCa1snEPYctwafyhdvnV7FZnsebVacA

Architecture

AccountDescription
MarginfiGroupGlobal configuration for a lending group
BankIndividual asset reserve (SOL bank, USDC bank, etc.)
MarginfiAccountUser’s account holding deposits and borrows

Risk tiers

marginfi classifies assets into risk tiers that determine how they interact:

TierDescription
CollateralCan be used as collateral for borrows
IsolatedCan only be borrowed in isolation (no mixing with other borrows)
VolatileHigher-risk assets with lower LTV

Key instructions

InstructionDescription
MarginfiAccountInitializeCreates a user account
LendingAccountDepositDeposits tokens into a bank
LendingAccountBorrowBorrows tokens against collateral
LendingAccountRepayRepays borrowed tokens
LendingAccountWithdrawWithdraws deposited tokens
LendingAccountLiquidateLiquidates an unhealthy account

Interest rate model

marginfi uses a piecewise linear interest rate curve:

Rate
  ↑
  |                    ╱
  |                  ╱
  |                ╱  ← kink point
  |          ────╱
  |     ────
  |────
  └──────────────────→ Utilization %

Below the optimal utilization (kink), rates increase slowly. Above it, rates increase sharply to incentivize repayment and new deposits.

Using the SDK

import { MarginfiClient, getConfig } from "@mrgnlabs/marginfi-client-v2";

const config = getConfig("production");
const client = await MarginfiClient.fetch(config, wallet, connection);

const account = await client.createMarginfiAccount();
const banks = client.banks;

// Deposit SOL
const solBank = [...banks.values()].find(b => b.label === "SOL");
await account.deposit(1_000_000_000, solBank.address); // 1 SOL

FAQ

What happens during a liquidation? When an account’s health factor drops below 1 (borrows exceed collateral × LTV), liquidators can repay a portion of the debt and receive the equivalent collateral plus a liquidation bonus. Liquidations are partial to minimize market impact.

How are interest rates determined? Rates are set by the utilization curve parameters: base rate, optimal utilization, and the rate at optimal and maximum utilization. Each bank (asset) has its own rate parameters.

Can I flash borrow on marginfi? marginfi supports flash loans where you borrow and repay within the same transaction. This is used for liquidations, leveraged strategies, and arbitrage.

Updated: