What You’ll Build
By the end of this tutorial, you’ll know how to programmatically:- Zap-In — Find a pool and add liquidity with a single token (SOL)
- Zap-Out — Withdraw your liquidity back to your wallet
How It Works
The Zap-In Flow
Adding liquidity to a Meteora pool involves 4 steps:The Zap-Out Flow
Withdrawing liquidity follows a similar pattern:Understanding Key Concepts
Before diving into code, here are the key concepts:Prerequisites
- An LP Agent API key (get one from the API Dashboard)
- A Solana wallet keypair
- Node.js >= 18
Step-by-Step: Zap-In
Step 1: Setup
First, set up your API client and wallet:Step 2: Discover a Pool
Browse available pools and filter by your criteria. The API returns pools sorted by your chosen metric.Step 3: Get Pool Info & Set Your Range
Fetch the pool’s current state to find the active bin (where the current price is). You’ll place liquidity around this bin.Step 4: Generate Zap-In Transactions
Tell the API how much SOL you want to deposit. It generates unsigned transactions that swap your SOL into the right token ratio and add liquidity.Already holding both tokens? Use
mode: "normal" with amountX and amountY instead of inputSOL to skip the swap step.Step 5: Sign & Land
Sign the transactions with your wallet and submit them via LP Agent’s Jito landing endpoint.Step-by-Step: Zap-Out
Step 1: Find Your Open Positions
Query your wallet to see all open LP positions.Step 2: Get Quotes (Optional)
Preview what you’ll receive before withdrawing. The API shows quotes for different output options.Step 3: Generate Zap-Out Transactions
Choose how much to withdraw and what token(s) to receive.Step 4: Sign & Land
Reference
Strategy Types
Common Errors
Tips
- Transaction landing: Always use LP Agent’s landing endpoints instead of direct RPC. Better success rates via Jito — for free.
- DAMM V2 pools: Both zap-in and zap-out auto-detect pool types. The same code works for DLMM and DAMM V2.
- Partial zap-out: Use
bpsless than 10000 to withdraw only a portion (e.g.,5000= 50%).
Complete Script
Here’s everything above combined into a single copy-paste-ready script:Full zap-in + zap-out script
Full zap-in + zap-out script
Next Steps
- Auto-Rebalancing Bot — Build a bot that monitors and rebalances positions automatically
- Explore the full API Reference for all available endpoints