marginfi

Implement lending, borrowing, flash loans, and leveraged positions on Marginfi via its TypeScript SDK.

6|20|Updated Mar 14, 2026
One-click install
npx skills add https://github.com/andresdefi/cryptoskills --skill marginfi-andresdefi
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: marginfi
Source: https://github.com/andresdefi/cryptoskills/tree/main/skills/marginfi
Command: npx skills add https://github.com/andresdefi/cryptoskills --skill marginfi-andresdefi

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires @mrgnlabs/marginfi-client-v2, @mrgnlabs/mrgn-common, @solana/web3.js, @coral-xyz/anchor, decimal.js.

What problem does it solve? AI agents and developers often lack accurate, up-to-date knowledge of the Marginfi protocol on Solana, leading to hallucinated program addresses, outdated SDK patterns, and incorrect health or interest calculations when building lending and borrowing applications. ## Core Features & Use Cases - Lending & Borrowing Operations: Create Marginfi accounts, deposit collateral, borrow assets, repay debt, and withdraw funds using the @mrgnlabs/marginfi-client-v2 SDK. - Advanced DeFi Primitives: Execute flash loans, leveraged looping positions, and repay-with-collateral swaps in single atomic transactions. - Risk & Account Monitoring: Compute health components, free collateral, interest rates, utilization, and portfolio values with correct oracle price handling. - Use Case: Build a bot that deposits SOL as collateral, borrows USDC against it with a safety buffer, monitors maintenance health, and repays the full debt including accrued interest. ## Quick Start Ask the agent to create a Marginfi account and deposit 1 SOL as collateral using the marginfi-client-v2 SDK on Solana mainnet.

Frequently Asked Questions about marginfi

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I deposit and borrow on Marginfi with TypeScript?

Initialize MarginfiClient with getConfig("production"), create or fetch a MarginfiAccountWrapper, then call account.deposit(amount, bankAddress) and account.borrow(amount, bankAddress) with UI-denominated amounts. Banks are looked up via client.getBankByTokenSymbol("SOL").

How do flash loans work on Marginfi?

Marginfi flash loans let you borrow without collateral provided you repay within the same transaction. Call account.flashLoan({ ixs }) with your custom instructions, such as arbitrage or liquidation logic, between the borrow and repay.

What is the Marginfi production program address on Solana?

The production program is MFv2hWf31Z9kbCa1snEPYctwafyhdvnV7FZnsebVacA with group 4qp6Fx6tnZkY5Wropq9wUYgtFxXKwE6viZxFHg3rdAG8. Use getConfig("production") from the SDK instead of hardcoding addresses.

Why does my Marginfi borrow transaction fail with insufficient health?

Borrows fail when weighted liabilities exceed weighted collateral under initial margin requirements. Check account.computeHealthComponents(MarginRequirementType.Initial) and computeFreeCollateral(), then deposit more collateral or reduce the borrow amount.

How do I repay Marginfi debt including accrued interest?

Call account.repay(0, bankAddress, true) with the repayAll flag set to true. This automatically covers accrued interest and closes the liability position, avoiding dust left by partial fixed-amount repayments.

Why do Marginfi oracle prices differ from market prices?

Marginfi applies confidence interval adjustments to oracle prices: collateral is valued at price minus confidence, liabilities at price plus confidence. Stale or uncranked oracle feeds can also cause transaction failures.