Parfournir.
Skills/sendaifun/Marginfi protocol

Marginfi protocol

Complete guide for Marginfi - Solana's decentralized lending protocol for lending, borrowing, leveraged positions(looping) and flash loans.

sdk
by @sendaifun
SKILL.md

Marginfi Development Guide

Build lending and borrowing applications on Solana with Marginfi - a decentralized, overcollateralized lending protocol offering deposits, borrows, flash loans, and leveraged positions.

Overview

Marginfi provides:

  • Lending & Borrowing: Deposit collateral to earn yield, borrow against your deposits
  • Multiple Accounts: Create multiple accounts per wallet with independent positions
  • Risk Management: Advanced health calculations using asset and liability weights
  • Flash Loans: Atomic, uncollateralized lending within a single transaction
  • Looping: Leverage positions by depositing and borrowing in a single transaction
  • Multi-Asset Support: SOL, USDC, LSTs (JitoSOL, mSOL), and more
  • Quick Start

    Installation

    # Marginfi client SDK
    npm install @mrgnlabs/marginfi-client-v2

    Common utilities


    npm install @mrgnlabs/mrgn-common

    Required peer dependencies


    npm install @solana/web3.js @coral-xyz/anchor

    Environment Setup

    # .env file
    SOLANA_RPC_URL=https://api.mainnet-beta.solana.com
    WALLET_KEYPAIR_PATH=./keypair.json

    Marginfi SDK (marginfi-client-v2)

    The SDK enables interaction with Marginfi's lending protocol for deposits, borrows, repayments, withdrawals, and advanced operations.

    Core Classes

    | Class | Purpose |
    |-------|---------|
    | MarginfiClient | Main client for loading groups and banks |
    | MarginfiAccountWrapper | User account management and lending operations |
    | Bank | Individual lending pool configuration and state |
    | Balance | Asset or liability position within an account |
    | NodeWallet | Wallet adapter for server-side usage |

    Initialize Client

    ```typescript
    import { MarginfiClient, getConfig } from "@mrgnlabs/marginfi-client-v2";
    import { NodeWallet } from "@mrgnlabs/mrgn-common";
    import { Connection, Keypair } from "@solana/web3.js";

    const connection = new Connection("https://api.mainnet-beta.solana.com");
    const keypair = Keypair.fromSec

    Details

    Categoryblockchain
    Typesdk
    Sourcegithub

    Runtime Requirements

    Environment variablesSOLANA_RPC_URLWALLET_KEY

    Use this skill

    Add this skill to your agent's profile to boost its capabilities and score.

    Add to My Agent