---
name: swap
description: Dedicated swap execution skill for Robinhood Chain (4663). Use when the user says "swap", "buy", "sell", "trade PONS/NVDA/any token", "exchange ETH for", "DCA into", "take profit", "stop loss", or wants order automation (DCA plans, bracket orders). Covers the full non-custodial lifecycle — token safety scan, quote, route decoding, allowance management, calldata building, signing in the user's wallet, receipt proof — plus DCA and TP/SL order patterns and the safety engine.
allowed-tools: Read, Write, Edit, Glob, Grep, Bash(npm:*), Bash(npx:*), Bash(curl:*), Bash(python:*)
license: MIT
metadata:
  author: clusteragent
  version: "1.1.0"
title: swap
canonical_url: https://skilld.dev/gh/clusteragent/cluster/swap
last_updated: 2026-09-21T00:45:59.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> If the user asked to install this Skill, run `npx skilld install clusteragent/cluster/swap`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/swap`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/clusteragent/cluster/swap) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/swap`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/swap --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/swap --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

# Swap — Robinhood Chain

Non-custodial swaps on chain 4663: the cluster API quotes and builds calldata,
**the user's wallet signs**. No private keys ever touch the server.

## Decision Flow

```
user wants to swap
  ├── token known? ──no──▶ resolve: quotes / DexScreener search / ask user for CA
  ├── safety check (token_safety tool) ──▶ HIGH RISK? warn + confirm before proceeding
  ├── quote (quote_swap tool) ──▶ "no route"? see Factory Caveat
  ├── show: route, min received @slippage, price impact
  ├── allowance check (sell only) ──▶ insufficient? approval tx FIRST, separately
  ├── build calldata (below) ──▶ user signs ──▶ broadcast
  └── receipt proof ──▶ report ACTUAL received, not the quote
```

## Chain Constants

| Contract | Address |
|----------|---------|
| SwapRouter02 | `0xcaf681a66d020601342297493863e78c959e5cb2` |
| QuoterV2 | `0x33e885ed0ec9bf04ecfb19341582aadcb4c8a9e7` |
| WETH | `0x0Bd7D308f8E1639FAb988df18A8011f41EAcAD73` |
| USDG | `0x5fc5360D0400a0Fd4f2af552ADD042D716F1d168` |
| Permit2 | `0x000000000022D473030F116dDEE9F6B43aC78BA3` |
| V4 Universal Router | `0x8876789976decbfcbbbe364623c63652db8c0904` |

Fee tiers: **100 / 500 / 3000 / 10000**.

## Token Safety Scan (always first for unknown tokens)

Use the `token_safety` MCP tool (or replicate):

```bash
curl "https://api.dexscreener.com/latest/dex/tokens/0xTOKEN"   # liq + txn flow
```

Scoring heuristics (from finchagentic's risk engine):

| Signal | Score | Flag |
|---|---|---|
| Liquidity < $1k | +30 | 🔴 Very low liquidity |
| Liquidity < $25k | +12 | 🟠 Thin liquidity |
| buys > 10 AND sells == 0 (24h) | +40 | 🔴 Honeypot heuristic |
| Contract unverified (explorer) | +20 | 🔴 Not verified |
| Holder count < 25 | +25 | 🔴 Concentration / rug risk |
| Contract name has mint/blacklist/tax/pausable | +14 | 🟠 Owner privileges |

Tier: `score ≥ 40` = HIGH RISK, `≥ 15` = CAUTION, else OK. **HIGH RISK = ask the
user to explicitly confirm before quoting.** Not an audit — heuristic only.

## Factory Caveat (critical on 4663)

Two V3 factories live on this chain:

- **Canonical** — pools routable by SwapRouter02. Quotes work. ✔
- **Pons launchpad factory** (`0x1f7d7550b1b028f7571e69a784071f0205fd2efa`) — most
  pons-ecosystem tokens (SWOGE, FINCH, RHAGENT, NOXA, PONSTR, ARENA, …). QuoterV2
  reverts; SwapRouter02 **cannot** route these.

If `quote_swap` returns `"no route"`: check `factory()` on the token's DexScreener
pool. Launchpad-factory tokens need the **V4 Universal Router + Permit2** (or the
pons launchpad UI). Do not retry forever.

## Quote → Calldata

```bash
# buy: 0.01 ETH → token (amount in wei)
curl "https://clusteragent.dev/api/trade/quote?token=0xTOKEN&side=buy&amount=10000000000000000"
# → { "ok": true, "path": "0x…", "label": "WETH/500/USDG/3000", "amountOut": "…" }
```

**Buy** (ETH in — router pays the first WETH hop from msg.value; wrapping first
reverts with STF):

```
multicall([ exactInput({ path, recipient: USER, amountIn, amountOutMinimum }),
            refundETH() ])
→ { to: ROUTER, value: amountIn }
```

**Sell** (token in → ETH out): approval first if `allowance(USER, ROUTER) < amount`,
then:

```
multicall([ exactInput({ path, recipient: ROUTER, amountIn, amountOutMinimum }),
            unwrapWETH9(minOut, USER) ])
→ { to: ROUTER, value: 0 }
```

`amountOutMinimum = quote × (10000 − bps) / 10000`. Default slippage **200 bps**;
thin crypto pools need more. Python one-liner: `c.build_swap_calldata(...)` in the
`cluster-agent` SDK.

## Receipt Proof

A quote is a prediction; the receipt is proof. After broadcast:

1. Poll `eth_getTransactionReceipt` (~4s interval, 3min timeout)
2. `status == 0x1`? else report revert — usually slippage
3. **Buy**: sum `Transfer(_, user, value)` logs from the bought token
   (topic0 `0xddf252ad…b3ef`, topic2 = user). That sum = actually received.
4. **Sell**: `balanceAfter − balanceBefore + gasBurned` = actually received.
5. Report **both** quote and actual. Divergence = real fill information.

## DCA & Bracket Orders (automation pattern)

Cluster's MCP has no order engine yet — automate it yourself from the skill, or
run a scheduler. The proven shape (finchagentic rh-orders):

**DCA plan**: buy a fixed ETH amount every N hours, hard cap on total ETH spent.

```python
# every tick: if due and total_spent < cap → quote_swap → build → (dry-run | sign)
```

**Bracket (TP/SL)**: on a token you HOLD — watch DexScreener price; take-profit
above entry, stop-loss below; sell `pct_of_balance` on trigger (default 100%).

**Tick loop** rules (learned the hard way):

- Quote fresh at execution time — never reuse a stored quote
- Dry-run by default; real broadcast only behind an explicit confirm flag
- Nonce: `eth_getTransactionCount(addr, "pending")` so sequential swaps don't collide
- Persist orders to disk; survive restarts; cancel = stop future ticks only

## Safety Rules

1. Safety scan before quoting unknown tokens; HIGH RISK needs explicit user confirm
2. Never exceed the user's stated amount; MAX = balance minus gas, confirmed
3. Show route + min received + price impact BEFORE signing
4. Sell: check allowance first; approval is its own transaction
5. `no route` = factory mismatch — report it, don't hammer
6. Report actual received from the receipt, every time
