Skip to content

New Agent Template: Camelot v3 LP Rebalancing Agent#229

Open
yourdevkalki wants to merge 11 commits intoEmberAGI:mainfrom
yourdevkalki:final-v2
Open

New Agent Template: Camelot v3 LP Rebalancing Agent#229
yourdevkalki wants to merge 11 commits intoEmberAGI:mainfrom
yourdevkalki:final-v2

Conversation

@yourdevkalki
Copy link

Based on the Camelot v3 LP Rebalancing Agent template, here's the PR description formatted according to your template:

Summary

Related Issue(s):
New Agent Template: Camelot v3 LP Rebalancing Agent (Alloc8-Inspired)

This PR adds a comprehensive Camelot v3 LP Rebalancing Agent template to the Vibekit templates directory. The agent provides automated liquidity position rebalancing for Camelot v3 concentrated liquidity pools with AI-powered analysis, dual operating modes (passive/active), and comprehensive tooling for DeFi LP management.

Type of Change:

  • 🤖 Agent template (new agent template)

🧪 Testing

Tests Performed:

  • Agent compilation and build verification
  • Tool functionality testing with mock data
  • A2A task execution testing
  • MCP server integration testing
  • Configuration validation testing

Test Results:

  • ✅ TypeScript compilation passes
  • ✅ All tools execute without errors
  • ✅ A2A tasks start and stop correctly
  • ✅ MCP server responds to health checks
  • ✅ Configuration loading works with all environment variables

Steps to Run Tests:

cd typescript/templates/alloc8-camelot-v3-rebalancer
pnpm install
pnpm build
pnpm test

Checklists

Code Quality

  • Code follows project conventions and style guidelines
  • TypeScript compilation passes (pnpm build)
  • Linting passes (pnpm lint:check)
  • All tests pass (pnpm test)
  • No any types introduced
  • Error handling implemented appropriately
  • Security best practices followed (no exposed secrets/keys)

Documentation

  • Code is self-documenting or includes necessary comments
  • README updated if applicable
  • API/interface changes documented
  • Breaking changes noted in description

Agent/MCP Specific (if applicable)

  • MCP protocol compliance verified
  • Agent skills and tools properly defined
  • Error handling for external API failures
  • Rate limiting and retry logic implemented
  • Configuration options documented

Deployment Notes

Deployment Considerations:

  • Agent requires at least one AI provider API key (OpenAI, Anthropic, XAI, Hyperbolic, or OpenRouter)
  • Wallet private key must be provided for transaction signing
  • Optional Telegram bot configuration for notifications
  • Subgraph API key required for position fetching

New or Changed Environment Variables:

# AI Provider Configuration (at least one required)
OPENAI_API_KEY=your_openai_api_key_here
OPENROUTER_API_KEY=your_openrouter_api_key_here
ANTHROPIC_API_KEY=your_anthropic_api_key_here
XAI_API_KEY=your_xai_api_key_here
HYPERBOLIC_API_KEY=your_hyperbolic_api_key_here

# Preferred AI provider and model
AI_PROVIDER=openai
AI_MODEL=gpt-4

# Agent Configuration
AGENT_NAME="Camelot v3 LP Rebalancing Agent"
AGENT_VERSION="1.0.0"
AGENT_DESCRIPTION="Automated LP rebalancing agent for Camelot v3 concentrated liquidity pools"
AGENT_URL="localhost"
PORT=3001

# Rebalancing Configuration
REBALANCER_MODE=passive       # passive or active
RISK_PROFILE=medium           # low, medium, or high
DISCOVERY_MODE=auto-discover  # auto-discover or single-pool
CHECK_INTERVAL=3600000        # Check interval in milliseconds (1 hour = 3600000)

# Chain Configuration (for auto-discovery mode)
CHAIN_IDS=42161              # Comma-separated chain IDs (default: 42161 for Arbitrum)

# Pool Configuration (required only for single-pool mode)
POOL_ID=0x...                # Camelot v3 pool address (required for single-pool mode)
TOKEN_0=ETH                  # First token symbol (required for single-pool mode)
TOKEN_1=USDC                 # Second token symbol (required for single-pool mode)

# Thresholds
PRICE_DEVIATION_THRESHOLD=0.05    # 5% price deviation threshold
UTILIZATION_THRESHOLD=0.8         # 80% liquidity utilization threshold

# Wallet Configuration
WALLET_PRIVATE_KEY=your_wallet_private_key_here

# Blockchain Configuration
ARBITRUM_RPC_URL=https://arb1.arbitrum.io/rpc

# MCP Server Configuration
EMBER_MCP_SERVER_URL=https://api.emberai.xyz/mcp

