Skip to content

Commit 5bade12

Browse files
authored
Merge pull request #2141 from earlyvibz/feature/plugin-hyperliquid
feat: plugin-hyperliquid
2 parents cb51da5 + 1c41de5 commit 5bade12

14 files changed

+832
-2
lines changed

agent/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
"@elizaos/plugin-arthera": "workspace:*",
8888
"@elizaos/plugin-allora": "workspace:*",
8989
"@elizaos/plugin-opacity": "workspace:*",
90+
"@elizaos/plugin-hyperliquid": "workspace:*",
9091
"@elizaos/plugin-akash": "workspace:*",
9192
"readline": "1.3.0",
9293
"ws": "8.18.0",
@@ -99,4 +100,4 @@
99100
"ts-node": "10.9.2",
100101
"tsup": "8.3.5"
101102
}
102-
}
103+
}

agent/src/index.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ import { webSearchPlugin } from "@elizaos/plugin-web-search";
8484
import { giphyPlugin } from "@elizaos/plugin-giphy";
8585
import { letzAIPlugin } from "@elizaos/plugin-letzai";
8686
import { thirdwebPlugin } from "@elizaos/plugin-thirdweb";
87-
87+
import { hyperliquidPlugin } from "@elizaos/plugin-hyperliquid";
8888
import { zksyncEraPlugin } from "@elizaos/plugin-zksync-era";
8989

