plugin-hedera-dex
v0.2.0
Published
Comprehensive Hedera DEX plugin for SaucerSwap integration with ElizaOS. Provides real-time pool data, token swapping, and complete DEX functionality on Hedera blockchain.
Downloads
20
Maintainers
Readme
Hedera DEX Plugin
A comprehensive Hedera DEX plugin for SaucerSwap integration with ElizaOS. This plugin provides real-time access to SaucerSwap V2 liquidity pools, token swapping capabilities, and complete DEX data from the Hedera blockchain.
🚀 Features
This plugin provides:
- 📊 Pool Management: Fetches all liquidity pools from SaucerSwap V2
- 💱 Token Swapping: Execute real token swaps on SaucerSwap DEX
- 🔍 Pool Information: Get detailed information about specific trading pairs
- ⚡ Real-time Data: Connects to Hedera Mirror Node for live blockchain data
- 🌐 Multi-network Support: Works with both Hedera mainnet and testnet
- 🔗 Provider Integration: Supplies contextual information about DEX capabilities
- 📈 Onchain Data: No mocking - fetches real pool data from contract events
- 🏥 Health Monitoring: Built-in health check and status endpoints
📁 Structure
plugin-hedera-dex/
├── src/
│ ├── __tests__/ # Unit tests
│ │ ├── plugin.test.ts
│ │ └── test-utils.ts
│ ├── plugin.ts # Main plugin implementation
│ ├── saucerswap-abi.ts # SaucerSwap contract ABIs
│ ├── manual-test.ts # Manual testing utilities
│ └── index.ts # Plugin export
├── scripts/
│ └── install-test-deps.js # Test dependency installer
├── dist/ # Compiled output
│ ├── index.js
│ └── index.d.ts
├── tsup.config.ts # Build configuration
├── tsconfig.json # TypeScript config
├── package.json # Dependencies and scripts
└── README.md # This file🚀 Getting Started
Prerequisites
- Node.js 18+ or Bun
- ElizaOS framework
- Hedera testnet/mainnet account (for real swaps)
- OpenAI or Anthropic API key
Installation
Clone or install the plugin:
# If part of the main project cd plugin-hedera-dex npm installBuild the plugin:
npm run buildConfigure environment variables:
# In your main project .env file HEDERA_NETWORK=testnet HEDERA_MIRROR_NODE_URL=https://testnet.mirrornode.hedera.com # Optional: For real swaps HEDERA_PRIVATE_KEY=your_private_key HEDERA_ACCOUNT_ID=0.0.your_account_id
💬 Usage
Available Actions
1. List Pools (LIST_POOLS)
Fetches all liquidity pools from SaucerSwap V2.
Trigger phrases:
- "Show me all the liquidity pools on SaucerSwap"
- "What pools are available for trading?"
- "List pools" / "Get pools" / "Show pools"
- "SaucerSwap pools"
What it does:
- Connects to the Hedera Mirror Node
- Queries the SaucerSwap V2 Factory contract for pool creation events
- Parses pool data including token pairs, fees, and liquidity information
- Returns formatted pool information with contract IDs and token details
2. Get Pool Info (GET_POOL_INFO)
Get detailed information about a specific trading pair.
Trigger phrases:
- "Show WHBAR/USDC pool details"
- "Get pool info for SAUCE and XSAUCE"
- "What are the details of the HBAR/USDT pool?"
3. Swap Tokens (SWAP_TOKENS)
Execute token swaps on SaucerSwap DEX.
Trigger phrases:
- "Swap 10 HBAR for USDT"
- "Trade 100 USDC for SAUCE"
- "Exchange 5.5 WHBAR to BONZO"
Features:
- Real swap execution on testnet/mainnet
- Automatic token association if needed
- Slippage protection
- Transaction confirmation
API Endpoints
The plugin provides REST API endpoints:
GET /- Health check endpointGET /api/status- Plugin status information
Configuration
Set environment variables in your .env file:
# Network Configuration
HEDERA_NETWORK=testnet # or mainnet
HEDERA_MIRROR_NODE_URL=https://testnet.mirrornode.hedera.com
# Wallet Configuration (for real swaps)
HEDERA_PRIVATE_KEY=your_private_key_here
HEDERA_ACCOUNT_ID=0.0.your_account_id
# Optional: Demo mode (uses mock data)
DEMO_MODE=falseSupported Networks:
- Mainnet: Factory contract
0.0.3946833 - Testnet: Factory contract
0.0.1197038
✨ Key Features
🔗 Blockchain Integration
- Direct integration with Hedera Hashgraph network
- Real-time data from Hedera Mirror Node API
- Support for both mainnet and testnet environments
- Actual on-chain transaction execution
💱 DEX Functionality
- Complete SaucerSwap V2 integration
- Pool discovery and liquidity information
- Token swapping with slippage protection
- Automatic token association handling
🏗️ Architecture
- Minimal dependencies for fast deployment
- TypeScript with full type safety
- Modular plugin architecture
- RESTful API endpoints
🧪 Testing & Development
- Comprehensive unit test suite
- Manual testing utilities
- Mock data support for development
- Built-in health monitoring
Plugin Components
Actions
Define agent capabilities:
const myAction: Action = {
name: 'MY_ACTION',
description: 'Description of what this action does',
validate: async (runtime, message, state) => {
// Validation logic
return true;
},
handler: async (runtime, message, state, options, callback) => {
// Action implementation
return { success: true, data: {} };
},
};Services
Manage plugin state:
export class MyService extends Service {
static serviceType = 'my-service';
async start() {
// Initialize service
}
async stop() {
// Cleanup
}
}Providers
Supply contextual information:
const myProvider: Provider = {
name: 'MY_PROVIDER',
description: 'Provides contextual data',
get: async (runtime, message, state) => {
return {
text: 'Provider data',
values: {},
data: {},
};
},
};API Routes
Backend endpoints:
routes: [
{
name: 'api-endpoint',
path: '/api/endpoint',
type: 'GET',
handler: async (req, res) => {
res.json({ data: 'response' });
},
},
];🛠️ Development Commands
# Install dependencies
npm install
# Build the plugin
npm run build
# Run tests
npm test
# Format code
npm run format
# Manual testing
npm run manual-test🚀 Deployment
Local Development
# In your main project
npm run devProduction Deployment
The plugin is ready for deployment on platforms like Render, Vercel, or any Node.js hosting service.
Environment Variables for Production:
NODE_ENV=production
HEDERA_NETWORK=mainnet
HEDERA_MIRROR_NODE_URL=https://mainnet-public.mirrornode.hedera.com
HEDERA_PRIVATE_KEY=your_production_private_key
HEDERA_ACCOUNT_ID=0.0.your_production_accountTesting
Write unit tests in src/__tests__/:
import { describe, it, expect } from 'bun:test';
describe('My Plugin', () => {
it('should work correctly', () => {
expect(true).toBe(true);
});
});Publishing
- Update
package.jsonwith your plugin details - Build your plugin:
bun run build - Publish:
elizaos publish
🔧 Technical Details
Dependencies
@elizaos/core- ElizaOS framework integration@hashgraph/sdk- Hedera SDK for blockchain operationsethers- Ethereum-compatible utilities for contract interactionaxios- HTTP client for API requestszod- Runtime type validation
Supported Token Standards
- HBAR - Native Hedera cryptocurrency
- HTS Tokens - Hedera Token Service fungible tokens
- Wrapped HBAR (WHBAR) - ERC-20 compatible HBAR
SaucerSwap Integration
- V2 Factory Contract: Pool discovery and creation events
- Router Contract: Token swapping and liquidity operations
- Pool Contracts: Individual liquidity pool interactions
🤝 Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Submit a pull request
📄 License
This plugin is part of the ElizaOS ecosystem and follows the same licensing terms.
🆘 Support
- Documentation: ElizaOS Docs
- Issues: Report bugs and feature requests via GitHub Issues
- Community: Join the ElizaOS Discord community
Built with ❤️ for the Hedera and ElizaOS communities
