A plugin for ElizaOS that enables interaction with the Raydium DEX on Solana, including liquidity pool management, position tracking, and automated market making capabilities.
The Raydium plugin provides comprehensive integration with Raydium's V2 SDK, allowing ElizaOS agents to:
- Manage concentrated liquidity positions (CLMM)
- Add and remove liquidity from pools
- Track and analyze LP positions
- Fetch pool information and statistics
- Execute swaps (coming soon)
- Liquidity Pool Management: Full support for adding and removing liquidity from Raydium pools
- Position Tracking: Monitor and analyze existing LP positions
- Token2022 Support: Compatible with Token2022 standard tokens
- Mainnet & Devnet Support: Configurable for both mainnet and devnet operations
- TypeScript Native: Fully typed for excellent developer experience
- Comprehensive Testing: Unit tests and E2E test scenarios included
npm install @elizaos/plugin-raydiumCreate a .env file in your project root:
# Required
SOLANA_PRIVATE_KEY=your_base58_private_key
SOLANA_RPC_URL=https://api.mainnet-beta.solana.com
# or use Helius RPC for better performance
HELIUS_RPC_URL=https://your-helius-rpc-url.com
# Optional
SOLANA_CLUSTER=mainnet # or devnetRegister the plugin in your ElizaOS agent configuration:
import { RaydiumPlugin } from '@elizaos/plugin-raydium';
const agent = new Agent({
plugins: [RaydiumPlugin],
// ... other configuration
});The plugin provides two main services:
Handles SDK initialization and connection management:
const sdkService = runtime.getService('RaydiumSdkService');
await sdkService.load(ownerKeypair);Provides liquidity pool operations:
const lpService = runtime.getService('RaydiumLpService');
// Get available pools
const pools = await lpService.getPools();
// Add liquidity
const result = await lpService.addLiquidity({
userVault: ownerKeypair,
poolId: '8sN9549P3Zn6xpQRqpApN57xzkCh6sJxLwuEjcG2W4Ji',
tokenAAmountLamports: '1000000000', // 1 SOL
slippageBps: 100, // 1%
});
// Get position details
const position = await lpService.getLpPositionDetails(
owner.publicKey.toBase58(),
positionNftMint
);
// Remove liquidity
const removeResult = await lpService.removeLiquidity({
userVault: ownerKeypair,
poolId: positionNftMint,
lpTokenAmountLamports: position.liquidity,
slippageBps: 100,
});Provides context about user's LP positions to the agent:
const context = await positionProvider.get(runtime, message, state);
// Returns formatted information about all user positionsThe plugin implements the standard ElizaOS ILpService interface:
interface ILpService {
getDexName(): string;
getPools(tokenAMint?: string, tokenBMint?: string): Promise<PoolInfo[]>;
addLiquidity(params: AddLiquidityParams): Promise<TransactionResult>;
removeLiquidity(params: RemoveLiquidityParams): Promise<TransactionResult>;
getLpPositionDetails(userPublicKey: string, poolId: string): Promise<LpPositionDetails | null>;
}interface AddLiquidityParams {
userVault: Keypair;
poolId: string;
tokenAAmountLamports: string;
tokenBAmountLamports?: string;
slippageBps: number;
tickLowerIndex?: number;
tickUpperIndex?: number;
}
interface RemoveLiquidityParams {
userVault: Keypair;
poolId: string;
lpTokenAmountLamports: string;
slippageBps: number;
}The plugin includes comprehensive test coverage:
bun run testE2E tests require a funded wallet on mainnet:
- Set up your
.envfile with a private key - Ensure the wallet has SOL and any required tokens
- Run the tests:
bun run testThe plugin has been tested with the SOL-ai16z pool:
- Pool ID:
8sN9549P3Zn6xpQRqpApN57xzkCh6sJxLwuEjcG2W4Ji - Token A: SOL
- Token B: ai16z (Token2022)
bun run build# Run all tests
bun run test
# Run only unit tests
bun run vitest
# Run with coverage
bun run test:coverage├── src/
│ ├── services/
│ │ ├── RaydiumSdkService.ts # SDK initialization and management
│ │ └── RaydiumLpService.ts # LP operations implementation
│ ├── providers/
│ │ └── positionProvider.ts # Context provider for positions
│ ├── e2e/
│ │ ├── scenarios.ts # E2E test scenarios
│ │ └── test-utils.ts # Testing utilities
│ ├── types.ts # Type definitions
│ └── index.ts # Plugin entry point
├── tests/ # Test files
├── docs.md # Detailed documentation
└── README.md # This file
- "Cannot find target token accounts": Ensure your wallet has the required tokens for the pool
- Empty pool list from API: The plugin will fall back to RPC data when API is unavailable
- Token2022 compatibility: Make sure to use pools that support Token2022 if trading those tokens
Enable debug logging:
import { setLoggerLevel, LogLevel } from '@raydium-io/raydium-sdk-v2';
setLoggerLevel('Raydium', LogLevel.Debug);Contributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
MIT License - see LICENSE file for details
For issues and questions:
- Open an issue on GitHub
- Join the ElizaOS Discord community
- Check the docs.md file for detailed technical documentation