packages/examples/lp-manager/README.md
An autonomous liquidity position (LP) management agent for DeFi. This agent monitors LP positions across multiple DEXes on Solana and EVM chains, automatically rebalancing when profitable opportunities are detected.
cd examples/lp-manager
bun install
Create a .env file in the typescript directory:
# User identifier (optional, auto-generated if not set)
LP_USER_ID=my-lp-agent
# Solana Configuration
SOLANA_PRIVATE_KEY=your_base58_private_key
SOLANA_RPC_URL=https://api.mainnet-beta.solana.com
# EVM Configuration (set the chains you want to use)
EVM_PRIVATE_KEY=0x_your_hex_private_key
ETHEREUM_RPC_URL=https://eth-mainnet.example.com
BASE_RPC_URL=https://mainnet.base.org
ARBITRUM_RPC_URL=https://arb1.arbitrum.io/rpc
BSC_RPC_URL=https://bsc-dataseed.binance.org
# Monitoring Configuration
LP_CHECK_INTERVAL_MS=300000 # 5 minutes (default)
LP_MIN_GAIN_THRESHOLD_PERCENT=1.0 # Minimum 1% net gain to rebalance
LP_MAX_SLIPPAGE_BPS=50 # 0.5% max slippage
LP_AUTO_REBALANCE_ENABLED=true # Enable automatic rebalancing
# Risk Management
LP_MAX_POSITION_SIZE_USD=10000 # Maximum position size
LP_MIN_POOL_TVL_USD=100000 # Minimum pool TVL to consider
LP_MAX_IL_RISK_PERCENT=10 # Maximum impermanent loss risk
# DEX Preferences (comma-separated, optional)
LP_SOLANA_DEXES=raydium,orca,meteora
LP_EVM_DEXES=uniswap,pancakeswap,aerodrome
# Development mode (with hot reload)
bun run dev
# Production mode
bun run start
| Variable | Default | Description |
|---|---|---|
LP_USER_ID | Auto-generated | Unique identifier for the agent |
LP_CHECK_INTERVAL_MS | 300000 (5 min) | How often to check positions |
LP_MIN_GAIN_THRESHOLD_PERCENT | 1.0 | Minimum net gain % to trigger rebalance |
LP_MAX_SLIPPAGE_BPS | 50 | Maximum slippage in basis points |
LP_AUTO_REBALANCE_ENABLED | true | Enable automatic rebalancing |
LP_CONCENTRATED_REPOSITION_THRESHOLD | 0.1 | Reposition when price is 10% from range edge |
LP_MAX_POSITION_SIZE_USD | 10000 | Maximum USD value per position |
LP_MIN_POOL_TVL_USD | 100000 | Minimum pool TVL to consider |
LP_MAX_IL_RISK_PERCENT | 10 | Maximum impermanent loss risk % |
When running in a terminal, the following commands are available:
| Command | Description |
|---|---|
status or s | Display current status summary |
check or c | Trigger an immediate monitoring cycle |
help or h | Show available commands |
quit or q | Stop the agent gracefully |
Each LP position is analyzed and marked as either rebalancable (š) or locked (š):
Rebalancable positions can be automatically moved to better pools when opportunities arise.
Locked positions are excluded from automatic rebalancing. A position is locked if:
Each opportunity is scored from 0-100 based on:
| Factor | Max Points | Criteria |
|---|---|---|
| Net Gain | 40 | 1% = 10 points, caps at 4% |
| Volume/TVL | 20 | 10-50% daily turnover is ideal |
| APR Sustainability | 20 | Lower, stable APRs score higher |
| TVL Health | 10 | Larger pools = better liquidity |
| Cost Efficiency | 10 | Lower cost relative to position |
Opportunities are also classified by APR quality:
High-APR opportunities (ā) are those with 20%+ APR that are sustainable.
The agent tracks LP positions by:
Every monitoring cycle, the agent:
When a profitable opportunity is found:
For concentrated liquidity positions (Raydium CLMM, Orca Whirlpools, Uniswap V3):
examples/lp-manager/
āāā src/
ā āāā agent.ts # Main agent entry point
ā āāā character.ts # Agent personality and settings
ā āāā index.ts # Module exports
ā āāā types.ts # TypeScript type definitions
ā āāā services/
ā āāā LpMonitoringService.ts # Autonomous monitoring service
āāā package.json
āāā tsconfig.json
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā LP MANAGER AGENT ā
ā Autonomous Liquidity Position Management for DeFi ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
[LpManagerAgent] Starting LP Manager Agent...
[LpManagerAgent] User ID: lp-agent-1736784000000
[LpManagerAgent] Runtime initialized
[LpManagerAgent] LP Manager services ready
[LpManagerAgent] Vault public key: 7xK2...3mNp
[LpManagerAgent] User profile ensured
[LpMonitoringService] Starting autonomous monitoring
[LpMonitoringService] Check interval: 300000ms (5 minutes)
============================================================
LP MANAGER AGENT STATUS
============================================================
Running: true
Monitoring: true
User ID: lp-agent-1736784000000
Last Check: 2026-01-13T12:00:00.000Z
Next Check: 2026-01-13T12:05:00.000Z
POSITIONS:
raydium:SOL-USDC-clmm
SOL/USDC - $5,240.00 @ 24.30% APR (in range)
uniswap:ETH-USDC-0.3
ETH/USDC - $3,100.00 @ 18.70% APR (in range)
OPPORTUNITIES:
ā raydium:SOL-USDC-clmm ā meteora:SOL-USDC-dlmm
APR: 24.30% ā 32.10% (net +7.80%)
Cost: $4.20, Risk: 15
Reason: Net gain 7.80% exceeds threshold, risk acceptable
SUMMARY:
Total Value: $8,340.00
Average APR: 21.50%
Positions: 2
Actionable Opportunities: 1
============================================================
LP_AUTO_REBALANCE_ENABLED=false to observe opportunities before enabling automatic execution.LP_MAX_SLIPPAGE_BPS to prevent losses from price movement during transactions.You can extend the agent by modifying LpMonitoringService.ts:
// Add custom opportunity evaluation logic
private evaluateOpportunity(opportunity: OptimizationOpportunity): OpportunityAnalysis {
// Your custom logic here
}
The agent uses @elizaos/plugin-lp-manager which can be extended to support additional DEXes. See the plugin documentation for details.
LP_AUTO_REBALANCE_ENABLED=truereason field in opportunity analysisMIT - See LICENSE file in repository root.