meme-agent/
├── src/
│ ├── agents/ # AI Agent System
│ │ ├── models/ # AI Model Implementations
│ │ ├── providers/ # AI Provider Integrations (Groq, DeepSeek)
│ │ │ ├── groq.provider.ts # Groq API Integration for Tweet Generation
│ │ │ └── deepseek.provider.ts # DeepSeek Integration
│ │ ├── prompts/ # Agent Prompts & Templates
│ │ └── groups/ # Agent Group Configurations
│ ├── services/ # Core Services
│ │ ├── ai/ # AI Services
│ │ │ ├── tweetGenerator.ts # Tweet Content Generation
│ │ │ ├── types.ts # AI Service Type Definitions
│ │ │ └── personality.ts # Character-based Generation
│ │ ├── social/ # Social Media Integration
│ │ │ ├── twitter.ts # Twitter API Integration
│ │ │ ├── MarketTweetCron.ts # Automated Market Updates
│ │ │ └── agentTwitterClient.ts # Twitter Client Implementation
│ │ ├── analysis/ # Analysis Services
│ │ │ ├── market-analysis.ts # Market Data Processing
│ │ │ └── transaction-analysis.ts # Transaction Analysis
│ │ └── blockchain/ # Blockchain Integration
│ ├── personality/ # Character System
│ │ ├── types.ts # Character Schema Definitions
│ │ ├── loadCharacter.ts # Character Loading Logic
│ │ └── traits/ # Character Traits Implementation
│ ├── infrastructure/ # Infrastructure Layer
│ │ ├── database/ # Database Management
│ │ │ ├── entities/ # TypeORM Entities
│ │ │ ├── schemas/ # MongoDB Schemas
│ │ │ └── services/ # Database Services
│ │ └── cache/ # Cache Management
│ ├── middleware/ # Express Middleware
│ │ ├── auth/ # Authentication
│ │ ├── validation/ # Request Validation
│ │ └── error/ # Error Handling
│ └── utils/ # Utility Functions
├── characters/ # Character Configurations
│ └── jenna.character.json # Jenna Character Definition
├── tests/ # Test Suites
│ ├── unit/ # Unit Tests
│ │ └── services/
│ │ └── social/ # Twitter Service Tests
│ └── integration/ # Integration Tests
├── logs/ # Application Logs
│ ├── social.log # Social Media Integration Logs
│ └── market.log # Market Analysis Logs
└── scripts/ # Utility Scripts
-
Tweet Generation Pipeline
src/services/ai/tweetGenerator.ts
: Core tweet generation logicsrc/services/ai/personality.ts
: Character-based content adaptationsrc/services/social/MarketTweetCron.ts
: Automated market updates
-
Twitter Service Implementation
src/services/social/twitter.ts
: Main Twitter servicesrc/services/social/agentTwitterClient.ts
: Twitter API clientsrc/middleware/rateLimit.ts
: Rate limiting implementation
-
Character System Integration
src/personality/types.ts
: Character schema definitionssrc/personality/loadCharacter.ts
: Character loading logiccharacters/jenna.character.json
: Character configuration
-
Market Data Integration
src/services/analysis/market-analysis.ts
: Market data processingsrc/services/blockchain/defi/tradingEngine.ts
: Trading functionalitysrc/services/analysis/transaction-analysis.ts
: Transaction analysis
### Technology Stack
#### Core Technologies
- **Runtime**: Node.js (≥18.0.0)
- ESM modules
- Worker threads support
- Native fetch API
- **Package Manager**: pnpm (≥8.0.0)
- Workspace support
- Fast, efficient installation
- **Language**: TypeScript 5.3
- Strict type checking
- ESM support
- Decorators
#### Database Layer
- **PostgreSQL 14**
- TypeORM integration
- JSON(B) support
- Full-text search
- Partitioning
- **MongoDB 6**
- Mongoose ODM
- Time-series collections
- Change streams
- Atlas integration
- **Redis 7**
- Caching layer
- Pub/Sub system
- Rate limiting
- Session storage
#### AI Infrastructure
- **Primary Model**: DeepSeek-33B
- 33 billion parameters
- Custom fine-tuning
- Specialized prompts
- **Secondary Models**
- GPT-4 Turbo
- Claude-3 Opus
- Ollama (local)
- Groq (cloud)
## Core Features
### 1. Transaction Management
- **Real-time Monitoring**
- WebSocket connections
- Transaction streaming
- Block confirmation tracking
- Mempool monitoring
- **Analysis Engine**
- Price impact calculation
- Slippage prediction
- Gas optimization
- MEV protection
- **Multi-DEX Support**
- Jupiter integration
- Orca integration
- Best route finding
- Split orders
- **Caching System**
- Transaction history
- Order book snapshots
- Token metadata
- Price feeds
### 2. Token Analysis
- **Contract Analysis**
- Bytecode verification
- Security audit
- Ownership analysis
- Permission checks
- **Market Analysis**
- Volume profiling
- Liquidity analysis
- Holder distribution
- Price correlation
- **Social Metrics**
- Sentiment analysis
- Trend detection
- Influencer tracking
- Community growth
- **Technical Analysis**
- Custom indicators
- Pattern recognition
- Volatility metrics
- Risk assessment
### 3. Social Media Integration
#### Twitter Integration Architecture
The Twitter integration follows the elizaOS pattern, using direct authentication without API tokens for improved reliability and maintainability.
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ │ AI Service │ │ Tweet Service │ │ Market Data │ │ (tweetGenerator)│────▶│ (twitter.ts) │◀────│ Services │ └────────┬────────┘ └────────┬────────┘ └────────┬────────┘ │ │ │ ▼ ▼ ▼ ┌─────────────────────────────────────────────────────────────────┐ │ Character Configuration │ │ (personality & engagement settings) │ └─────────────────────────────────────────────────────────────────┘
#### Core Components
1. **Twitter Authentication Service** (`src/services/social/twitter.ts`)
```typescript
interface TwitterAuthService {
initialize(config: TwitterConfig): Promise<void>;
authenticate(): Promise<AuthResult>;
validateSession(): Promise<boolean>;
handleAuthError(error: AuthError): Promise<void>;
}
interface TwitterConfig {
username: string; // Twitter account username
password: string; // Twitter account password
email: string; // Twitter account email
mockMode?: boolean; // Enable mock mode for development
maxRetries?: number; // Maximum authentication retries
retryDelay?: number; // Delay between retries (ms)
}
Authentication Flow:
-
Environment Variable Loading:
class TwitterAuthManager { private loadCredentials(): TwitterConfig { return { username: process.env.TWITTER_USERNAME, password: process.env.TWITTER_PASSWORD, email: process.env.TWITTER_EMAIL, mockMode: process.env.TWITTER_MOCK_MODE === 'true', maxRetries: parseInt(process.env.TWITTER_MAX_RETRIES || '3'), retryDelay: parseInt(process.env.TWITTER_RETRY_DELAY || '5000') }; } }
-
Session Management:
interface SessionManager { initializeSession(): Promise<void>; validateSession(): Promise<boolean>; refreshSession(): Promise<void>; persistCookies(cookies: Cookie[]): Promise<void>; }
-
Error Handling:
interface AuthErrorHandler { handleACIDChallenge(): Promise<void>; // Handle Error 399 handleSuspiciousLogin(): Promise<void>; implementRetryStrategy(): Promise<void>; }
-
Content Generation Service (
src/services/ai/tweetGenerator.ts
)interface TweetGenerator { generateMarketTweet(data: MarketData): Promise<string>; generateEngagementResponse(context: Context): Promise<string>; validateContent(tweet: string): Promise<ValidationResult>; } interface ContentRules { maxEmojis: 0; // No emojis allowed maxHashtags: 0; // No hashtags allowed minInterval: 300000; // 5-minute minimum between tweets requireUnique: true; // Ensure unique post formats }
Content Validation:
class ContentValidator { private readonly rules: ContentRules = { maxEmojis: 0, maxHashtags: 0, minInterval: 300000, requireUnique: true }; async validateTweet(content: string): Promise<ValidationResult> { // Ensure no emojis if (this.containsEmojis(content)) { return { valid: false, reason: 'Contains emojis' }; } // Ensure no hashtags if (this.containsHashtags(content)) { return { valid: false, reason: 'Contains hashtags' }; } // Check uniqueness if (!await this.isUniqueFormat(content)) { return { valid: false, reason: 'Similar format exists' }; } return { valid: true }; } }
-
Rate Limiting Service
interface RateLimitManager { checkLimit(action: TwitterAction): Promise<boolean>; trackRequest(action: TwitterAction): void; getRemainingQuota(): RateLimit; } class TwitterRateLimiter implements RateLimitManager { private readonly limits = { tweets: { window: 900000, max: 300 }, // 15-minute window engagements: { window: 600000, max: 1000 } // 10-minute window }; }
-
Market Update Pipeline
Market Data Collection → Data Validation → Content Generation → Spam Check → Post [Jupiter/Helius] → [Validator] → [TweetGenerator] → [ContentRules] → [Twitter]
-
Authentication Pipeline
Load Credentials → Session Check → Auth Flow → Cookie Management → Ready [.env] → [Validator] → [AuthService] → [SessionManager] → [TwitterService]
-
Error Recovery Flow
Error Detection → Classification → Retry Strategy → Session Refresh → Resume [Monitor] → [ErrorHandler] → [RetryService] → [SessionManager] → [Service]
-
Data Collection
- Twitter authentication & session management
- Rate limit handling
- Mock mode fallback
- Cookie-based persistence
-
Analysis Pipeline
- Market sentiment analysis
- Tweet content validation
- Character-aware generation
- Response optimization
-
Engagement System
- Real-time monitoring
- Context-aware responses
- Personality consistency
- Rate limit awareness
-
Automated Actions
- Market updates
- Trading signals
- Community engagement
- Performance reporting
- Decision Engine
- Multi-model consensus
- Risk evaluation
- Market timing
- Position sizing
- Portfolio Management
- Asset allocation
- Rebalancing
- Risk management
- Performance tracking
- Execution Engine
- Order splitting
- Timing optimization
- Slippage control
- Fee management
- Performance Analysis
- Trade analytics
- Strategy backtesting
- Risk metrics
- Attribution analysis
-
Caching Strategy
interface CacheConfig { ttl: number; maxSize: number; updateInterval: number; }
- Multi-level caching
- Intelligent prefetching
- Cache invalidation
- Memory management
-
Database Optimization
CREATE INDEX idx_token_analysis ON analysis_results USING GiST (token_address, created_at DESC);
- Query optimization
- Index management
- Connection pooling
- Data partitioning
-
API Management
interface RateLimitConfig { windowMs: number; maxRequests: number; strategy: 'sliding' | 'fixed'; }
- Rate limiting
- Request batching
- Response compression
- Circuit breaking
-
Error Handling
class OperationalError extends Error { public readonly isOperational: boolean = true; constructor( public statusCode: number, message: string, public source?: string ) { super(message); } }
- Error classification
- Retry mechanisms
- Fallback strategies
- Recovery procedures
-
Monitoring System
interface MetricCollector { recordLatency(operation: string, duration: number): void; incrementCounter(metric: string): void; recordGauge(metric: string, value: number): void; }
- Performance metrics
- Health checks
- Resource monitoring
- Alert system
-
API Security
interface SecurityConfig { rateLimit: RateLimitConfig; apiKeyRotation: number; ipWhitelist: string[]; requestValidation: ValidationConfig; }
- Authentication
- Authorization
- Input validation
- Rate limiting
-
Data Protection
interface EncryptionConfig { algorithm: string; keyRotation: number; saltRounds: number; }
- Encryption
- Key management
- Access control
- Audit logging
Issues & Solutions:
interface ModelFallback {
primary: AIModel;
fallback: AIModel[];
threshold: number;
maxRetries: number;
}
- Implemented model rotation
- Response validation
- Latency monitoring
- Error recovery
Twitter Content Generation:
interface TweetValidation {
maxLength: number;
contentRules: {
noEmojis: boolean;
noHashtags: boolean;
requireUnique: boolean;
};
retryConfig: {
maxAttempts: number;
backoffMs: number;
};
}
- Character-aware generation
- Market data integration
- Content validation
- Rate limit management
Issues & Solutions:
interface TransactionRetry {
maxAttempts: number;
backoffMs: number;
conditions: RetryCondition[];
}
- Dynamic gas adjustment
- MEV protection
- Confirmation tracking
- Error recovery
Issues & Solutions:
interface DataPartitioning {
strategy: 'time' | 'hash' | 'range';
interval: string;
cleanup: CleanupConfig;
}
- Sharding strategy
- Backup procedures
- Recovery protocols
- Consistency checks
- GraphQL API implementation
- WebSocket optimization
- Database sharding
- Cache optimization
- Kubernetes deployment
- Service mesh integration
- Load balancing
- Auto-scaling
- Advanced ML models
- Social integration
- Analytics dashboard
- Automated testing
{
"dependencies": {
"@pythnetwork/client": "^2.17.0",
"@solana/buffer-layout": "^4.0.1",
"@switchboard-xyz/oracle": "^2.1.13",
"amqplib": "^0.10.3",
"bull": "^4.12.0",
"graphql": "^16.8.1",
"ioredis-cluster": "^2.1.1",
"node-machine-learning": "^1.0.0",
"technicalindicators": "^3.1.0",
"ws": "^8.16.0"
}
}
{
"devDependencies": {
"@types/amqplib": "^0.10.4",
"@types/bull": "^4.10.0",
"@types/ws": "^8.5.10",
"artillery": "^2.0.3",
"autocannon": "^7.14.0",
"madge": "^6.1.0",
"typescript-transform-paths": "^3.4.6"
}
}
These components work together to provide:
- Technical analysis
- Machine learning capabilities
- Message queue processing
- Real-time communication
- Performance testing
- Dependency analysis