feat(hyperliquid): v0.2.0 — deposit, close, TP/SL, bracket orders#184
feat(hyperliquid): v0.2.0 — deposit, close, TP/SL, bracket orders#184GeoGu360 merged 7 commits intoMigOKG:mainfrom
Conversation
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…2 permit The HL Arbitrum bridge uses batchedDepositWithPermit((address,uint64,uint64,(uint256,uint256,uint8))[]) not deposit(address,uint64). This fix: - Signs a USDC EIP-2612 permit via onchainos sign-message --type eip712 - Constructs correct ABI encoding for batchedDepositWithPermit (static inline tuple) - Fixes onchainos contract-call flag: --data → --input-data, --value → --amt - Improves error reporting: captures onchainos stdout JSON errors (not stderr) - Adds usdc_permit_nonce() RPC helper - Adds onchainos_sign_eip712() helper Verified on-chain: depositTxHash 0x10eec96639afeab26bedfcfb73d0588996b1c174c653affd176656dd1d91e515 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Close positions: - `close --coin BTC [--size 0.005] --confirm` — one-command market close - Auto-detects position direction and size from clearinghouse state - Validates size ≤ current position TP/SL on existing positions: - `tpsl --coin BTC --sl-px 95000 --tp-px 110000 --confirm` - Auto-detects position direction and size - Validates SL/TP prices against current price and position side - Market trigger orders with 10% slippage tolerance (matches HL UI default) - Both sent in single request (grouping: na) Bracket orders (entry + TP/SL linked OCO): - `order --coin BTC --side buy --size 0.01 --sl-px 95000 --tp-px 110000 --confirm` - Uses grouping: normalTpsl — children activate on entry fill - Supports both market and limit entry types Also updates SKILL.md with trigger phrases and command docs for all new commands. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
onchainos AA wallets have a different underlying EOA signer vs displayed address. HL exchange needs the signer registered as an API wallet before orders are accepted. Adds a prominent one-time setup section to SKILL.md with exact steps and how to discover the signer address from the error message. Also adds HYPERLIQUID_TESTNET=1 env var support in config.rs to point all API calls at hyperliquid-testnet.xyz for testing. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
🔨 Phase 2: Build Verification — ✅ PASSED
Build succeeded. Compiled artifact uploaded as workflow artifact. Source integrity: commit SHA `` is the content fingerprint. |
Phase 4: Summary + Pre-flight for
|
| Command | Description |
|---|---|
hyperliquid positions |
Check open positions and account summary |
hyperliquid prices |
Get market mid prices for all or specific coins |
hyperliquid order |
Place market/limit orders with optional TP/SL brackets |
hyperliquid close |
Market-close existing positions |
hyperliquid tpsl |
Set stop-loss/take-profit on open positions |
hyperliquid cancel |
Cancel open orders by ID |
hyperliquid deposit |
Deposit USDC from Arbitrum to Hyperliquid |
Triggers
Activate when users mention Hyperliquid trading, perpetual positions, HL orders, or want to trade perps with phrases like "trade on Hyperliquid", "HL long/short", or "Hyperliquid prices". Also trigger for stop-loss/take-profit management and position closing on the platform.
Auto-injected Pre-flight
## Pre-flight Dependencies (auto-injected by Plugin Store CI)
> Run once per session before first use. These checks ensure required tools are installed.
### Install onchainos CLI + Skills (auto-injected)
```bash
# 1. Install onchainos CLI
onchainos --version 2>/dev/null || curl -fsSL https://raw.githubusercontent.com/okx/onchainos-skills/main/install.sh | sh
# 2. Install onchainos skills (enables AI agent to use onchainos commands)
npx skills add okx/onchainos-skills --yes --global
# 3. Install plugin-store skills (enables plugin discovery and management)
npx skills add MigOKG/plugin-store --skill plugin-store --yes --globalInstall hyperliquid binary (auto-injected)
if ! command -v hyperliquid >/dev/null 2>&1; then
OS=$(uname -s | tr A-Z a-z)
ARCH=$(uname -m)
case "${OS}_${ARCH}" in
darwin_arm64) TARGET="aarch64-apple-darwin" ;;
darwin_x86_64) TARGET="x86_64-apple-darwin" ;;
linux_x86_64) TARGET="x86_64-unknown-linux-gnu" ;;
linux_aarch64) TARGET="aarch64-unknown-linux-gnu" ;;
esac
curl -fsSL "https://github.com/MigOKG/plugin-store/releases/download/plugins/hyperliquid@0.1.0/hyperliquid-${TARGET}" -o ~/.local/bin/hyperliquid
chmod +x ~/.local/bin/hyperliquid
fiReport install (auto-injected, runs once)
REPORT_FLAG="$HOME/.plugin-store/reported/hyperliquid"
if [ ! -f "$REPORT_FLAG" ]; then
mkdir -p "$HOME/.plugin-store/reported"
# Device fingerprint → SHA256 → 32-char device ID
DEV_RAW="$(hostname):$(uname -s):$(uname -m):$HOME"
DEV_ID=$(echo -n "$DEV_RAW" | shasum -a 256 | head -c 32)
# HMAC signature (obfuscated key, same as CLI binary)
_K=$(echo 'OE9nNWFRUFdfSVJkektrMExOV2RNeTIzV2JibXo3ZWNTbExJUDFIWnVoZw==' | base64 -d 2>/dev/null || echo 'OE9nNWFRUFdfSVJkektrMExOV2RNeTIzV2JibXo3ZWNTbExJUDFIWnVoZw==' | openssl base64 -d)
HMAC_SIG=$(echo -n "${_K}${DEV_ID}" | shasum -a 256 | head -c 8)
DIV_ID="${DEV_ID}${HMAC_SIG}"
unset _K
# Report to Vercel stats
curl -s -X POST "https://plugin-store-dun.vercel.app/install" \
-H "Content-Type: application/json" \
-d '{"name":"hyperliquid","version":"0.1.0"}' >/dev/null 2>&1 || true
# Report to OKX API (with HMAC-signed device token)
curl -s -X POST "https://www.okx.com/priapi/v1/wallet/plugins/download/report" \
-H "Content-Type: application/json" \
-d '{"pluginName":"hyperliquid","divId":"'"$DIV_ID"'"}' >/dev/null 2>&1 || true
touch "$REPORT_FLAG"
fi
</details>
---
*Generated by Plugin Store CI after maintainer approval.*
274ac46 to
b376c18
Compare
📋 Phase 3: AI Code Review Report — Score: 72/100
1. Plugin Overview
Summary: This plugin enables trading perpetual futures on the Hyperliquid DEX. It supports checking positions, getting market prices, placing market/limit orders with optional TP/SL brackets, closing positions, canceling orders, and depositing USDC from Arbitrum to Hyperliquid via an official bridge contract. All write operations require explicit Target Users: DeFi traders who want to trade perpetual futures on Hyperliquid through an AI agent interface, with wallet management handled by onchainos. 2. Architecture AnalysisComponents:
Skill Structure:
Data Flow:
Dependencies:
3. Auto-Detected Permissionsonchainos Commands Used
Wallet Operations
External APIs / URLs
Chains Operated On
Overall Permission SummaryThis plugin has significant financial operation capabilities: it can place leveraged perpetual orders, close positions, set stop-loss/take-profit orders, cancel orders, and deposit USDC cross-chain from Arbitrum to Hyperliquid. All write operations are gated behind a 4. onchainos API ComplianceDoes this plugin use onchainos CLI for all on-chain write operations?Yes — All on-chain write operations use onchainos CLI. On-Chain Write Operations (MUST use onchainos)
Data Queries (allowed to use external sources)
External APIs / Libraries Detected
Verdict: ✅ Fully CompliantAll on-chain write operations (signing, broadcasting, contract calls) go through onchainos CLI. The direct Arbitrum RPC calls are strictly read-only ( 5. Security AssessmentStatic Rule Scan (C01-C09, H01-H09, M01-M08, L01-L02)
LLM Judge Analysis (L-PINJ, L-MALI, L-MEMA, L-IINJ, L-AEXE, L-FINA, L-FISO)
Toxic Flow Detection (TF001-TF006)TF005 — curl|sh + financial access:
TF006 — External data boundary + financial operations:
Prompt Injection ScanThe SKILL.md contains no instruction override, identity manipulation, hidden behavior, or confirmation bypass patterns. The base64 string in the telemetry section ( Result: Dangerous Operations CheckThe plugin involves: placing leveraged perpetual orders, closing positions, depositing USDC cross-chain, signing EIP-712 messages. All write operations have explicit user confirmation steps via Result: Data Exfiltration RiskThe telemetry section in SKILL.md sends device fingerprint data (hostname, OS, architecture, home directory hash) to two external endpoints. While this is for install tracking, the HMAC key is obfuscated via base64 encoding, and the device fingerprint includes potentially identifying information. Result: Overall Security Rating: 🔴 High RiskDue to TF005 (curl|sh + financial operations), C03 (base64 obfuscation in telemetry), and the inherent risk of leveraged perpetual trading. 6. Source Code Security (if source code is included)Language & Build Config
Dependency Analysis
No suspicious, unmaintained, or vulnerable dependencies detected. Code Safety Audit
Does SKILL.md accurately describe what the source code does?Yes — The SKILL.md accurately describes the 7 commands, their parameters, the two-step confirm flow, the signing mechanism via onchainos, and the deposit flow. The source code implementation matches the documented behavior. One minor note: SKILL.md mentions Verdict:
|
| Dimension | Score | Notes |
|---|---|---|
| Completeness (pre-flight, commands, error handling) | 20/25 | Good command coverage with 7 commands. Error handling is thorough with descriptive messages. Pre-flight checks are present but use unsafe patterns (curl|sh). |
| Clarity (descriptions, no ambiguity) | 20/25 | SKILL.md is well-structured with clear command documentation, output examples, and trigger phrases. Parameter descriptions are comprehensive. |
| Security Awareness (confirmations, slippage, limits) | 15/25 | Good: --confirm gate on all writes, preview mode default, TP/SL validation, slippage tolerance (10%), risk warnings for perpetuals. Bad: curl|sh install, base64 obfuscated telemetry key, binary download without checksum verification. |
| Skill Routing (defers correctly, no overreach) | 12/15 | Properly defers to okx-dex-swap for spot swaps, okx-defi-portfolio for portfolio. Does not overreach into other domains. |
| Formatting (markdown, tables, code blocks) | 5/10 | Good use of tables and code blocks. Some sections are verbose. The pre-flight section mixes auto-injected boilerplate with plugin-specific content. |
Strengths
- Excellent confirmation flow: All write operations require
--confirm, with preview as default — strong protection against accidental execution - Proper onchainos integration: All signing and broadcasting goes through onchainos CLI, maintaining the security model
- Comprehensive validation: TP/SL price validation relative to position direction, size validation, balance checks before deposits
Issues Found
- 🔴 Critical: TF005 — curl|sh in SKILL.md with financial operations. The pre-flight section includes
curl -fsSL https://raw.githubusercontent.com/okx/onchainos-skills/main/install.sh | shwhich is in the Agent execution path. For a plugin with financial operations (leveraged trading), this is a critical supply chain risk. The remote script could be modified to inject malicious code. - 🔴 Critical: Binary download without checksum verification. The SKILL.md binary install section downloads the
hyperliquidbinary via curl without any SHA256 checksum verification:curl -fsSL "https://github.com/MigOKG/plugin-store/releases/download/plugins/hyperliquid@0.1.0/hyperliquid-${TARGET}" -o ~/.local/bin/hyperliquid. A MITM attack or repository compromise could serve a malicious binary. - 🟡 Important: Base64-obfuscated telemetry key (C03). The SKILL.md telemetry section contains a base64-encoded HMAC key that is decoded at runtime. While not directly executable, this obfuscation pattern makes auditing harder and matches C03.
- 🟡 Important: Undeclared telemetry endpoints.
plugin-store-dun.vercel.app/installandwww.okx.com/priapi/v1/wallet/plugins/download/reportare not listed inplugin.yamlapi_calls. Device fingerprint (hostname hash) is sent to these endpoints. - 🟡 Important: Unpinned npm package installs (M01/M02).
npx skills add okx/onchainos-skills --yes --globalandnpx skills add MigOKG/plugin-store --skill plugin-store --yes --globallack version pinning. - 🔵 Minor: EIP-712 signing chain mismatch. The
onchainos_hl_signfunction uses--chain 1(Ethereum mainnet) for the EIP-712 signing call, while the EIP-712 domain specifieschainId: 1337. This works because onchainos only needs the chain parameter for address resolution, but it's confusing and could break if onchainos adds chain-specific signing validation. - 🔵 Minor: Arbitrum RPC hardcoded.
ARBITRUM_RPCis hardcoded tohttps://arbitrum-one-rpc.publicnode.comwith no fallback or configurability.
8. Recommendations
-
[CRITICAL] Replace curl|sh install with checksummed download: Download the install script to a file, verify its SHA256 against a published checksum, then execute. Alternatively, use a package manager with version pinning.
-
[CRITICAL] Add binary checksum verification: The binary download in SKILL.md must include SHA256 verification against a published checksums file, similar to how the official onchainos skills handle it.
-
[HIGH] Remove or make telemetry transparent: Either remove the telemetry section entirely, or (a) declare the endpoints in
plugin.yamlapi_calls, (b) remove the base64-obfuscated HMAC key and use a plaintext approach, (c) clearly document what data is collected and why. -
[HIGH] Pin dependency versions: Change
npx skills add okx/onchainos-skills --yes --globaltonpx skills add okx/onchainos-skills@<version> --yes --globalfor both skills installs. -
[MEDIUM] Declare all network endpoints in plugin.yaml: Add
plugin-store-dun.vercel.appandwww.okx.com/priapi/v1/wallet/plugins/download/reportto theapi_callslist. -
[LOW] Make Arbitrum RPC configurable: Allow users to set a custom RPC via environment variable (e.g.,
ARBITRUM_RPC_URL). -
[LOW] Document the EIP-712 chain parameter choice: Add a code comment explaining why
--chain 1is used for Hyperliquid L1 signing (address resolution only, domain chainId 1337 is in the typed data).
9. Reviewer Summary
One-line verdict: Well-engineered Hyperliquid perpetuals plugin with proper onchainos integration and confirmation gates, but blocked by critical supply chain risks (curl|sh install + unverified binary download) in a high-stakes financial context.
Merge recommendation: 🔍 Needs changes before merge
Items that must be addressed:
- Replace
curl | shinstall pattern with checksum-verified download (TF005 / C01) - Add SHA256 checksum verification for binary download
- Remove or de-obfuscate the base64-encoded telemetry HMAC key (C03)
- Pin all
npx skills addcommands to specific versions (M01) - Declare telemetry endpoints in
plugin.yamlapi_calls(L02)
Generated by Claude AI via Anthropic API — review the full report before approving.
❌ Phase 1: Structure Validation — FAILED→ Please fix the errors above and push again. |
803b7e9 to
0a2ee47
Compare
…, add testnet api_calls - Remove --force from wallet_contract_call: let onchainos handle its own confirmation flow; plugin --confirm flag already gates the call - Fix SKILL.md command numbering: deposit was #8, should be #7 - Add testnet endpoint to plugin.yaml api_calls - Update plugin.yaml description to reflect v0.2.0 capabilities Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
637c31c to
c3a7cc2
Compare
Summary
Follow-up to #165. Adds the full trading lifecycle on top of the merged v0.1.0 base:
deposit— bridge USDC from Arbitrum to Hyperliquid L1 viabatchedDepositWithPermit(EIP-2612 permit, no separate approve tx). Verified on-chain:0x10eec96639afeab26bedfcfb73d0588996b1c174c653affd176656dd1d91e515close— one-command market close of an existing position (auto-detects size and direction)tpsl— set stop-loss / take-profit on an existing position (auto-detects position, validates prices, market trigger with 10% slippage tolerance)orderupgrade — adds--sl-px/--tp-pxfor OCO bracket orders (grouping: normalTpsl)HYPERLIQUID_TESTNET=1env var routes all calls to testnetChecklist
cargo build --releasepassesplugin-store lintpassesnormalTpslgrouping accepted)🤖 Generated with Claude Code