Castor Docs
← Website
Get started

Castor docs

Castor is buyer protection for AI agents paying over x402 on Solana. Sellers lock a USDC bond. When a paid call leaks (times out, errors, breaks its schema or comes back empty) the agent is refunded from that bond in seconds. Sellers are still paid instantly.

Rolling out with the $CSTR launch. Package names, program IDs and final parameters are published on @castoronsol and in this reference as each part goes live.

How it works

Castor never holds the agent's payment. The seller's bond is the guarantee, so small calls stay as fast as plain x402.

  1. 1
    Seller builds the dam. The seller deposits USDC into a bond account and registers its endpoints with their price, checks and output schema.
  2. 2
    Agent pays through a watcher. The agent sends a normal x402 request. A Castor watcher forwards it, settles the payment straight to the seller and receives the response.
  3. 3
    Checks run, leaks get refunded. The watcher runs the endpoint's leak checks. Clean responses go to the agent. A failed check produces a signed leak report, and the program refunds the agent from the seller's bond.

Quickstart: sellers

1. Install the middleware.

npm install @castor/seller

2. Protect an endpoint. Wrap any x402 route. Declare a price, the checks you accept and, for schema, the JSON Schema of your response.

import { castor } from "@castor/seller";
import weatherSchema from "./weather.schema.json";

app.use("/api/weather", castor.protect({
  price: "0.01 USDC",
  checks: ["timeout:3s", "status", "schema", "empty"],
  schema: weatherSchema,
}));

3. Build the dam. Connect Phantom in the Castor app, open Seller dashboard → Bond and deposit USDC. Your endpoints get the Castor badge as soon as the bond covers the minimum.

Quickstart: agents

npm install @castor/agent
import { withCastor } from "@castor/agent";

const pay = withCastor(x402Client, {
  onlyProtected: true,
  onRefund: (r) => console.log("refunded", r.amount, r.reason),
});

const res = await pay.fetch("https://api.example.com/weather");

With onlyProtected on, the client refuses to pay endpoints without a live Castor bond. Refunds land in the paying wallet; no claim step.

Leak checks

Only checks a machine can prove. Sellers choose which ones apply to each endpoint; agents see them in the catalog before paying.

CheckConfigFires when
timeouttimeout:3sNo complete response inside the declared window
statusstatusAny 4xx or 5xx after the payment settled
schemaschema + JSON SchemaThe body fails validation against the published schema
emptyempty200 OK with an empty body, null or an empty object/array

Bonds & coverage

  • Bonds are USDC. Protection never depends on a token price.
  • Coverage is capped by the bond. A refund can never exceed what is left in the seller's bond. Agents see live coverage per endpoint in the catalog.
  • Minimum bond. Below the minimum [VALUE TBD] the badge is removed until the seller tops up.
  • Withdrawals have a cooldown. Sellers request a withdrawal and wait [PERIOD TBD], so the dam can't be drained right before a run of leaks.
  • Backstop. From Phase 04, the $CSTR backstop pool covers refunds a dry bond can't.

Watchers

A watcher is an x402 facilitator that sits in the payment path. Because it sees both the payment and the response first-hand, a refund is triggered by what actually happened, not by what the agent claims.

  • Phase 01: Castor runs the watcher and signs leak reports.
  • Phase 02: anyone can run a watcher by staking $CSTR. A leak report needs a quorum of watcher signatures; signing a false report is slashed.

Beaver Score

Every protected endpoint gets a public score in the catalog. Agents use it to choose who to pay; sellers use it to climb the rankings.

Leak rate
Share of paid calls that leaked
Bond size
How much water the dam holds
Vouchers
$CSTR delegated by stakers
Track record
Age and volume of protected calls

Seller SDK

castor.protect(options)

OptionTypeDescription
pricestringPrice per call in USDC, e.g. "0.01 USDC"
checksstring[]Leak checks for this endpoint
schemaJSONSchemaOutput schema; required with the schema check
bondPublicKey?Bond account to cover this endpoint; defaults to the seller's main bond

Agent SDK

withCastor(x402Client, options)

OptionTypeDescription
onlyProtectedbooleanRefuse to pay endpoints without a live bond
minScorenumber?Skip endpoints below this Beaver Score
maxPricestring?Never pay more than this per call
onRefund(refund) => voidCalled with amount, reason and transaction when a refund lands

On-chain program

An Anchor program on Solana. Program ID: [coming soon]

Accounts
  • SellerBond USDC vault, coverage, withdrawal request
  • Endpoint URL hash, price, checks, schema hash
  • LeakReport payment tx, failed check, watcher signatures
Instructions
  • init_bond · deposit
  • request_withdraw · withdraw
  • register_endpoint
  • submit_leak_report → refund

$CSTR

Every beaver has a job. Contract address: [coming soon]

RoleWhat you doWhat you get
WatcherStake, run a node, co-sign leak reportsFees; slashed for false reports
ArbiterStake, judge disputes on big paymentsFees; slashed against the honest majority
Second damStake in the backstop poolCut of protection fees; covers dry bonds
VoucherDelegate to sellers you trustShare of their fees; bitten if they leak
SellerHold or stakeLower fees, catalog boost, faster badge
AgentStakeHigher coverage per call, premium checks
HolderVoteGovern checks, fees, bonds; buybacks from fees

FAQ

Can an agent fake a refund?
No. Refunds follow what watchers observed, never what the agent claims.
Do sellers wait for their money?
No. Payments settle to the seller instantly; the bond is the guarantee.
What about large payments?
From Phase 03, payments above a threshold use escrow with a challenge window and staked arbiters.
Where do I report a bug?
Open an issue on GitHub or reach us on X.
← Back to castor website GitHubX @castoronsol