ClawDex — Solana DEX Trading Skill
Trade any Solana token through Jupiter aggregator with simulation, safety guardrails, and full JSON output.
Prerequisites
Before using this skill, ensure ClawDex is installed and configured:
CODEBLOCK0
If not configured yet, run onboarding:
clawdex status --json
If status fails, set up with:
CODEBLOCK2
Commands
Check wallet balances
CODEBLOCK3
Returns an array of { token, symbol, mint, balance, decimals } objects. Zero-balance accounts are included in JSON output.
Get a quote (no execution)
CODEBLOCK4
Lightweight price check — no simulation, no wallet needed.
Simulate a swap (dry run)
CODEBLOCK5
Runs full simulation on-chain without broadcasting. Does not require --yes. Use this to preview the output amount and route before committing.
Execute a swap
CODEBLOCK6
--yes is required for non-interactive execution. Without it, ClawDex exits with code 1.
Health check
CODEBLOCK7
Verify RPC connectivity, wallet validity, and config state.
Trading Workflow
Always follow this sequence:
- 1. Health check —
clawdex status --json — abort if rpc.healthy is false - Check balances —
clawdex balances --json — verify sufficient funds - Simulate —
clawdex swap --simulate-only --json — preview the trade - Execute —
clawdex swap --yes --json — only if simulation looks good - Verify —
clawdex balances --json — confirm balances updated (may need 5s delay on public RPC)
Token Specification
Tokens can be passed by symbol or mint address:
- - By symbol:
SOL, USDC, INLINECODE11 - By mint: INLINECODE12
Exit Codes
| Code | Meaning | Agent action |
|---|
| 0 | Success | Continue |
| 1 |
General error | Check message |
| 2 | Config error | Run onboarding |
| 3 | Safety violation | Reduce amount or adjust limits |
| 4 | Simulation failed | Try different pair/amount |
| 5 | Send failed | Retry with backoff |
Safety
Set guardrails to prevent runaway trades:
CODEBLOCK8
When a guardrail triggers, the JSON response includes a violations array describing what failed.
Important Rules
- - Always use
--json for machine-parseable output - Always use
--yes for real swaps (not needed for --simulate-only) - Never skip simulation unless you have a good reason — use
--simulate-only first - Parse
balance as a string, not a number — it preserves full decimal precision - Check exit codes — non-zero means the trade did not succeed
- Wait before verifying — RPC balance reads can lag a few seconds after a swap
ClawDex — Solana DEX 交易技能
通过 Jupiter 聚合器交易任何 Solana 代币,支持模拟、安全防护和完整 JSON 输出。
前置条件
使用此技能前,请确保 ClawDex 已安装并配置:
bash
which clawdex || npm install -g clawdex@latest
如果尚未配置,请运行初始化:
bash
clawdex status --json
如果状态检查失败,请通过以下命令进行设置:
bash
clawdex onboarding \
--jupiter-api-key $JUPITERAPIKEY \
--rpc ${SOLANARPCURL:-https://api.mainnet-beta.solana.com} \
--wallet ~/.config/solana/id.json \
--json
命令
查看钱包余额
bash
clawdex balances --json
返回 { token, symbol, mint, balance, decimals } 对象数组。JSON 输出中包含零余额账户。
获取报价(不执行)
bash
clawdex quote --in SOL --out USDC --amount 0.01 --json
轻量级价格查询——无需模拟,无需钱包。
模拟兑换(试运行)
bash
clawdex swap --in SOL --out USDC --amount 0.01 --simulate-only --json
在链上运行完整模拟但不广播。不需要 --yes 参数。在正式执行前使用此命令预览输出金额和路由。
执行兑换
bash
clawdex swap --in SOL --out USDC --amount 0.01 --yes --json
非交互式执行必须使用 --yes。不加此参数时,ClawDex 将以退出码 1 退出。
健康检查
bash
clawdex status --json
验证 RPC 连接、钱包有效性和配置状态。
交易流程
始终遵循以下顺序:
- 1. 健康检查 — clawdex status --json — 如果 rpc.healthy 为 false 则中止
- 检查余额 — clawdex balances --json — 确认资金充足
- 模拟 — clawdex swap --simulate-only --json — 预览交易
- 执行 — clawdex swap --yes --json — 仅在模拟结果良好时执行
- 验证 — clawdex balances --json — 确认余额已更新(公共 RPC 可能需要 5 秒延迟)
代币规范
代币可通过符号或铸币地址传入:
- - 按符号:SOL、USDC、USDT
- 按铸币地址:EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v
退出码
一般错误 | 检查消息 |
| 2 | 配置错误 | 运行初始化 |
| 3 | 安全违规 | 减少金额或调整限制 |
| 4 | 模拟失败 | 尝试不同的交易对/金额 |
| 5 | 发送失败 | 使用退避策略重试 |
安全
设置防护措施以防止失控交易:
bash
clawdex safety set maxslippagebps=300 maxtradesol=1 maxpriceimpact_bps=100
当触发防护措施时,JSON 响应将包含描述失败原因的 violations 数组。
重要规则
- - 始终使用 --json 以获得机器可解析的输出
- 始终使用 --yes 进行真实兑换(--simulate-only 不需要)
- 除非有充分理由,否则切勿跳过模拟 — 先使用 --simulate-only
- 将 balance 解析为字符串,而非数字 — 以保留完整的十进制精度
- 检查退出码 — 非零值表示交易未成功
- 等待后再验证 — RPC 余额读取在兑换后可能会有几秒延迟