Skip to main content
Glama
monostate

100ms Raydium Sniper MCP

by monostate
region-manager.mock.ts4.69 kB
import { Connection, PublicKey, Keypair } from '@solana/web3.js'; import bs58 from 'bs58'; import dotenv from 'dotenv'; // Load environment variables dotenv.config(); // Define region connection type export interface GCloudRegion { name: string; functionUrl: string; status: 'available' | 'unavailable' | 'unknown'; lastError?: string; metrics: { latency: number; successRate: number; lastSuccess?: Date; transactionCount: number; failureCount: number; }; } export interface TransactionResult { region: string; success: boolean; signature?: string; error?: string; executionTime?: number; } export class RegionManager { private regions: Map<string, GCloudRegion> = new Map(); private wallet: Keypair; private state: any; private heliusConnection: Connection; constructor(state: any) { this.state = state; // Initialize wallet (use a mock wallet for testing) try { const privateKey = process.env.WALLET_PRIVATE_KEY; if (privateKey) { this.wallet = Keypair.fromSecretKey(bs58.decode(privateKey)); } else { // Generate a new keypair for testing this.wallet = Keypair.generate(); console.log('Using generated test wallet:', this.wallet.publicKey.toString()); } } catch (error) { console.warn('Error initializing wallet from private key, using generated keypair:', error); this.wallet = Keypair.generate(); console.log('Using generated test wallet:', this.wallet.publicKey.toString()); } // Initialize Helius connection for local operations const heliusEndpoint = `https://mainnet.helius-rpc.com/?api-key=${process.env.HELIUS_API_KEY}`; this.heliusConnection = new Connection(heliusEndpoint, { commitment: 'processed', confirmTransactionInitialTimeout: 10000 }); console.log(`Wallet initialized: ${this.wallet.publicKey.toString()}`); } async initializeConnections(): Promise<void> { // Clear any existing connections this.regions.clear(); // Mock regions for testing const mockRegions = ['us-central1', 'asia-east1', 'europe-west1']; // Initialize connections for each region for (const region of mockRegions) { // Mock function URL const functionUrl = `https://${region}-${process.env.PROJECT_ID || 'mock-project'}.cloudfunctions.net/quickBuyFunction`; // Add to regions map with mock data this.regions.set(region, { name: region, functionUrl, status: 'available', // Set to available for testing metrics: { latency: Math.floor(Math.random() * 50) + 20, // Random latency between 20-70ms successRate: 0.95, // 95% success rate lastSuccess: new Date(), transactionCount: Math.floor(Math.random() * 100), failureCount: Math.floor(Math.random() * 5) } }); console.log(`Initialized mock Google Cloud Function for region ${region}: ${functionUrl}`); } } getRegions(): GCloudRegion[] { return Array.from(this.regions.values()); } getRegion(name: string): GCloudRegion | undefined { return this.regions.get(name); } getWallet(): Keypair { return this.wallet; } getHeliusConnection(): Connection { return this.heliusConnection; } // For compatibility with the old interface async connectWebSockets(tokenMint: string): Promise<void> { // No-op in the mock implementation console.log(`WebSocket connection not needed in mock implementation. Token: ${tokenMint}`); } async executeInAllRegions(tokenMint: string, slippageBps: number): Promise<TransactionResult[]> { // Mock execution in all regions const results: TransactionResult[] = []; for (const [regionName, region] of this.regions.entries()) { // 90% chance of success for testing const success = Math.random() < 0.9; if (success) { results.push({ region: regionName, success: true, signature: bs58.encode(Buffer.from(Array(32).fill(0).map(() => Math.floor(Math.random() * 256)))), executionTime: Math.floor(Math.random() * 50) + 30 // Random execution time between 30-80ms }); } else { results.push({ region: regionName, success: false, error: 'Mock transaction failed', executionTime: Math.floor(Math.random() * 100) + 50 // Random execution time between 50-150ms }); } } return results; } async closeAllConnections(): Promise<void> { // Nothing to close in mock implementation this.regions.clear(); } }

Latest Blog Posts

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/monostate/100ms-SPL-Token-Sniper-MCP'

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