|
| 1 | +--- |
| 2 | +name: stx-pox-delegate |
| 3 | +description: "Authorize and revoke PoX-4 stacking delegation on Stacks mainnet — the write companion to read-only stacking monitors." |
| 4 | +metadata: |
| 5 | + author: "lekanbams" |
| 6 | + author-agent: "Lekan Bams" |
| 7 | + user-invocable: "true" |
| 8 | + arguments: "doctor | status | delegate --delegate-to <addr> --amount-stx <n> [--until-burn-ht <h>] [--confirm] | revoke [--confirm]" |
| 9 | + entry: "stx-pox-delegate/stx-pox-delegate.ts" |
| 10 | + requires: "wallet, signing, settings" |
| 11 | + tags: "l2, write, mainnet-only, requires-funds, infrastructure" |
| 12 | +--- |
| 13 | + |
| 14 | +# STX PoX Delegate |
| 15 | + |
| 16 | +## What it does |
| 17 | + |
| 18 | +Broadcasts `delegate-stx` and `revoke-delegate-stx` calls to the canonical Stacks PoX-4 contract (`SP000000000000000000002Q6VF78.pox-4`). This is the write side of stacking delegation: solo stacking requires 80k+ STX, so most STX holders earn PoX yield by delegating to a stacking pool. This skill performs that authorization on-chain. |
| 19 | + |
| 20 | +This is the write companion to the read-only `stacking-delegation` skill in this registry — that one monitors, this one acts. |
| 21 | + |
| 22 | +## Why agents need it |
| 23 | + |
| 24 | +An autonomous yield agent on Stacks needs a programmatic way to opt into PoX-4 stacking via a pool. Without this, every delegation step requires a human wallet popup. With it, the agent can: check current delegation, decide whether to (re)delegate based on signals from monitors like `stacking-delegation` or `hodlmm-risk`, and broadcast the authorization with explicit safety gates. |
| 25 | + |
| 26 | +## Safety notes |
| 27 | + |
| 28 | +- **Mainnet write.** Calls a public PoX-4 function. Real STX gas is spent (~0.001 STX per tx). |
| 29 | +- **Funds stay in your wallet.** `delegate-stx` is a non-custodial signaling call — it authorizes a pool to lock up to `amount-ustx` of your STX in a future `delegate-stack-stx` call, but does not move or lock funds at delegate time. The agent that runs the actual stacking is the principal you pass via `--delegate-to`. Choose pools you trust. |
| 30 | +- **Double-confirmation required.** `delegate` and `revoke` are no-ops without `--confirm`; without it the skill returns a dry-run preview. This is intentional — accidental delegation to a malicious principal would let that principal stack your STX without further consent. |
| 31 | +- **Post-conditions.** `delegate-stx` is a no-asset Clarity call (it touches no fungible balances at signing time), so the broadcast uses `PostConditionMode.Deny` with an empty `postConditions` array. This is correct for this specific call shape — there is nothing to constrain — and is documented here to preempt the standard reviewer flag against empty-deny on swaps. |
| 32 | +- **Refusal conditions.** The skill refuses if: amount < 1 STX (micro-amount), amount > 95% of wallet balance (no gas left), `--until-burn-ht` is in the past or within 10 burn blocks, `--delegate-to` parses as something other than a Stacks principal, or wallet balance is below 0.01 STX (insufficient gas). |
| 33 | +- **No fabricated identifiers.** The pox-4 contract address is the canonical Stacks built-in (`SP000000000000000000002Q6VF78.pox-4`); the function signature is verified against `https://api.hiro.so/v2/contracts/interface/SP000000000000000000002Q6VF78/pox-4`. |
| 34 | + |
| 35 | +## Commands |
| 36 | + |
| 37 | +| Command | Description | |
| 38 | +|---------|-------------| |
| 39 | +| `doctor` | Hiro API health, wallet presence, current PoX cycle. No password needed. | |
| 40 | +| `status` | Read-only `get-delegation-info` for the active wallet. No password needed. | |
| 41 | +| `delegate` | **Write.** Calls `pox-4.delegate-stx`. Requires `--delegate-to`, `--amount-stx`, `--password`, `--confirm`. | |
| 42 | +| `revoke` | **Write.** Calls `pox-4.revoke-delegate-stx`. Requires `--password`, `--confirm`. | |
| 43 | + |
| 44 | +```bash |
| 45 | +# Preflight |
| 46 | +bun run skills/stx-pox-delegate/stx-pox-delegate.ts doctor |
| 47 | +bun run skills/stx-pox-delegate/stx-pox-delegate.ts status |
| 48 | + |
| 49 | +# Dry-run preview (no broadcast) |
| 50 | +bun run skills/stx-pox-delegate/stx-pox-delegate.ts delegate \ |
| 51 | + --delegate-to SP21YTSM60CAY6D011EZVEVNKXVW8FVZE198XEFFP \ |
| 52 | + --amount-stx 1 \ |
| 53 | + --password "$WALLET_PASSWORD" |
| 54 | + |
| 55 | +# Real broadcast |
| 56 | +bun run skills/stx-pox-delegate/stx-pox-delegate.ts delegate \ |
| 57 | + --delegate-to SP21YTSM60CAY6D011EZVEVNKXVW8FVZE198XEFFP \ |
| 58 | + --amount-stx 1 \ |
| 59 | + --password "$WALLET_PASSWORD" \ |
| 60 | + --confirm |
| 61 | + |
| 62 | +# Revoke active delegation |
| 63 | +bun run skills/stx-pox-delegate/stx-pox-delegate.ts revoke \ |
| 64 | + --password "$WALLET_PASSWORD" \ |
| 65 | + --confirm |
| 66 | +``` |
| 67 | + |
| 68 | +## Output contract |
| 69 | + |
| 70 | +All outputs are JSON to stdout. Errors go to stderr. |
| 71 | + |
| 72 | +**Success:** |
| 73 | +```json |
| 74 | +{ |
| 75 | + "status": "success", |
| 76 | + "action": "delegate", |
| 77 | + "data": { |
| 78 | + "txid": "0x...", |
| 79 | + "explorer": "https://explorer.hiro.so/txid/0x...?chain=mainnet", |
| 80 | + "sender": "SP...", |
| 81 | + "delegateTo": "SP...", |
| 82 | + "amountUstx": "1000000", |
| 83 | + "untilBurnHt": null |
| 84 | + }, |
| 85 | + "error": null |
| 86 | +} |
| 87 | +``` |
| 88 | + |
| 89 | +**Dry-run (no `--confirm`):** |
| 90 | +```json |
| 91 | +{ |
| 92 | + "status": "blocked", |
| 93 | + "action": "delegate", |
| 94 | + "data": { "preview": { ... }, "next": "rerun with --confirm to broadcast" }, |
| 95 | + "error": null |
| 96 | +} |
| 97 | +``` |
| 98 | + |
| 99 | +**Error:** |
| 100 | +```json |
| 101 | +{ "error": "descriptive message" } |
| 102 | +``` |
| 103 | + |
| 104 | +## Known constraints |
| 105 | + |
| 106 | +- **Mainnet only.** PoX-4 testnet uses a different deployer; this skill targets mainnet `SP000000000000000000002Q6VF78.pox-4`. |
| 107 | +- **Wallet must be the AIBTC MCP wallet** at `~/.aibtc/wallets/<id>/keystore.json` (AES-256-GCM + scrypt format), or `STACKS_PRIVATE_KEY` env var for automation. |
| 108 | +- **No `--pox-addr` parameter exposed.** The optional BTC reward address is a power-user feature most pools set themselves; surfacing it here would let an agent send rewards to an arbitrary BTC address, which is a footgun. Add via a follow-up if a pool requires it. |
| 109 | +- **No `delegate-stack-stx`.** That call is what pools execute against your delegation; it is not what an end-user delegator broadcasts. This skill covers the delegator side only. |
0 commit comments