- Frontend: Hedron Frontend - User interface for the Hedera DeFi AI Agent
- AutoSwapLimit Contract: AutomationSwapLimit - Intermediate contract for limit orders
- MockPriceOracle: 0.0.6506125
- AutoSwapLimit: 0.0.6506134
An artificial intelligence agent specialized in the Hedera Hashgraph DeFi ecosystem that helps both novice and experienced users navigate and optimize their investments through integrated SaucerSwap DEX operations, Bonzo Finance lending protocols, and advanced AutoSwapLimit trading strategies. The agent provides real-time analysis and automated execution capabilities.
| π Quick Navigation | π Path | π Description |
|---|---|---|
| π¦ DeFi Tools | typescript/src/shared/tools/defi/ | Complete DeFi integration suite |
| π€ WebSocket Agent | typescript/examples/langchain/websocket-agent.ts | Main AI agent server |
| π§ Message Handlers | typescript/examples/langchain/handlers/ | WebSocket message processing |
- Complexity of the DeFi ecosystem: New users feel overwhelmed by the number of protocols and available options
- Lack of technical knowledge: Difficulty understanding concepts like liquidity mining, yield farming, lending, staking
- Risk of losses: Making investment decisions without enough information can result in significant losses
- Fragmented information: Data is scattered across multiple platforms without a unified view
- Inefficient manual monitoring: Manually reviewing multiple protocols consumes valuable time
- Missed opportunities: The best arbitrage and yield opportunities can go unnoticed
- Complex comparative analysis: Comparing yields, risks, and features between protocols takes a lot of time
- Lack of automation: Need for tools that facilitate data-driven decision making
- Automated analysis: Continuous monitoring of SaucerSwap, Bonzo Finance, and AutoSwapLimit
- Personalized recommendations: Suggestions based on the user's risk profile and objectives
- Conversational interface: Natural interaction via WebSocket for real-time queries
- Persistent context: Conversation memory that maintains session context
- REST APIs: Direct connection to platform data endpoints
- Smart contracts: Native interaction with on-chain protocols
- Intelligent rate limiting: Optimized request management to avoid limitations
- Smart cache: 30-second cache system to optimize performance
- Type: DEX with AMM (Automated Market Maker)
- Features:
- Token swap quotes and execution
- Real-time price discovery
- Single-sided staking (Infinity Pools)
- Liquidity analysis
- Advanced trading with AutoSwapLimit orders
- Dominance: +44% of total Hedera DeFi TVL and +60% of unique active wallets
- Type: Lending & borrowing protocol (Aave V2 fork)
- Features:
- Supply assets to earn interest
- Real-time lending rates monitoring
- Portfolio analysis and optimization
- Risk assessment tools
- TVL: Steady growth post-launch (~$25M in Q4 2024, later ~$38M)
- Type: Advanced limit order system
- Features:
- Automated limit orders execution
- Price monitoring and alerts
- Order management and cancellation
- Strategic trading automation
graph TD
A[Client connects WebSocket] --> B{Message type}
B -->|CONNECTION_AUTH| C[Authenticate User]
C --> D[Create User Connection]
D --> E[Initialize LLM Agent]
E --> F[Load Hedera Tools]
F --> G[Load DeFi Tools]
G --> H[User Authenticated β
]
B -->|USER_MESSAGE| I[Process User Message]
I --> J[Verify Authentication]
J --> K{User Authenticated?}
K -->|No| L[Send Authentication Error]
K -->|Yes| M[Load Conversation Memory]
M --> N[Execute LLM Agent]
N --> O[Agent analyzes message with tools]
O --> P{Response type?}
P -->|Text response| Q[AGENT_RESPONSE]
P -->|Transaction required| R[TRANSACTION_TO_SIGN]
P -->|Swap quote| S[SWAP_QUOTE]
P -->|System message| T[SYSTEM_MESSAGE]
Q --> U[Send response to client]
R --> V[Client signs transaction]
S --> W[Show structured quote]
T --> X[Show system message]
V --> Y[TRANSACTION_RESULT]
B -->|TRANSACTION_RESULT| Z[Process transaction result]
Z --> AA[Update agent state]
AA --> U
G --> BB[DeFi Tools Loading]
BB --> CC[π¦ Bonzo Finance<br/>- Lending/Borrowing<br/>- Portfolio Analysis<br/>- Interest Rates]
BB --> DD[π₯ SaucerSwap<br/>- Token Swaps<br/>- Liquidity Pools<br/>- Price Quotes]
BB --> EE[π― AutoSwapLimit<br/>- Limit Orders<br/>- Order Management<br/>- Trading Automation]
BB --> FF[π Analytics<br/>- Real-time Data<br/>- Account Balances<br/>- Market Monitoring]
CC --> GG[Hedera Native Tools]
DD --> GG
EE --> GG
FF --> GG
GG --> HH[π HTS - Token Operations<br/>π£οΈ HCS - Consensus Messages<br/>π° HBAR - Transfers & Balances<br/>π Account Queries]
- Connection Establishment: Client connects to WebSocket server
- Authentication: User sends
CONNECTION_AUTHwith their Hedera account ID - Agent Initialization: System creates personalized agent with tools and memory
- Message Processing: Agent processes user queries using integrated DeFi and Hedera tools
- Response Generation: AI generates responses, quotes, or transaction requests
- Transaction Handling: Client signs transactions externally, reports results back
π¦ DeFi Tools Suite β π Browse DeFi Tools
- Bonzo Finance: Lending & borrowing protocol integration
- SaucerSwap API: DEX market data and analytics
- SaucerSwap Quote: Real-time swap price quotes
- SaucerSwap Router: Swap execution tools
- Infinity Pools: Single-sided staking
- AutoSwapLimit: Advanced limit order system
- AutoSwap Queries: Order monitoring tools
- HTS (Hedera Token Service): Token operations and management
- HCS (Hedera Consensus Service): Messaging and consensus
- HBAR Operations: Transfers, balance queries, account management
- Account Queries: Real-time account information and token balances
| Message Type | Direction | Purpose |
|---|---|---|
CONNECTION_AUTH |
Client β Agent | User authentication with account ID |
USER_MESSAGE |
Client β Agent | User queries and instructions |
AGENT_RESPONSE |
Agent β Client | AI-generated text responses |
SWAP_QUOTE |
Agent β Client | Structured swap quotation data |
TRANSACTION_TO_SIGN |
Agent β Client | Transaction bytes requiring signature |
TRANSACTION_RESULT |
Client β Agent | Signed transaction confirmation |
SYSTEM_MESSAGE |
Agent β Client | System notifications and errors |
- Persistent Context: Each user maintains conversation history
- Token Management: Intelligent memory pruning to optimize performance
- Session Isolation: Each WebSocket connection has independent context
- Auto Cleanup: Memory cleared on disconnection
The Hedera DeFi AI Agent operates as an intelligent middleware between users and the Hedera DeFi ecosystem:
- π Authentication: Users authenticate with their Hedera account ID
- π§ Personalization: Each user gets a dedicated agent instance with memory
- π§ Tool Loading: Agent loads 25+ specialized tools for DeFi operations
- π¬ Natural Language: Users interact in plain language - no technical knowledge required
- π― Intelligent Routing: AI determines which tools to use based on user intent
- π Real-time Data: Tools fetch live data from protocols and mirror nodes
- β‘ Smart Execution: Multi-step operations handled automatically
- π Secure Transactions: Users sign transactions on their side - agent never holds keys
User: "Show me the best yield opportunities on SaucerSwap"
βββ Agent analyzes intent: yield opportunities + SaucerSwap
βββ Calls SaucerSwap API tools for pool data
βββ Calls Infinity Pool tools for staking rewards
βββ Processes and ranks opportunities
βββ Returns formatted analysis with APYs and risks
User: "Set up a limit order to sell 1000 SAUCE at $0.15"
βββ Agent processes: limit order + SAUCE + price target
βββ Calls AutoSwapLimit tools to prepare order
βββ Generates transaction bytes
βββ Sends TRANSACTION_TO_SIGN message
βββ User signs transaction externally
βββ Agent confirms order creation
- Node.js (v16 or higher)
- npm or yarn package manager
-
Navigate to the langchain directory:
cd typescript/examples/langchain -
Install dependencies:
npm install
-
Start the WebSocket agent:
npm run start:websocket
The agent will start and be ready to accept WebSocket connections for real-time DeFi analysis and recommendations.
This project is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License (CC BY-NC-SA 4.0).
β You can:
- Share and redistribute the code
- Adapt and modify the code
- Use for personal, educational, and research purposes
β You cannot:
- Use for commercial purposes without explicit permission
- Distribute modified versions under a different license
If you want to use this project for commercial purposes, please contact the project maintainers for licensing options.
When using this project, please provide appropriate credit and link to this repository.
Built to democratize access to DeFi on Hedera Hashgraph π