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
A compound bot that runs on a loop and:- Monitors your open LP positions for accrued fees
- Claims fees once they cross a configurable threshold
- Swaps the claimed tokens into SOL in the same flow
- Re-deposits the SOL back into the same pool to compound your yield
How Compounding Works
LP fees accrue inside your position but don’t earn additional fees on their own — they sit idle until you claim and redeploy them. A compound cycle turns those idle fees into more liquidity:The Bot’s Decision Loop
Every check interval, the bot follows this flow:Key Decisions the Bot Makes
| Decision | How It’s Handled |
|---|---|
| When to compound? | When uncollectedFee (USD) crosses MIN_FEE_USD |
| Should I swap to SOL first? | Yes — claim-fee-tx does it in one round-trip with swapToNative: true |
| How much to re-deposit? | The post-claim SOL balance gain, minus a small reserve for fees |
Prerequisites
- An LP Agent API key (get one from the API Dashboard)
- A Solana wallet with SOL for transaction fees
- Node.js >= 18
Configuration
Tune these settings before running the bot:| Setting | Default | Description |
|---|---|---|
CHECK_INTERVAL_MS | 300000 | How often to check positions (ms). 5 min is a good starting point — fees accrue slowly. |
MIN_FEE_USD | 1 | Minimum uncollected fee value (USD) before claiming. Below this, the gas cost outweighs the gain. |
SLIPPAGE_BPS | 500 | Slippage tolerance for the swap-to-SOL leg (500 = 5%) |
RESERVE_SOL | 0.05 | SOL kept in the wallet for future tx fees |
STRATEGY | Spot | Re-deposit distribution: Spot, Curve, or BidAsk |
BIN_RANGE | 34 | Bins on each side of active bin for the re-deposit |
POOL_FILTER | undefined | Only compound a specific pool, or undefined for all |
Step-by-Step
Step 1: Setup
Set up your API client and wallet (same boilerplate as the zap-in tutorial):Step 2: Find Positions With Accrued Fees
Query your open positions and pick the ones whose uncollected fees are worth claiming.Step 3: Generate Claim + Swap-to-SOL Transactions
Theclaim-fee-tx endpoint can return both the claim and the swap-to-SOL transactions in one call when you pass swapToNative: true.
| Field | Description |
|---|---|
claimTxsWithJito[] | Unsigned claim-fee txs (base64), Jito tip already attached |
swapTxsWithJito[] | Unsigned swap txs (base64). Empty if swapToNative: false. Otherwise: one swap per non-SOL fee token, plus a final Jito-tip tx. |
lastValidBlockHeight | Submit before this block height passes (≈ 60s) |
meta | Position metadata, including raw fee amounts at build time |
If a fee token is already SOL, no swap tx is generated for it — it’s transferred to your wallet directly by the claim tx.
Step 4: Sign & Land
Sign every tx and submit them via the landing endpoint. The landing endpoint sends the claim bundle first, then the swap bundle.Step 5: Re-Deposit Into the Same Pool
After the claim lands, your wallet has more SOL. Read the new SOL balance, set aside a reserve for future fees, and zap the rest into the same pool.This example opens a fresh position centered on the current price rather than topping up the original position. Most strategies prefer this — it keeps your range tight around the current price even as the market moves.
Reference
Choosing MIN_FEE_USD
Each compound cycle costs roughly 0.01–0.03 SOL in transaction fees (claim + swap-to-SOL + zap-in). At ~1.50–5` is a safe default for most users.
Common Errors
| Error | Cause | Fix |
|---|---|---|
No claim fee transactions to build | Position has 0 fees to claim | Wait for fees to accrue |
Token X price unavailable | Price feed missing for swap | Try again later or skip swap (swapToNative: false) |
| Transaction expired | lastValidBlockHeight has passed | Re-generate and re-sign within ~60s |
Fees claimed, but swap execution failed | Swap leg failed on-chain | Fees are still claimed in your wallet — you can swap manually or retry |
Tips
- Run on a slow cadence: Fees accrue over hours, not seconds. Checking every 5–15 minutes is plenty and keeps API usage low.
- Out-of-range positions: Fees are still claimable, but if you re-deposit into the same range you’ll be adding to dead liquidity. Consider rebalancing instead, or set the new bin range around the current active bin (which is what the example bot does).
- Consider tax implications: Each claim is a taxable event in many jurisdictions — check with your local rules.
- DAMM V2 support: The same code works for DLMM and DAMM V2 — the only difference is the
typefield in the request body.
API Endpoints Used
| Endpoint | Purpose |
|---|---|
GET /lp-positions/opening | Fetch open positions and their uncollectedFee |
POST /position/claim-fee-tx | Generate claim-fee + optional swap-to-SOL transactions |
POST /position/landing-claim-fee-tx | Land claim + swap transactions via Jito |
GET /token/balance | Read post-claim SOL balance |
GET /pools/{poolId}/info | Get active bin for the new deposit range |
POST /pools/{poolId}/add-tx | Generate zap-in transactions for the re-deposit |
POST /pools/landing-add-tx | Land the zap-in via Jito |
Complete Bot Script
Here’s the full bot ready to copy-paste and run:Full auto-compound bot script
Full auto-compound bot script
Next Steps
- Auto-Rebalancing Bot — Compound + rebalance go well together
- Zap-In & Zap-Out Tutorial — Understand the underlying zap flow
- Explore the full API Reference