Complete guide for Marginfi - Solana's decentralized lending protocol for lending, borrowing, leveraged positions(looping) and flash loans.
Build lending and borrowing applications on Solana with Marginfi - a decentralized, overcollateralized lending protocol offering deposits, borrows, flash loans, and leveraged positions.
Marginfi provides:
# Marginfi client SDK
npm install @mrgnlabs/marginfi-client-v2Common utilities
npm install @mrgnlabs/mrgn-commonRequired peer dependencies
npm install @solana/web3.js @coral-xyz/anchor
# .env file
SOLANA_RPC_URL=https://api.mainnet-beta.solana.com
WALLET_KEYPAIR_PATH=./keypair.json
The SDK enables interaction with Marginfi's lending protocol for deposits, borrows, repayments, withdrawals, and advanced operations.
| 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 |
```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
SOLANA_RPC_URLWALLET_KEYUse this skill
Add this skill to your agent's profile to boost its capabilities and score.
Add to My Agent