Skip to main content
Glama

Meteora DLMM MCP Server

by fciaf420
api-vs-sdk-test.jsโ€ข6.11 kB
// Test both Meteora API and SDK approaches require('dotenv').config(); const https = require('https'); const DLMM = require("@meteora-ag/dlmm").default; const { Connection, PublicKey } = require("@solana/web3.js"); const config = { rpcUrl: process.env.RPC_URL || "https://solana-rpc.publicnode.com", apiBase: "https://dlmm-api.meteora.ag" }; const connection = new Connection(config.rpcUrl); // Helper function to make API calls function apiCall(endpoint) { return new Promise((resolve, reject) => { const url = `${config.apiBase}${endpoint}`; console.log(`API Call: ${url}`); https.get(url, (res) => { let data = ''; res.on('data', chunk => data += chunk); res.on('end', () => { try { resolve(JSON.parse(data)); } catch (error) { reject(new Error(`Failed to parse JSON: ${error.message}`)); } }); }).on('error', reject); }); } async function testMeteoraAPI() { console.log('\n๐ŸŒ Testing Meteora API Approach...'); try { // Test 1: Get all pairs console.log('๐Ÿ“Š Fetching all DLMM pairs...'); const pairs = await apiCall('/pair/all'); console.log(`โœ… Found ${pairs.length} pairs via API`); if (pairs.length > 0) { const samplePair = pairs[0]; console.log('๐Ÿ“‹ Sample pair:', { address: samplePair.address, tokenX: samplePair.mint_x, tokenY: samplePair.mint_y, tokenXSymbol: samplePair.name.split('-')[0], tokenYSymbol: samplePair.name.split('-')[1] }); // Test 2: Get specific pair info console.log(`\n๐Ÿ” Fetching details for pair: ${samplePair.address}`); const pairDetails = await apiCall(`/pair/${samplePair.address}`); console.log('โœ… Pair details:', { fees24h: pairDetails.fees_24h, volume24h: pairDetails.volume_24h, liquidity: pairDetails.liquidity, activeBin: pairDetails.active_bin_id }); } return true; } catch (error) { console.error('โŒ API Error:', error.message); return false; } } async function testMeteoraSDK() { console.log('\n๐Ÿ› ๏ธ Testing Meteora SDK Approach...'); try { // Test 1: Get pairs using SDK static method console.log('๐Ÿ“Š Fetching pairs via SDK...'); const pairs = await DLMM.getLbPairs(connection); console.log(`โœ… Found ${pairs.length} pairs via SDK`); if (pairs.length > 0) { const samplePairAddress = pairs[0].publicKey; console.log(`๐Ÿ” Testing pair: ${samplePairAddress.toString()}`); // Test 2: Create DLMM instance console.log('๐Ÿ—๏ธ Creating DLMM instance...'); const dlmmPool = await DLMM.create(connection, samplePairAddress); console.log('โœ… DLMM instance created'); // Test 3: Get active bin (read operation) console.log('๐Ÿ“ˆ Fetching active bin...'); const activeBin = await dlmmPool.getActiveBin(); console.log('โœ… Active bin:', { binId: activeBin.binId, price: activeBin.price }); // Test 4: Check available methods for transactions console.log('๐Ÿ”ง Available transaction methods:'); const txMethods = [ 'claimSwapFee', 'claimAllSwapFee', 'addLiquidityByStrategy', 'removeLiquidity', 'swap', 'createPosition' ]; txMethods.forEach(method => { const hasMethod = typeof dlmmPool[method] === 'function'; console.log(` ${hasMethod ? 'โœ…' : 'โŒ'} ${method}`); }); } return true; } catch (error) { console.error('โŒ SDK Error:', error.message); return false; } } async function testUserPositions() { console.log('\n๐Ÿ‘ค Testing User Position Queries...'); // Test wallet (you can replace with a real wallet that has positions) const testWallet = "11111111111111111111111111111112"; // System program - won't have positions try { // API approach console.log('๐ŸŒ API approach for positions...'); try { const positions = await apiCall(`/user/${testWallet}`); console.log(`โœ… API: Found ${positions.length} positions`); } catch (error) { console.log('โ„น๏ธ API: Position endpoint might not exist or wallet has no positions'); } // SDK approach console.log('๐Ÿ› ๏ธ SDK approach for positions...'); const positions = await DLMM.getAllLbPairPositionsByUser(connection, new PublicKey(testWallet)); console.log(`โœ… SDK: Found ${positions.length} positions`); return true; } catch (error) { console.error('โŒ Position query error:', error.message); return false; } } async function runComparison() { console.log('๐Ÿš€ Meteora DLMM: API vs SDK Comparison Test'); console.log('=' .repeat(60)); const tests = [ { name: 'Meteora API', fn: testMeteoraAPI }, { name: 'Meteora SDK', fn: testMeteoraSDK }, { name: 'User Positions', fn: testUserPositions } ]; const results = {}; for (const test of tests) { console.log(`\n๐Ÿงช Testing: ${test.name}`); try { results[test.name] = await test.fn(); } catch (error) { console.error(`โŒ ${test.name} failed:`, error.message); results[test.name] = false; } } console.log('\n' + '=' .repeat(60)); console.log('๐Ÿ“Š COMPARISON RESULTS:'); console.log('=' .repeat(60)); Object.entries(results).forEach(([name, success]) => { console.log(`${success ? 'โœ…' : 'โŒ'} ${name}: ${success ? 'SUCCESS' : 'FAILED'}`); }); console.log('\n๐Ÿ’ก RECOMMENDATIONS:'); console.log('๐Ÿ“– READ Operations: Use Meteora API (simpler, faster)'); console.log('โœ๏ธ WRITE Operations: Use Meteora SDK (required for transactions)'); console.log('๐Ÿ”„ HYBRID Approach: API for reads + SDK for writes'); console.log('\n๐ŸŽฏ NEXT STEPS:'); console.log('1. Update MCP server to use API for read operations'); console.log('2. Keep SDK for transaction operations (claiming fees, etc.)'); console.log('3. Test with real wallet addresses that have positions'); } runComparison().catch(console.error);

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/fciaf420/Meteora-DLMM-MCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server