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 LP Agent Portal)
- 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.min_market_cap and min_liquidity take plain USD amounts.
Discover returns both Meteora DLMM (meteora) and DAMM V2 (meteora_damm_v2) pools. The next step reads the DLMM active bin, so this guide asks for DLMM pools only. Drop platform to see DAMM V2 pools too: add-tx detects the pool type from the address.
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.id (the position address, which you pass as position_id to withdraw), its protocol (meteora for DLMM, meteora_damm_v2 for DAMM V2), current value, PnL, whether it’s in range, and token details.
Step 2: Estimate the Payout (Optional)
See what each output option really pays out before you withdraw. Each estimate is priced on the same swap routedecrease-tx builds, with swaps and fees already taken.
zap-out-estimates covers Meteora DLMM positions. Skip this step for a DAMM V2 position.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: Zap-in detects the pool type from the pool address. Zap-out does not: send
type: "meteora_damm_v2"todecrease-txfor a DAMM V2 position (copy it from the position’sprotocol).zap-out-estimatescovers DLMM positions only. - 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