Clawd twamm

From x402agent/solana-clawd · View interactive version

Clawd twamm is an AI agent skill from the GitHub repository x402agent/solana-clawd. Time-Weighted AMM crank automation for the Clawd agent. Use when scheduling large spot orders to execute at the time-weighted oracle price with near-zero slippage, operating the permissionless on-chain TWAMM crank program.

How to use this skill

Skill file

clawd-twamm

Use this skill when the user wants to:

What TWAMM Is

TWAMM (Time-Weighted Automated Market Maker) is an Anchor program that executes orders as infinitely many infinitesimal swaps over a time window. The result: the average fill price tracks the time-weighted oracle price, eliminating the price impact a large single swap would cause.

Key trade-off: near-zero slippage vs deferred fill — orders are not immediate.

Workspace Setup

# Check workspace status (finds perps/twamm-master automatically)
clawd perps twamm status

# Build the Anchor program
clawd perps twamm build

# Preview what the crank command will run
clawd perps twamm plan --token-a <MINT_A> --token-b <MINT_B>

Environment variables:

Running the Crank

The crank is gated — all three must be set before a live run:

CLAWD_TWAMM_LIVE=true OPERATOR_CONFIRMED=true \
  clawd perps twamm crank --token-a <MINT_A> --token-b <MINT_B> --yes

Never pass --yes without confirming the operator has reviewed the crank parameters.

Agent API (ClawdPerpsRuntime)

const runtime = new ClawdPerpsRuntime();

// Check TWAMM workspace status
const status = runtime.getTwammStatus();

// Build a crank plan (dry-run, shows exact command)
const plan = runtime.buildTwammCrankPlan({ tokenAMint, tokenBMint });

// Preview a TWAMM-scheduled execution for a large order
const preview = runtime.previewTwammExecution("SOL", "buy", 50_000);
// preview.twamm = the crank plan
// preview.route.payload.blocked = true until CLAWD_TWAMM_LIVE=true

Integration with Perps Aggregator

The clawd-perps-aggregator exposes "twamm" as a VenueId. When routing a large order:

import { buildVenueAdapters, ImperialTransport } from "@openclawdsolana/clawd-perps-aggregator";

const adapters = buildVenueAdapters(transport, ["phoenix", "twamm"]);
// TWAMM adapter returns slippageBps ≤ 2 for any size

When to Prefer TWAMM over Immediate Execution

| Scenario | Use TWAMM |

|---|---|

| Order > $50k notional | ✓ recommended |

| Thin orderbook / high slippage | ✓ recommended |

| Requires immediate fill | ✗ use Phoenix CLOB |

| Perps position (levered) | ✗ use Vulcan TWAP |

For perps TWAP execution use vulcan-twap-execution (Vulcan's built-in strategy runner).

Safety

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.