Architecture Overview
The system follows a clean separation of concerns across four layers:Layer Breakdown
Layer 1: Integration Layer
Layer 1: Integration Layer
Karen provides three ways for external systems to interact with the wallet infrastructure:MCP Server
- Model Context Protocol server for AI assistants
- Exposes 17 tools for wallet operations
- Used by Claude Desktop, OpenClaw, and other MCP-compatible agents
- Located in
src/mcp/server.ts
- HTTP endpoints for programmatic access
- Bearer token authentication
- Rate limiting and spending caps per API key
- Located in
src/api/server.ts
- Import Karen’s core modules directly into Node.js applications
- Full programmatic control over all components
- Best for building custom agent platforms
Layer 2: Agent Runtime
Layer 2: Agent Runtime
The autonomous agent layer implements a continuous decision-making loop:Core Loop: Observe → Think → Act → Remember
- Observe - Gather current wallet state, balances, recent transactions
- Think - Send context to LLM with available skills and strategy
- Act - Execute the chosen skill via the skill registry
- Remember - Persist decision and outcome to memory for future context
AgentRuntime(src/agent/runtime.ts) - Main agent execution loopOrchestrator(src/agent/orchestrator.ts) - Manages multiple concurrent agentsMemoryStore(src/agent/memory/memory-store.ts) - Persistent decision historySkillRegistry(src/agent/skills/index.ts) - 17 pluggable agent capabilities
Layer 3: Core Engine
Layer 3: Core Engine
The foundational wallet and transaction infrastructure:Wallet Manager (
src/core/wallet/wallet-manager.ts)- Create wallets with HD derivation (BIP-44)
- Secure keystore encryption (AES-256-GCM)
- Balance queries for SOL and SPL tokens
src/core/transaction/transaction-engine.ts)- Build, sign, and send transactions
- Automatic guardrail validation
- Comprehensive audit logging
src/core/transaction/guardrails.ts)- Per-transaction spending limits
- Rate limiting (transactions per minute)
- Daily spending caps
- Program allowlists
- Address blocklists
src/core/audit-logger.ts)- JSONL append-only logs for all transactions
- Agent decision tracking
- Event streaming for monitoring
Layer 4: Protocol Adapters
Layer 4: Protocol Adapters
High-level interfaces for DeFi protocols:
- JupiterAdapter - Token swaps via Jupiter DEX aggregator
- TokenLauncherAdapter - Create and manage SPL tokens
- StakingAdapter - Native SOL staking to validators
- SplTokenAdapter - SPL token operations (burn, close, freeze)
- WrappedSolAdapter - Wrap/unwrap SOL to wSOL
src/protocols/Directory Structure
Integration Methods
- MCP (Recommended for AI Agents)
- REST API
- Direct SDK
The MCP server exposes Karen’s capabilities as tools that any MCP-compatible AI assistant can use.Configuration Example (Claude Desktop):Available MCP Tools:
karen_create_wallet- Create a new walletkaren_balance- Check balanceskaren_swap- Swap tokens via Jupiterkaren_transfer- Send SOL or SPL tokenskaren_launch_token- Create a new SPL tokenkaren_stake- Stake SOL to validators- …and 11 more (see MCP Tools)
Data Flow Example
Here’s what happens when an agent decides to swap SOL for USDC:- Agent Runtime observes current wallet state (2 SOL, 0 USDC)
- LLM Provider receives context + available skills, decides to invoke
swap - Skill Registry executes the
swapskill with parameters{inputToken: "SOL", outputToken: "USDC", amount: 0.5} - Jupiter Adapter fetches a quote and builds the swap transaction
- Transaction Engine validates against guardrails (spending limit, rate limit, program allowlist)
- Wallet Manager decrypts the keypair to sign the transaction
- Solana RPC broadcasts the signed transaction
- Audit Logger records the transaction details
- Memory Store persists the decision + outcome for future context
- Agent proceeds to next cycle
All Karen operations run on Solana Devnet by default. To use mainnet, update the RPC URL in
src/core/solana/connection.ts.Next Steps
Wallets
Learn about HD derivation, keystore encryption, and wallet management
Agents
Understand the agent runtime, LLM integration, and decision-making loop
Security
Explore guardrails, spending limits, and audit logging
Quick Start
Get Karen running in 5 minutes