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
Prerequisites
- An LP Agent API key (get one from the LP Agent Portal)
- A Solana wallet with SOL for transaction fees
- Node.js >= 18
Configuration
Tune these settings before running the bot: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.
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 ~$150/SOL, that's $1.50–$4.50. Set `MIN_FEE_USD` so the gain comfortably covers the cost: `$5` is a safe default for most users.
Common Errors
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: Claiming works the same for DLMM and DAMM V2: the only difference is the
typefield in the request body. The re-deposit differs: a DAMM V2 pool has no bins, so skip the active-bin lookup and calladd-txwithoutfromBinId/toBinId(the complete script below does this)./lp-positions/openreturns both kinds of position unless you passplatform.
API Endpoints Used
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