Overview
What the Project 0 TypeScript SDK is, how it is organised, and where to start.
@0dotxyz/p0-ts-sdk is the official TypeScript SDK for the marginfi program that powers Project 0 on Solana. It loads the protocol state (banks, oracle prices, lookup tables, e-mode settings) into a single client, wraps your marginfi account in a convenient API, and builds complete, ready-to-sign transactions for every protocol action — from a plain deposit to a leveraged loop that crosses venues (Project 0, Kamino, Drift and Jupiter Lend).
Program upgrade 0.1.10 — 2026-08-25 15:00 UTC. Integrators must be on
@0dotxyz/p0-ts-sdk@^2.7.0 before the mainnet flip; older SDKs break on flash
loans, health simulation and account transfers afterwards. See
Program Upgrade 0.1.10.
Coming from @mrgnlabs/marginfi-client-v2? It has been deprecated since March
2026 — follow the migration guide.
Start here
Getting Started
Install the SDK, pick an environment, and run your first deposit and borrow.
Architecture & API Layers
Wrapper methods, transaction builders, instruction builders and raw instructions — and when to use each.
Core
Accounts
Create, derive, discover and load marginfi accounts; read positions; transfer and close.
Banks & Prices
Find banks, understand asset tags, read APYs, caps, rate limits and oracle prices.
Deposit, Withdraw, Borrow & Repay
The four core operations, their options, return shapes and how to send them.
Health, Max Amounts & E-mode
Health factor, free collateral, bank-aware max borrow/withdraw/deposit, and e-mode impacts.
Advanced flows
Looping
Build leveraged positions in one flash loan with direct or bridged swap routing.
Position Swaps
Swap collateral, swap debt, repay with collateral, and roll Exponent PTs.
Flash Loans
Wrap your own instructions in a marginfi flash loan.
Integrations & Native Stake
Kamino, Drift and Jupiter Lend banks, plus minting LSTs from native stake.
Reference
Transactions
Result types, multi-transaction ordering, bundles, priority fees, oracle cranking and lookup tables.
Error Handling
Typed TransactionBuildingError codes and the program errors you should recognise.
Program Upgrade 0.1.10
What the 0.1.9 → 0.1.10 upgrade changes and what you must do.
Migration Guide
Move from marginfi-client-v2 to p0-ts-sdk.
Package entry points
| Import | Contents |
|---|---|
@0dotxyz/p0-ts-sdk | Everything you normally need: Project0Client, MarginfiAccountWrapper, transaction and instruction builders, types and utilities. |
@0dotxyz/p0-ts-sdk/vendor | Heavy oracle and venue integrations (Pyth, Switchboard, Kamino, Drift, Jupiter Lend, Exponent, …). Split out to keep bundles small. |
@0dotxyz/p0-ts-sdk/jupiter | Jupiter swap helpers (createJupiterClient). |
@0dotxyz/p0-ts-sdk/instructions | Raw Anchor instruction builders — see Architecture. |
The SDK is written in TypeScript and exports all of its types. Builders never sign or send: every make*Tx returns unsigned transactions and every make*Ix returns instructions, so the SDK fits any wallet or key-management setup. It works on mainnet (production) and the staging deployments; there is no devnet deployment.
Running the examples
The SDK repository ships runnable examples in examples/:
- Core —
01-deposit,02-borrow,03-withdraw,04-repay - Pricing & health —
05-oracle-prices,06a-account-health-simulated,06b-account-health-calculated - Position swaps —
10-swap-collateral,11-swap-debt - Native stake —
12-mint-staked-lst,13-redeem-staked-lst,14-merge-stake-accounts - Exponent PT rollover —
15-roll-pt,17-roll-pt-redeem-proof - Leverage loops —
16a-loop,16b-loop-bridged,16c-loop-pinned-route - Discovery —
18-mint-holders - Swaps —
swap-engine(multi-provider quoting used by loops and swaps)
git clone https://github.com/0dotxyz/p0-ts-sdk.git
cd p0-ts-sdk/examples
cp .env.example .env # set RPC URL, account address, optional keypair
npx tsx 01-deposit.tsEach example runs in simulation mode by default, so you can explore without spending fees or risking funds.
API reference and help
- TypeDoc — clone the repository and run
pnpm docs(output indocs/). Every exported function and type also carries JSDoc insrc/. - GitHub Issues — report bugs or request features.
- Discord — join the developer community.
- AI agents — the docs are available through the MCP server and as plain markdown (
/llms.txt).