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 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.
What you get back: A list of pools with their addresses, token pairs, TVL, volume, and protocol type. The API supports both Meteora DLMM and DAMM V2 pools — the same code works for both.

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 encrypted ID (needed for withdrawal), current value, PnL, whether it’s in range, and token details.

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 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: Both zap-in and zap-out auto-detect pool types. The same code works for DLMM and DAMM V2.
  • 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