> ## Documentation Index
> Fetch the complete documentation index at: https://docs.rach.finance/llms.txt
> Use this file to discover all available pages before exploring further.

# Stablecoin swaps

> Swap a customer's USDT for USDC (or back) on the same chain, or move it across chains, from TRON USDT to Base USDC for example, with refunds always returning to the customer.

Rach swaps your customers' stablecoins two ways:

| | Same-chain swap | Cross-chain swap |
| - | - | - |
| What | USDT ↔ USDC on one EVM chain | USDT/USDC on one chain → USDT/USDC on another, or USDT ↔ USDC on Solana |
| Chains | Polygon, Base, Ethereum, BNB Chain | Polygon, Base, Ethereum, BNB Chain, TRON, Solana |
| How | Rach's swap contract, in one sponsored transaction | NEAR Intents, with a signed quote and automatic refund |
| Endpoint | `POST /v1/swaps` | `POST /v1/swaps/cross-chain` (signed) |
| Typical time | One block | About 1–3 minutes |

Either way, Rach pays the gas and the customer needs no native token.

## Same-chain swaps

```bash theme={null}
curl -X POST https://api.rach.finance/caas/v1/swaps \
  -H "X-API-Key: $RACH_API_KEY" -H "Content-Type: application/json" \
  -d '{
    "customer_ref": "cus_8f2a91",
    "chain": "bsc",
    "token_in": "USDT",
    "token_out": "USDC",
    "amount": "500",
    "idempotency_key": "convert-7781"
  }'
```

The output lands in the same customer's address on the same chain. The result arrives as
`swap.settled` or `swap.failed` ([Webhooks](https://docs.rach.finance/guides/webhooks.md#caas-webhooks)), or poll
`GET /v1/swaps/{id}`.

## Cross-chain swaps

### 1. Quote (optional, reserves nothing)

`POST /v1/swaps/cross-chain/quote` with your API key:

```json theme={null}
{
  "customer_ref": "cus_8f2a91",
  "from_chain": "tron",  "from_token": "USDT",
  "to_chain": "base",    "to_token": "USDC",
  "amount": "250"
}
```

```json theme={null}
{
  "from_chain": "tron", "from_token": "USDT", "to_chain": "base", "to_token": "USDC",
  "amount": "250.000000",
  "fee": "…",
  "total_debited": "…",
  "expected_out": "249.490000",
  "min_out": "246.990000",
  "recipient": "0x8a3f…41",
  "to_customer": true,
  "estimated_seconds": 80,
  "available": "1310.000000",
  "sufficient_balance": true
}
```

* `amount` is what goes into the swap. Rach's flat fee for the **origin** chain comes on top, as
  for a [payout](https://docs.rach.finance/guides/caas-payouts.md).
* `expected_out` is the likely output. `min_out` is the least the customer will receive: if the
  swap cannot deliver at least that much, it is refunded instead.
* The output goes to the customer's **own address on `to_chain`** unless you pass `to_address`
  (any valid address on that chain).
* `slippage_bps` is optional: default `100` (1%), maximum `500`.

### 2. Swap (signed)

Send the same body to `POST /v1/swaps/cross-chain`, signed with your
[payout key](https://docs.rach.finance/guides/caas-payout-signing.md) and carrying an `Idempotency-Key`. Add a `reference` if
you want one echoed back.

```json theme={null}
{
  "id": "xsw_5d0e…",
  "reference": "convert-7781",
  "customer_ref": "cus_8f2a91",
  "from_chain": "tron", "from_token": "USDT", "to_chain": "base", "to_token": "USDC",
  "amount": "250.000000", "fee": "…", "total_debited": "…",
  "expected_out": "249.490000", "min_out": "246.990000",
  "recipient": "0x8a3f…41", "to_customer": true,
  "deposit_address": "TXq…",
  "payout_id": "po_77c1…",
  "status": "DEPOSITING",
  "quote_deadline": "2026-11-21T09:55:00Z",
  "created_at": "2026-11-21T09:25:00Z",
  "updated_at": "2026-11-21T09:25:00Z"
}
```

What happens next:

1. Rach requests a quote from NEAR Intents. The refund address is always the customer's own
   address on the origin chain. Rach checks NEAR's signature and that every term matches what
   you asked for.
2. Rach sends `amount` from the customer's address to the quote's `deposit_address`, exactly
   like a payout (`status: DEPOSITING`).
3. NEAR Intents swaps and delivers to `recipient` (`PROCESSING`), then the swap ends:

| Status | Meaning | Webhook |
| - | - | - |
| `SETTLED` | Delivered. `amount_out` and `destination_tx_hash` are set. | `cross_chain_swap.settled` |
| `REFUNDED` | NEAR Intents could not fill it and returned `refunded` to the customer's origin address. | `cross_chain_swap.refunded` |
| `FAILED` | The swap did not complete. `deposited: false` means nothing left the customer's address and no fee was charged. `deposited: true` means NEAR Intents failed after the deposit; Rach recovers the funds to the customer's address, where they arrive as `transfer.received`. | `cross_chain_swap.failed` |

```json theme={null}
{
  "event": "cross_chain_swap.settled",
  "event_id": "cross_chain_swap.settled:xsw_5d0e…",
  "swap_id": "xsw_5d0e…",
  "customer_ref": "cus_8f2a91",
  "from_chain": "tron", "from_token": "USDT", "to_chain": "base", "to_token": "USDC",
  "amount": "250.000000", "fee": "…", "total_debited": "…",
  "expected_out": "249.490000", "min_out": "246.990000", "amount_out": "249.512300",
  "recipient": "0x8a3f…41", "to_customer": true, "deposited": true,
  "deposit_tx_hash": "a9e3…", "destination_tx_hash": "0x77b0…",
  "status": "SETTLED",
  "updated_at": "2026-11-21T09:26:40Z"
}
```

Poll with `GET /v1/swaps/cross-chain/{id}`, or list with `GET /v1/swaps/cross-chain`
(`?customer_ref=`, `limit`, `offset`).

> [!WARNING]
>
> **Credit from deposits, not from swap events.** When the output (`to_customer: true`) or a
> refund lands in a customer's own address, it also arrives as a normal
> [`transfer.received`](https://docs.rach.finance/guides/caas-customers#get-told-about-every-deposit). That deposit is
> your signal to credit. Swap events tell you what happened to the swap; crediting from both
> would credit twice. A typical ledger debits `total_debited` in the origin token when you
> request the swap, credits from `transfer.received`, and releases the debit on
> `cross_chain_swap.failed` with `deposited: false`.

### Limits

* **Minimum:** NEAR Intents currently requires about **\$100** per swap. Below that, the quote is
  refused with `422` and the provider's reason.
* Only the canonical USDT and USDC contracts on each chain are swapped (for example, native USDC
  on Polygon, not bridged USDC.e). Base has no canonical USDT, and TRON has no USDC.
* A deposit that reaches NEAR Intents after `quote_deadline` is refunded to the customer.

### Sandbox

Test-mode keys get a **real dry quote** from NEAR Intents, with placeholder addresses, in the
live response shape and `status: "SANDBOX_SIMULATED"`. Nothing is reserved or moved.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.