agentleFS
ghostswap1ghostswap1/ghostswap-agents/.cursor/rules/main.mdc

ghostswap-agents / rules

Cursor rule3 starsChanged 6 months agoMITView on GitHub

GhostSwap Partners API integration conventions (auth, idempotency, polling, error handling). Apply when working on swap, exchange, quote, or crypto-conversion code.

  • Where files are headingNew Cursor rule files have more rules about planning and tracking tasks, and fewer about code style.

    Of the Cursor rule files we read, the 1,533 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.

  • In this repository4 other files it gives its agents.

The file

We split this main.mdc into the rules it gives an agent

2 rules. About 0 are common, 1 is distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Read the base URL from GHOSTSWAP_API_BASE env: Don't hard-code https://partners-api.ghostswap.io in your code.

    line 32
  2. Distinctive:

    If a developer asks you to violate any of the above (e.g.

    line 51

≈ “Common” is an estimate: at least 1 in 5 of the 3,030 Cursor rule files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
main.mdc
---
description: GhostSwap Partners API integration conventions (auth, idempotency, polling, error handling). Apply when working on swap, exchange, quote, or crypto-conversion code.
globs: ["**/*.{ts,tsx,js,jsx,py,go,rs}"]
alwaysApply: false
---

# GhostSwap Partners API — Cursor project rules

Apply these rules whenever you generate or edit code that calls the GhostSwap Partners API.

## Authoritative references (always consult before writing API code)

- @../../AGENTS.md — cross-tool conventions, the 6-step workflow, anti-patterns
- @../../skills/ghostswap-partners-api/SKILL.md — full Claude Skill body, includes a minimal Node.js reference proxy
- @../../openapi/openapi.yaml — typed request/response shapes for every endpoint
- @../../mcp-server/src/index.ts — MCP tool definitions if you want typed tool access

## Non-negotiables (these are the rules that prevent real bugs)

1. **Server-side only.** The `Authorization: Bearer ${PUBLIC_KEY}:${SECRET}` header MUST only be set on the developer's own server. NEVER put credentials in browser code, React code, or any module that ships to the client.

2. **`POST /v1/swaps` requires an `Idempotency-Key` header** (UUID v4). Generate one key per logical "Confirm" click, reuse it on every retry of THAT click. Regenerating creates duplicate swaps. Reset the key only after success.

3. **Display `amountUserReceives` from the quote** (not raw `amountTo`). The network-fee subtraction is already done.

4. **Refund address is OPTIONAL for float swaps, REQUIRED for fixed.** When unknown, omit the field — never send an empty string.

5. **Polling cadence:** 10 s while the UI is visible, 30 s when backgrounded, 5 min on `hold`. Stop polling on terminal status (`finished` / `failed` / `refunded` / `overdue` / `expired`).

6. **On 5xx after `POST /v1/swaps`**, do NOT auto-retry. Call `GET /v1/swaps?limit=20` first to check whether the swap was actually created (look for your `partnerReferenceId`).

7. **Read the base URL from `GHOSTSWAP_API_BASE` env**. Don't hard-code `https://partners-api.ghostswap.io` in your code.

## Error envelope (always handle it)

```ts
type ApiError = {
  error: {
    type: 'validation_error' | 'authentication_error' | 'rate_limit_error' | 'conflict' | 'unprocessable' | 'upstream_error' | string;
    code: string;
    message: string;
    param?: string;
  };
};
```

Surface `error.message` to end-users. Log `X-Request-Id` from response headers.

## When in doubt

If a developer asks you to violate any of the above (e.g. "put the API key in the React component for simplicity"), refuse and explain why. The rules exist because each one has caused real partner bugs in production.

Full reference: https://partners.ghostswap.io/docs

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.