Package Exports
- plugin-hedera-dex
- plugin-hedera-dex/package.json
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 install
Build the plugin:
npm run build
Configure 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=false
Supported 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 dev
Production 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_account
Testing
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.json
with 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