Skip to main content

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
No smart contract knowledge required: LP Agent handles everything through simple REST APIs.
LP Agent provides built-in transaction landing via Jito bundles for both zap-in and zap-out. This gives you a significantly better landing rate than submitting transactions directly via RPC: and it’s free to use.

How It Works

The Zap-In Flow

Adding liquidity to a Meteora pool involves 4 steps:
What is “zap-in”? You provide just SOL, and the API automatically swaps it into the correct ratio of both tokens before adding liquidity. No need to manually buy tokens first.

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.
What you get back: A list of pools with their addresses, token pairs, TVL, volume, and protocol type. Dollar filters such as 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.
To rank pools by recent fee yield, use sortBy: "fee_tvl_ratio" with feeTVLInterval set to 5m, 1h, 6h or 24h. Each pool also reports its fees for the last 5 minutes, 1 hour and 6 hours in fee_5m, fee_1h and fee_6h (USD).

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.
How to choose your range: Wider = less risk of going out of range, but lower fee APR. Tighter = higher fees but more frequent rebalancing needed. Start with 30-70 bins on each side.

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.
What you get back: Base64-encoded unsigned transactions, split into swap transactions (to convert SOL) and add-liquidity transactions. Plus metadata about your new position.

Step 5: Sign & Land

Sign the transactions with your wallet and submit them via LP Agent’s Jito landing endpoint.
That’s it! Your liquidity is now live and earning fees.

Step-by-Step: Zap-Out

Step 1: Find Your Open Positions

Query your wallet to see all open LP positions.
What you get back: Each position includes its 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 route decrease-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.
Output options:

Step 4: Sign & Land

Always use the landing-decrease-tx endpoint instead of submitting transactions directly via RPC. LP Agent’s Jito integration provides a much better landing rate and it’s completely free.

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" to decrease-tx for a DAMM V2 position (copy it from the position’s protocol). zap-out-estimates covers DLMM positions only.
  • Partial zap-out: Use bps less 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:

Next Steps