9090
import { OpacityAdapter } from "@elizaos/plugin-opacity";
@@ -758,6 +758,12 @@ export async function createAgent(
758758
? artheraPlugin
759759
: null,
760760
getSecret(character, "ALLORA_API_KEY") ? alloraPlugin : null,
761+
getSecret(character, "HYPERLIQUID_PRIVATE_KEY")
762+
? hyperliquidPlugin
763+
: null,
764+
getSecret(character, "HYPERLIQUID_TESTNET")
765+
? hyperliquidPlugin
766+
: null,
761767
getSecret(character, "AKASH_MNEMONIC") &&
762768
getSecret(character, "AKASH_WALLET_ADDRESS")
763769
? akashPlugin
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
*
2+
3+
!dist/**
4+
!package.json
5+
!readme.md
6+
!tsup.config.ts

packages/plugin-hyperliquid/README.md

+111
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# Hyperliquid Plugin for Eliza
2+
3+
This plugin enables interaction with the Hyperliquid DEX through Eliza, providing spot trading capabilities.
4+
5+
## Features
6+
7+
- 💱 Spot Trading
8+
- Market orders (immediate execution)
9+
- Limit orders (price-specific)
10+
- Smart price validation to prevent mistakes
11+
- 📊 Price Checking
12+
- Real-time price information
13+
- 24h price change
14+
- Volume statistics
15+
- 🔄 Order Management
16+
- Cancel all open orders
17+
- Clear feedback on execution
18+
19+
## Installation
20+
21+
Add the plugin to your Eliza configuration:
22+
23+
```json
24+
{
25+
"plugins": ["@elizaos/plugin-hyperliquid"]
26+
}
27+
```
28+
29+
## Configuration
30+
31+
Set the following environment variables:
32+
33+
```env
34+
HYPERLIQUID_PRIVATE_KEY=your_private_key # Required for trading and cancelling orders
35+
HYPERLIQUID_TESTNET=true_or_false # Optional, defaults to false
36+
```
37+
38+
## Available Actions
39+
40+
### 1. SPOT_TRADE
41+
42+
Place spot market or limit orders.
43+
44+
Examples:
45+
46+
```
47+
# Market Orders
48+
"buy 1 PIP" -> Buys 1 PIP at market price
49+
"sell 2 HYPE" -> Sells 2 HYPE at market price
50+
"market buy 1 ETH" -> Buys 1 ETH at market price
51+
52+
# Limit Orders
53+
"buy 1 PIP at 20 USDC" -> Places buy order for 1 PIP at 20 USDC
54+
"sell 0.5 HYPE at 21 USDC" -> Places sell order for 0.5 HYPE at 21 USDC
55+
```
56+
57+
### 2. PRICE_CHECK
58+
59+
Get current price information for any token.
60+
61+
Examples:
62+
63+
```
64+
"What's the price of PIP?"
65+
"Check HYPE price"
66+
"Get ETH price"
67+
```
68+
69+
Returns: Current price, 24h change, and volume.
70+
71+
### 3. CANCEL_ORDERS
72+
73+
Cancel all your open orders.
74+
75+
Examples:
76+
77+
```
78+
"Cancel all orders"
79+
"Cancel my orders"
80+
```
81+
82+
## Price Validation
83+
84+
The plugin includes smart price validation to prevent mistakes:
85+
86+
- Market Orders: Validates price is within ±50% of market price
87+
- Limit Orders:
88+
- Buy orders must be below market price
89+
- Sell orders must be above market price
90+
- Warns if price is very different from market (±80%)
91+
92+
## Error Handling
93+
94+
The plugin provides clear error messages for common issues:
95+
96+
- Invalid token symbols
97+
- Price validation failures
98+
- Network connection issues
99+
- Order execution failures
100+
101+
## Security Notes
102+
103+
- Store your private key securely using environment variables
104+
- Test with small amounts first
105+
- Use testnet for initial testing
106+
- Monitor your orders regularly
107+
- Double-check prices before confirming trades
108+
109+
## License
110+
111+
MIT
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import eslintGlobalConfig from "../../eslint.config.mjs";
2+
3+
export default [...eslintGlobalConfig];
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "@elizaos/plugin-hyperliquid",
3+
"version": "0.1.7",
4+
"main": "dist/index.js",
5+
"type": "module",
6+
"types": "dist/index.d.ts",
7+
"dependencies": {
8+
"@elizaos/core": "workspace:*",
9+
"hyperliquid": "^1.5.6",
10+
"zod": "^3.23.8"
11+
},
12+
"devDependencies": {
13+
"@types/node": "^20.0.0",
14+
"tsup": "8.3.5"
15+
},
16+
"scripts": {
17+
"build": "tsup --format esm --dts",
18+
"dev": "tsup --format esm --dts --watch",
19+
"lint": "eslint --fix --cache ."
20+
}
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import {
2+
Action,
3+
ActionExample,
4+
IAgentRuntime,
5+
Memory,
6+
State,
7+
HandlerCallback,
8+
elizaLogger,
9+
} from "@elizaos/core";
10+
import { Hyperliquid } from "hyperliquid";
11+
12+
export const cancelOrders: Action = {
13+
name: "CANCEL_ORDERS",
14+
similes: ["CANCEL_ALL_ORDERS", "CANCEL", "CANCEL_ALL"],
15+
description: "Cancel all open orders on Hyperliquid",
16+
validate: async (runtime: IAgentRuntime) => {
17+
return !!runtime.getSetting("HYPERLIQUID_PRIVATE_KEY");
18+
},
19+
handler: async (
20+
runtime: IAgentRuntime,
21+
message: Memory,
22+
state: State,
23+
options: Record<string, unknown>,
24+
callback?: HandlerCallback
25+
) => {
26+
try {
27+
// Initialize SDK
28+
const sdk = new Hyperliquid({
29+
privateKey: runtime.getSetting("HYPERLIQUID_PRIVATE_KEY"),
30+
testnet: runtime.getSetting("HYPERLIQUID_TESTNET") === "true",
31+
enableWs: false,
32+
});
33+
await sdk.connect();
34+
35+
elizaLogger.info("Cancelling all open orders...");
36+
const result = await sdk.custom.cancelAllOrders();
37+
elizaLogger.info("Cancel result:", result);
38+
39+
if (callback) {
40+
const cancelledCount =
41+
result?.response?.data?.statuses?.length || 0;
42+
callback({
43+
text:
44+
cancelledCount > 0
45+
? `Successfully cancelled ${cancelledCount} open order${cancelledCount > 1 ? "s" : ""}`
46+
: "No open orders to cancel",
47+
content: result,
48+
});
49+
}
50+
51+
return true;
52+
} catch (error) {
53+
elizaLogger.error("Error cancelling orders:", error);
54+
if (callback) {
55+
callback({
56+
text: `Error cancelling orders: ${error.message}`,
57+
content: { error: error.message },
58+
});
59+
}
60+
return false;
61+
}
62+
},
63+
examples: [
64+
[
65+
{
66+
user: "{{user1}}",
67+
content: {
68+
text: "Cancel all my orders",
69+
},
70+
},
71+
{
72+
user: "{{agent}}",
73+
content: {
74+
text: "I'll cancel all your open orders.",
75+
action: "CANCEL_ORDERS",
76+
},
77+
},
78+
{
79+
user: "{{agent}}",
80+
content: {
81+
text: "Successfully cancelled 2 open orders",
82+
},
83+
},
84+
],
85+
] as ActionExample[][],
86+
};
87+
88+
export default cancelOrders;

0 commit comments

Comments
 (0)