# Subgraph Configuration (required)
SUBRAPH_API_KEY=your_subgraph_api_key_here

# Telegram Notifications (optional)
TELEGRAM_BOT_TOKEN=your_telegram_bot_token_here
TELEGRAM_CHAT_ID=your_telegram_chat_id_here

# Server Configuration
ENABLE_CORS=true
BASE_PATH=/

Breaking Changes or Migration Steps:

  • None - this is a new template addition

New Dependencies Added:

  • @google-a2a/types - For A2A task management
  • nanoid - For unique ID generation
  • viem - For blockchain interactions
  • @openzeppelin/contracts - For smart contract interactions

Additional Context

Key Features Implemented:

  1. Comprehensive Tool Suite (10 tools):

    • fetchWalletPositions - Auto-discover all active LP positions
    • getWalletLiquidityPositions - Get detailed position information
    • getLiquidityPools - Fetch pool data and configuration
    • getTokenMarketData - Get real-time token prices
    • withdrawLiquidity - Withdraw liquidity from positions
    • supplyLiquidity - Supply liquidity with optimal ranges
    • swapTokens - Token swapping (placeholder for future implementation)
    • getWalletBalances - Check wallet token balances
    • calculatePoolKPIs - Calculate comprehensive pool metrics
    • analyzePositionWithLLM - AI-powered position analysis
  2. A2A Tasks Architecture:

    • PassiveModeTask - Monitors positions and sends alerts
    • ActiveModeTask - Automatically executes rebalances
    • BaseRebalanceTask - Shared functionality and utilities
  3. AI-Powered Analysis:

    • Multi-provider AI support (OpenAI, Anthropic, XAI, Hyperbolic, OpenRouter)
    • Intelligent position health assessment
    • Market condition analysis
    • Optimal range recommendations
    • Risk level evaluation
  4. Production-Ready Features:

    • Docker containerization (dev and prod)
    • Health endpoints and agent cards
    • Structured logging and error handling
    • Telegram notification integration
    • Comprehensive configuration management

Architecture Highlights:

  • V2 Framework Compliance: Uses latest Vibekit v2 patterns with skills, tools, and context providers
  • MCP Integration: Leverages Ember MCP server for blockchain data
  • LLM Orchestration: Intelligent tool routing and coordination
  • Risk Management: Configurable risk profiles (low, medium, high)
  • Flexible Discovery: Both auto-discovery and single-pool modes

This agent template demonstrates advanced DeFi automation capabilities and serves as a comprehensive example for building sophisticated LP management agents with Vibekit.

@ParastooGM
Copy link
Contributor

Hey @yourdevkalki ! Thanks for your contribution. Could you please provide a demo of your agent functionality?

@yourdevkalki
Copy link
Author

yourdevkalki commented Sep 29, 2025

Hey @yourdevkalki ! Thanks for your contribution. Could you please provide a demo of your agent functionality?

i am attaching few demo screenshots
Screenshot 2025-09-30 at 2 07 54 AM
Screenshot 2025-09-30 at 2 10 19 AM
Screenshot 2025-09-30 at 1 00 29 AM
Screenshot 2025-09-30 at 2 07 28 AM

* Load and validate agent configuration from environment variables
*/
export function loadAgentConfig(): AgentConfig {
const config = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strategy configs should be supplied as input parameters to the strategy itself so that the user of the agent has direct control through the conversational interface. They can be optional with defaults.

mode: process.env.REBALANCER_MODE || 'passive',
riskProfile: process.env.RISK_PROFILE || 'medium',
discoveryMode: process.env.DISCOVERY_MODE || 'auto-discover',
poolId: process.env.POOL_ID,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean the agent only works on a single pool defined at startup?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs updated to latest Ember Onchain Actions MCP tools

/**
* Check if token swap is needed for optimal ratio
*/
private async checkIfSwapNeeded(): Promise<boolean> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The real strategy needs to be executed here

};

// Get wallet balances
const walletAddress = getWalletAddressFromPrivateKey(this.context.config.walletPrivateKey);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Private key shouldn't be passed around willy nilly. Keep it securely isolated in it's own module. Ideally, this can all be managed using Viem.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace with Onchain Actions token MCP Resource

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the difference between this and fetchWalletPositions.ts?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace with Onchain Actions liquidity withdrawal tool

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace with Onchain Actions MCP Resource for tokens

* Utility function to safely convert a private key to wallet address
* Handles formatting and validation of the private key
*/
export function getWalletAddressFromPrivateKey(privateKey: string): string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make private key contained within this module. It shouldn't be passed around the codebase.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants