marginfi

Implement lending, borrowing, flash loans, and leveraged positions on Marginfi using the TypeScript SDK.

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

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? Building on Marginfi requires precise knowledge of its SDK APIs, account model, health calculations, and program addresses, where mistakes like wrong bank lookups or unsafe borrows can cause failed transactions or liquidations. ## Core Features & Use Cases - Lending & Borrowing Operations: Create Marginfi accounts, deposit collateral, borrow, repay, and withdraw using the @mrgnlabs/marginfi-client-v2 SDK with UI-denominated amounts. - Advanced DeFi Primitives: Execute flash loans, leveraged looping positions, and repay-with-collateral flows composed with swap instructions. - Risk & Health Monitoring: Compute health components, free collateral, interest rates, and utilization to manage positions safely. - Use Case: Build a bot that deposits SOL as collateral, borrows 50% of available USDC capacity, monitors maintenance health, and repays with accrued interest using repayAll. ## Quick Start Ask the agent to set up a Marginfi client on Solana mainnet and deposit 1 SOL into the SOL bank using the marginfi-client-v2 SDK.

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"), fetch or create an account, then call account.deposit(amount, bank.address) and account.borrow(amount, bank.address). Amounts are UI-denominated, and banks are resolved with client.getBankByTokenSymbol.

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, bundled atomically.

How do I check account health before borrowing on Marginfi?

Use account.computeHealthComponents(MarginRequirementType.Maintenance) to get weighted assets and liabilities, and account.computeFreeCollateral() for borrowing capacity. Borrow only when net health and free collateral are positive.

Why does my Marginfi repay amount differ from what I calculated?

Interest accrues between your calculation and transaction submission, changing the debt. Pass repayAll=true with account.repay(0, bankAddress, true) to automatically cover accrued interest and close the position.

What are the Marginfi program and group addresses on Solana mainnet?

The production program is MFv2hWf31Z9kbCa1snEPYctwafyhdvnV7FZnsebVacA and the production group is 4qp6Fx6tnZkY5Wropq9wUYgtFxXKwE6viZxFHg3rdAG8. Prefer loading them via getConfig("production") instead of hardcoding.