marginfi
Complete guide for Marginfi - Solana's decentralized lending protocol for lending, borrowing, leveraged positions(looping) and flash loans. Covers account creation, deposits, borrows, repayments, withdrawals, flash loans, and leveraged positions using the @mrgnlabs/marginfi-client-v2 SDK.
What this skill does
# 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
```bash
# 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
```bash
# .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.fromSecretKey(/* your secret key */);
const wallet = new NodeWallet(keypair);
// Get production configuration
const config = getConfig("production");
// Load Marginfi client
const client = await MarginfiClient.fetch(config, wallet, connection);
// Access banks
for (const [address, bank] of client.banks) {
console.log(`${bank.tokenSymbol}: ${address}`);
}
```
### Get Bank by Token
```typescript
// Get bank by token symbol
const solBank = client.getBankByTokenSymbol("SOL");
const usdcBank = client.getBankByTokenSymbol("USDC");
// Get bank by mint address
const usdcMint = new PublicKey("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v");
const usdcBankByMint = client.getBankByMint(usdcMint);
// Get bank by public key
const bank = client.getBankByPk(new PublicKey("..."));
```
### Create Account
```typescript
// Create a new Marginfi account
const account = await client.createMarginfiAccount();
console.log("Account address:", account.address.toBase58());
console.log("Authority:", account.authority.toBase58());
```
### Fetch Existing Accounts
```typescript
// Get all accounts for a wallet
const accounts = await client.getMarginfiAccountsForAuthority(wallet.publicKey);
for (const account of accounts) {
console.log("Account:", account.address.toBase58());
console.log("Active balances:", account.activeBalances.length);
// Check positions
for (const balance of account.activeBalances) {
const bank = client.getBankByPk(balance.bankPk);
const quantity = balance.computeQuantityUi(bank!);
console.log(` ${bank?.tokenSymbol}: Assets=${quantity.assets}, Liabilities=${quantity.liabilities}`);
}
}
```
### Deposit Collateral
```typescript
async function deposit(
account: MarginfiAccountWrapper,
client: MarginfiClient,
tokenSymbol: string,
amount: number // UI-denominated amount (tokens, e.g., 1 for 1 SOL)
) {
const bank = client.getBankByTokenSymbol(tokenSymbol);
if (!bank) throw new Error(`Bank ${tokenSymbol} not found`);
// Execute deposit
const signature = await account.deposit(amount, bank.address);
console.log("Deposit signature:", signature);
return signature;
}
// Example: Deposit 1 SOL
await deposit(account, client, "SOL", 1);
```
### Borrow Assets
```typescript
async function borrow(
account: MarginfiAccountWrapper,
client: MarginfiClient,
tokenSymbol: string,
amount: number
) {
const bank = client.getBankByTokenSymbol(tokenSymbol);
if (!bank) throw new Error(`Bank ${tokenSymbol} not found`);
// Execute borrow
const signature = await account.borrow(amount, bank.address);
console.log("Borrow signature:", signature);
return signature;
}
// Example: Borrow 100 USDC
await borrow(account, client, "USDC", 100);
```
### Repay Debt
```typescript
async function repay(
account: MarginfiAccountWrapper,
client: MarginfiClient,
tokenSymbol: string,
amount: number,
repayAll: boolean = false
) {
const bank = client.getBankByTokenSymbol(tokenSymbol);
if (!bank) throw new Error(`Bank ${tokenSymbol} not found`);
// Execute repay
const signature = await account.repay(amount, bank.address, repayAll);
console.log("Repay signature:", signature);
return signature;
}
// Partial repay
await repay(account, client, "USDC", 50);
// Repay all (handles accrued interest)
await repay(account, client, "USDC", 0, true);
```
### Withdraw Collateral
```typescript
async function withdraw(
account: MarginfiAccountWrapper,
client: MarginfiClient,
tokenSymbol: string,
amount: number,
withdrawAll: boolean = false
) {
const bank = client.getBankByTokenSymbol(tokenSymbol);
if (!bank) throw new Error(`Bank ${tokenSymbol} not found`);
// Execute withdraw
const signature = await account.withdraw(amount, bank.address, withdrawAll);
console.log("Withdraw signature:", signature);
return signature;
}
// Partial withdraw
await withdraw(account, client, "SOL", 0.5);
// Withdraw all
await withdraw(account, client, "SOL", 0, true);
```
## Advanced Operations
### Flash Loans
Execute uncollateralized loans that must be repaid within the same transaction:
```typescript
import { TransactionInstruction } from "@solana/web3.js";
async function executeFlashLoan(
account: MarginfiAccountWrapper,
customInstructions: TransactionInstruction[]
) {
// Flash loan allows you to borrow without collateral
// as long as you repay in the same transaction
const signature = await account.flashLoan({
ixs: customInstructions
});
console.log("Flash loan signature:", signature);
return signature;
}
```
### Looping (Leverage)
Deposit and borrow in a single transaction for leveraged positions:
```typescript
import { AddressLookupTableAccount, TransactionInstruction } from "@solana/web3.js";
async function loop(
account: MarginfiAccountWrapper,
client: MarginfiClient,
depositToken: string,
borrowToken: string,
depositAmount: number,
borrowAmount: number,
swapInstructions: TransactionInstruction[],
swapLookupTables: AddressLookupTableAccount[]
) {
const depositBank = client.getBankByTokenSymbol(depositToken);
const borrowBank = client.getBankByTokenSymbol(borrowToken);
if (!depositBank || !borrowBank) {
throw new Error("Bank not found");
}
const signature = await account.loop(
depositAmount,
borrowAmount,
depositBank.address,
borrowBank.address,
swapInstructions,
swapLookupTables
);
console.log("Loop signature:", signature);
return signature;
}
```
### Repay with Collateral
Repay debt using deposited collateral via a swap:
```typescript
async function repayWithCollateral(
account: MarginfiAccountWrapper,
client: MarginfiClient,
repayAmount: number,
withdrawAmount: number,
depositToken: string,
borrowToken: string,
swapInstructions: TransactionInstruction[],
swapLookupTables: AddressLookupTableAccount[]
) {
const depositBank = client.getBankByTokenSymbol(depositToken);
const borrowBank = client.getBankByTokenSymbol(boRelated in Backend & APIs
jfrog
IncludedInteract with the JFrog Platform via the JFrog CLI and REST/GraphQL APIs. Use this skill when the user wants to manage Artifactory repositories, upload or download artifacts, manage builds, configure permissions, manage users and groups, work with access tokens, configure JFrog CLI servers, search artifacts, manage properties, set up replication, manage JFrog Projects, run security audits or scans, look up CVE details, query exposures scan results from JFrog Advanced Security, manage release bundles and lifecycle operations, aggregate or export platform data, or perform any JFrog Platform administration task. Also use when the user mentions jf, jfrog, artifactory, xray, distribution, evidence, apptrust, onemodel, graphql, workers, mission control, curation, advanced security, exposures, or any JFrog product name.
cupynumeric-migration-readiness
IncludedPre-migration readiness assessor for porting NumPy to cuPyNumeric. Use BEFORE substantial porting work begins when the user asks whether code will scale on GPU, whether they should migrate to cuPyNumeric, which NumPy patterns transfer cleanly, what must be refactored before porting, or mentions pre-port assessment, scaling analysis, or refactor planning. Inspect the user's source code, look up NumPy usage, cross-reference the cuPyNumeric API support manifest, and distinguish distributed-scaling-friendly patterns from blockers such as unsupported APIs, scalar synchronization, host round-trips, Python/object-heavy control flow, shape/data-dependent branching, and in-place mutation hazards. Produce a verdict of READY, LIGHT REFACTOR, SIGNIFICANT REFACTOR, or NOT RECOMMENDED, with concrete refactor pointers.
alibabacloud-data-agent-skill
IncludedInvoke Alibaba Cloud Apsara Data Agent for Analytics via CLI to perform natural language-driven data analysis on enterprise databases. Data Agent for Analytics is an intelligent data analysis agent developed by Alibaba Cloud Database team for enterprise users. It automatically completes requirement analysis, data understanding, analysis insights, and report generation based on natural language descriptions. This tool supports: discovering data resources (instances/databases/tables) managed in DMS, initiating query or deep analysis sessions, real-time progress tracking, and retrieving analysis conclusions and generated reports. Use this Skill when users need to query databases, analyze data trends, generate data reports, ask questions in natural language, or mention "Data Agent", "data analysis", "database query", "SQL analysis", "data insights".
token-optimizer
IncludedReduce OpenClaw token usage and API costs through smart model routing, heartbeat optimization, budget tracking, and native 2026.2.15 features (session pruning, bootstrap size limits, cache TTL alignment). Use when token costs are high, API rate limits are being hit, or hosting multiple agents at scale. The 4 executable scripts (context_optimizer, model_router, heartbeat_optimizer, token_tracker) are local-only — no network requests, no subprocess calls, no system modifications. Reference files (PROVIDERS.md, config-patches.json) document optional multi-provider strategies that require external API keys and network access if you choose to use them. See SECURITY.md for full breakdown.
resend-cli
IncludedUse this skill when the task is specifically about operating Resend from an AI agent, terminal session, or CI job via the official resend CLI: installing/authenticating the CLI, sending/listing/updating/cancelling emails, batch sends, domains and DNS, webhooks and local listeners, inbound receiving, contacts, topics, segments, broadcasts, templates, API keys, profiles, or debugging Resend CLI/API failures. Trigger on mentions of Resend CLI, `resend`, `resend doctor`, `resend emails send`, `resend domains`, `resend webhooks listen`, `resend emails receiving`, or agent-friendly terminal automation.
alibabacloud-odps-maxframe-coding
IncludedUse this skill for MaxFrame SDK development and documentation navigation on Alibaba Cloud MaxCompute (ODPS). Helps answer MaxFrame API, concept, official example, and supported pandas API questions; create data processing programs; read/write MaxCompute tables; debug jobs (remote or local); and build custom DPE runtime images. Trigger when users mention MaxFrame, MaxCompute with MaxFrame, ODPS table processing, DPE runtime, MaxFrame docs/examples, DataFrame/Tensor operations, or GPU runtime setup. Works for both English and Chinese queries about Alibaba Cloud data processing with MaxFrame.