Documentation Index
Fetch the complete documentation index at: https://docs.lpagent.io/llms.txt
Use this file to discover all available pages before exploring further.
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:| Concept | What It Means |
|---|---|
| Bin | A price point in a Meteora DLMM pool. Liquidity is placed across a range of bins. |
| Active Bin | The bin where the current price sits. Your position earns fees when the price is within your bin range. |
| Strategy | How liquidity is distributed across bins — Spot (uniform), Curve (concentrated in middle), or BidAsk (concentrated at edges). |
| BPS | Basis points. 10000 = 100%, 5000 = 50%, 500 = 5%. Used for slippage and withdrawal amounts. |
| Landing | Submitting signed transactions on-chain. LP Agent uses Jito bundles for better success rates. |
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.| Output | Description |
|---|---|
allBaseToken | Swap everything to SOL (recommended for easy re-entry) |
both | Receive both tokens as-is (no swap) |
allToken0 | Swap everything to token X |
allToken1 | Swap everything to token Y |
Step 4: Sign & Land
Reference
Strategy Types
| Strategy | Description | Best For |
|---|---|---|
Spot | Uniform distribution across all bins | Stable pairs (SOL/USDC) |
Curve | Bell curve concentrated around active bin | Range-bound markets |
BidAsk | Heavier allocation at the edges | Volatile pairs with mean reversion |
Common Errors
| Error | Cause | Fix |
|---|---|---|
Token X price unavailable | Price feed missing | Try again later or use a different pool |
Insufficient balance | Not enough tokens | Reduce inputSOL or amountX/amountY |
Missing amount to ZapIn | inputSOL not provided in zap-in mode | Add inputSOL to the request body |
| Transaction expired | lastValidBlockHeight has passed | Re-generate and re-sign (don’t wait more than ~60s) |
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