# Simulate Swap

Create a confirmed swap record without calling LI.FI or any blockchain — for exercising swap UI and transaction-history flows.

## Overview

This endpoint does not price anything and does not touch a chain. It writes a swap transaction for `walletId` with status `confirmed` and returns it with `simulation: true`. The `quoteId` starts with `sim_`, the placeholder `txHash` starts with `SIMULATED`, and `toAmount` equals `fromAmount`.

The record uses `fromChain` as its chain and `fromToken` and `fromAmount` as its token and amount; the symbol and decimals fields are stored for display. Defaults when omitted: `fromTokenSymbol` `EURC_TEST`, `fromTokenDecimals` `6`, `toTokenSymbol` `SOL`, `toTokenDecimals` `9`.

> ⚠️ The API describes this endpoint as being for testnet development and flow testing only, but the handler does not enforce that: it accepts any authenticated user and does not check `isTestnet`. The simulated swap appears in the user's transaction history as a confirmed swap. Use test wallets and pass `isTestnet: true`.

## Endpoint

### `POST /v1/swap/simulate`

Authentication: bearer token required.

Creates a confirmed simulated swap record. No LI.FI call and no on-chain transaction.

**Request body**

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `walletId` | string (uuid) | yes | Wallet the record is created for. Must belong to the authenticated user. |
| `fromChain` | string | yes | Recorded as the transaction's chain. |
| `toChain` | string | yes | Required by the schema; not stored on the record. |
| `fromToken` | string | yes | Recorded as the transaction's token address. |
| `toToken` | string | yes | Recorded in the metadata as the destination token address. |
| `fromAmount` | string | yes | Digits only (`^\d+$`). Returned as both `fromAmount` and `toAmount`. |
| `isTestnet` | boolean | no | Stored on the record. |
| `fromTokenSymbol` | string | no | Default `EURC_TEST`. |
| `fromTokenDecimals` | integer | no | Default `6`. |
| `toTokenSymbol` | string | no | Default `SOL`. |
| `toTokenDecimals` | integer | no | Default `9`. |

**Responses**

`200` OK

```json
{
  "transactionId": "…",
  "quoteId": "sim_1757584800000_k3j9x2",
  "txHash": "SIMULATED…",
  "status": "confirmed",
  "fromAmount": "1000000",
  "toAmount": "1000000",
  "simulation": true
}
```

`404` Not Found

```json
{
  "statusCode": 404,
  "error": "NotFoundError",
  "message": "Wallet not found"
}
```

## Implementation

```javascript
// Create a simulated swap to test history and UI states — no LI.FI, no chain
async function simulateSwap(token, { walletId, fromChain, toChain, fromToken, toToken, fromAmount }) {
  const res = await fetch('https://api.aureahub.com/v1/swap/simulate', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'Authorization': `Bearer ${token}`
    },
    body: JSON.stringify({
      walletId,
      fromChain,
      toChain,
      fromToken,
      toToken,
      fromAmount,                 // digits only
      isTestnet: true,
      fromTokenSymbol: 'EURC_TEST',
      fromTokenDecimals: 6,
      toTokenSymbol: 'SOL',
      toTokenDecimals: 9
    })
  });

  const body = await res.json();
  if (!res.ok) throw new Error(`${res.status}: ${body.message}`);

  // { transactionId, quoteId: 'sim_…', txHash: 'SIMULATED…', status: 'confirmed', simulation: true, ... }
  return body;
}
```

---

Web version: https://docs.aureahub.com/#swap-simulate
