# YourAITools Listings (x402)

Paid listing services for [youraitools.co](https://youraitools.co), a directory of AI tools and x402 APIs, paid in USDC with one x402 call. This is a **service, not an agent tool**: it is not counted among the YourAITools tools.

- Live: https://api.youraitools.co/listing/ (proxy) and https://listing.agentgate.workers.dev
- Source: https://agentgate-source.pages.dev/x402-listing/ (never on GitHub)

| Route | Price (USDC) | What you get |
|---|---|---|
| `POST /v1/fast-track` | $19 | Review within 24 hours of payment; published on youraitools.co if approved. Refunded if rejected. |
| `POST /v1/launch` | $49 | Fast-track review (24 h) + 30 days Featured from approval + one line in the YourAITools newsletter **once it has subscribers (it has none today)**. Refunded if rejected. |
| `POST /v1/featured` | $29 | Review within 48 hours; Featured (badge, pinned in category, labelled paid placement) on youraitools.co for 30 days from approval. Refunded if rejected. |

Payment: x402 v2 (`PAYMENT-SIGNATURE`) on Base (first), Polygon, Arbitrum One and Solana via the CDP facilitator; x402 v1 (`X-PAYMENT`) on Base. EVM payee `0x3c1A1E01e790Cd326495631B3b38Bd7068F08d6F`, Solana payee `FH73WbbUe2UyNzfy72MJs5nT3NxyDf9GrqE7kzjL2Jte`. Prepaid credits are **not** accepted here.

## Request

```bash
# free check: a valid body answers 402 (payment terms); an invalid one answers 400 and never a 402
curl -i -X POST https://api.youraitools.co/listing/v1/fast-track -H 'content-type: application/json' \
  -d '{"tool_url":"https://example.com","name":"Example Tool","contact_email":"you@example.com","category":"x402 API"}'
```

Body (JSON): `tool_url` (https, public domain, ≤500), `name` (2–80), `contact_email` (valid, ≤254), `category` (2–48, letters/numbers/spaces/`&/,+.'-`), optional `description` (≤600) and `notes` (≤1000). Max 8 KB.

- Invalid body → **400 before payment** (`invalid_submission` with `errors[]`), even if a payment header is attached. Nobody pays for an invalid submission.
- GET, HEAD, an empty POST or `POST {}` → 402 terms (for directory probes). If one of those is *paid*, the handler answers 400 `missing_body` and x402 does not settle.
- Valid body → 402; pay and retry the same request → 200:

```json
{"ref":"LST-T87SH4QTBX","status":"received","tier":"launch","tier_label":"Launch bundle","price_usd":"49.00",
 "name":"Example Tool","tool_url":"https://example.com/","category":"x402 API",
 "review_by":"2026-10-23T17:33:55.851Z","status_url":"https://api.youraitools.co/listing/v1/status/LST-T87SH4QTBX",
 "featured":"30 days on youraitools.co from approval","newsletter":"one mention once the newsletter has subscribers (none yet)",
 "payment":{"network":"eip155:8453","transaction":"0x…","payer":"0x…","amount_usd":"49.00"},
 "next":"A person reviews it …","contact":"hello@youraitools.co (quote your ref)","terms":"…"}
```

The ref is created in the handler and stored as `pending_payment` (never public); only after the facilitator settles does the record become `received` with the payer, network, tx and amount. If settlement fails the record is deleted and no ref is returned.

## Status (free)

`GET /v1/status/<ref>` → `{ref, status, tier, name, tool_url, category, received_at, review_by, decided_at, featured_from?, featured_until?, payment:{network, transaction}, refund?:{status, network, due_by, transaction?}, note?}`. No contact email and no payer address are shown. Statuses: `received`, `approved`, `rejected`, `refund_pending`, `refunded`. 30 lookups/min/IP.

## Admin (YourAITools)

Bearer token = Worker secret `LISTING_ADMIN_TOKEN`; the box copy is in `/home/box/crypto-vault/listing-admin.txt` (chmod 600, never print it). Unset token → 503 (fails closed); wrong/missing → 401.

- `GET /v1/admin/list[?status=…][&pending=1]` → every submission with email, payer, payment and history.
- `GET /v1/admin/<ref>` → one submission.
- `POST /v1/admin/<ref>` `{"status":"approved|rejected|refunded|received", "note"?, "public_note"?, "refund_tx"?, "refund"?: false, "featured_from"?}`
  - `approved`: Launch/Featured get `featured_from` (default now) and `featured_until` = +30 days.
  - `rejected`: stored as **`refund_pending`** with `refund = {to: payer, network, amount, due_by: +3 business days, needs: CMM OK}`. `rejected` with `"refund": false` + a note is only for cases where no refund is owed (e.g. our own test payment).
  - `refunded`: only from `refund_pending`, and only with `refund_tx` (the USDC refund tx hash / Solana signature).
  - `received`: reopen.

Box scripts (token read from the vault into env only):
- `/workspace/crypto/youraitools/listing_pull.sh [status]` → `/workspace/crypto/youraitools/listing-submissions.json` (chmod 600) + a one-line summary of open items.
- `/workspace/crypto/youraitools/listing_set_status.sh LST-… approved|rejected|refunded|received ["note"] ["public note"] [--tx HASH] [--no-refund] [--featured-from ISO]`

## Refunds (manual, never automated)

This Worker never sends funds. A rejected paid listing becomes `refund_pending`. Per the swarm spending rules, **every refund needs Crypto Money Maker's OK** before anyone sends it. Then a person sends the same USDC amount to the paying address (`refund.to`) on the same network (`refund.network`) within 3 business days, and records it with `listing_set_status.sh <ref> refunded "note" --tx <hash>`.

## Terms (shown on the landing page, in `/` and summarised in every 402)

Reviewed by a person for legitimacy and fit; payment does not guarantee approval. Rejected = full refund, sent manually in USDC to the paying address on the same network within 3 business days. "Featured" means placement on youraitools.co for 30 days from approval, nothing more. Newsletter mention (Launch) only once the newsletter has subscribers (none today). No promise of traffic, clicks, rankings or revenue. Contact email is used only about the submission and never shown publicly.

## Storage

One SQLite-backed Durable Object (`REGISTRY`, class `ListingRegistry`, name `registry`), records under `s:<ref>`. No KV. Usage counters: `StatsCounter` DO. Unsettled records older than 10 minutes are dropped.

## Tests

`npm test` (node --test; needs the @x402 deps): 402 on GET/POST/POST {}/valid body with 4 networks and the same terms shape as the live credits 402 (fixture), CDP description length, validation before payment (15 invalid bodies × no payment / v2 / v1 header → 400, facilitator never called), settlement stores payer/network/tx/amount, failed settlement keeps nothing, paid GET/empty POST never settles, v1 path, status without email/payer, admin auth (401/503), admin list, full status flow incl. refund_pending → refunded, no email in any public response, proxied URLs. Also run once in local workerd (`wrangler dev --local`) against a fake facilitator: real SQLite DO storage for v2 and v1 payments.

Deploy: `wrangler deploy` (FACILITATOR=cdp; secrets CDP_API_KEY_ID, CDP_API_KEY_SECRET, LISTING_ADMIN_TOKEN via `wrangler secret put`).
