> For the complete documentation index, see [llms.txt](https://docs.sodex.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.sodex.com/for-developers/api-reference/mirror-api/history-and-status.md).

# History & Status

Use the history endpoint for account-level reconciliation and the status endpoints to locate a transfer by its external or ValueChain identifier.

## Deposit and withdrawal history

`GET /user/{userAddress}/deposit-withdrawals`

```bash
curl "https://mainnet-gw.sodex.dev/api/v1/user/0x1111111111111111111111111111111111111111/deposit-withdrawals?side=withdraw&pending=true&limit=10" \
  -H "Accept: application/json"
```

### Query parameters

| Name         | Type    | Required | Description                               |
| ------------ | ------- | -------- | ----------------------------------------- |
| `start`      | int32   | No       | Pagination offset. Minimum `0`.           |
| `startTime`  | int64   | No       | Start-time filter. Minimum `0`.           |
| `endTime`    | int64   | No       | End-time filter. Minimum `0`.             |
| `limit`      | int32   | No       | Page size from `1` to `10`; default `10`. |
| `side`       | string  | No       | `deposit` or `withdraw`.                  |
| `token`      | string  | No       | Token identifier or address.              |
| `pending`    | boolean | No       | Select pending or non-pending records.    |
| `chain`      | string  | No       | External chain identifier.                |
| `coinSymbol` | string  | No       | Coin symbol.                              |

`data.records` contains the current page and `data.total` contains the total number of matches. A record includes account, amount, coin, chain, decimals, sender, receiver, status, timestamps, token, and current transaction hash. It can also include `originTxHash`, `withdrawFee`, `withdrawId`, `failCode`, and `failReason`.

## Transfer status endpoints

These APIs return external deposit or withdrawal records that match a transfer identifier.

## Deposit status

Return deposit records for an external-chain transaction hash.

### Request

```http
GET /api/v1/user/deposit/status
```

### Query Parameters

| Name     | Type     | Required | Description                              |
| -------- | -------- | -------- | ---------------------------------------- |
| `chain`  | `string` | `true`   | External chain identifier.               |
| `txHash` | `string` | `true`   | External-chain deposit transaction hash. |

### Request Example

```bash
curl \
  "https://mainnet-gw.sodex.dev/api/v1/user/deposit/status?chain=BASE_ETH&txHash=0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" \
  -H "Accept: application/json"
```

Additional Information:

* The same deposit transaction hash may match multiple records with different `n` values.
* If `chain` does not match the record, the API returns an empty result instead of an error.

## Bridge deposit AML status

Call deposit status with `chain` and the original bridge `txHash`. Gateway looks up formal deposits first. While no formal records exist, a source chain on the AML list is enough to trigger the order lookup. Once records exist, Gateway checks all returned records for a possible bridge deposit on a listed route. It also attempts the lookup when the list or a candidate record’s coin is unknown.

Read `data.records` and `data.total` for formal deposits. When AML orders match, `data.aml.orders` and `data.aml.total` describe those orders. Each order has its own `eventIndex` and `amlStatus`. The `creditToSpot` flag indicates whether the deposit targets Spot.

For a transaction with multiple events, an indexed custody deposit or an unlisted bridge coin can be the only formal record visible while a different event is under review. Gateway can skip the AML lookup in that case. An absent `data.aml` means this response contains no AML result. Confirm credit using a matching formal record, and refund completion using a matching `Refunded` order.

If the AML lookup fails, Gateway returns the formal records with top-level code zero and reports the failure in `data.aml.error`. If the formal lookup fails, Gateway returns a top-level error and skips the AML lookup.

## Deposit refund request

Submit `POST /api/v1/user/deposit/refund` for a `Rejected` AML order. Set `Content-Type: application/json`. The original payer signs the refund message and sends the following required strings in the JSON body.

| Fields                     | Value                                                                                                   |
| -------------------------- | ------------------------------------------------------------------------------------------------------- |
| `account`, `refundAddress` | Original payer's wallet address for this flow.                                                          |
| `chain`, `token`, `txHash` | Copy from the rejected order. For Base USDC, use token ID `BASE_USDC` and the original bridge hash.     |
| `eventIndex`               | Copy from the rejected order, including an explicitly empty string.                                     |
| `nonce`                    | 16 random bytes encoded as 32 lowercase hex characters without a prefix. Keep leading zeros.            |
| `expiryTime`               | Signature expiry as decimal Unix seconds without leading zeros.                                         |
| `accountSign`              | The original payer’s 65-byte EIP-191 signature over the refund message, hex-encoded with a `0x` prefix. |

The wallet signs `eventIndex` under the name `n` and `refundAddress` under `to`. Mirror validates refund fields and the payer signature. On rejection, Gateway returns Mirror’s HTTP status and response body, including its error code and message. A successful submission returns `code: 0` and `data: {}`. Poll deposit status with the original hash until the matching order reports `Refunded`.

Mirror can report a business rejection with HTTP 200. For example, the refund endpoint can return the following body verbatim. Check the numeric Gateway success code (`code === 0`) before treating the request as accepted.

```json
{
  "code": "-1",
  "message": "invalid signature"
}
```

### Wallet example

Use the selected rejected order and an ethers v6 signer for the original payer. Sign the UTF-8 text with LF between lines and no trailing newline. Keep the address and hash casing used in the request. The example uses the mainnet audience.

```javascript
async function signRefund(signer, order) {
  const account = await signer.getAddress();
  if (order.amlStatus !== "Rejected" ||
      account.toLowerCase() !== order.sender.toLowerCase()) {
    throw new Error("Select a rejected order from the connected payer");
  }

  const nonce = Array.from(crypto.getRandomValues(new Uint8Array(16)),
    byte => byte.toString(16).padStart(2, "0")).join("");
  const body = {
    account, chain: order.chain, token: order.token, txHash: order.txHash,
    eventIndex: order.eventIndex, refundAddress: account, nonce,
    expiryTime: String(Math.floor(Date.now() / 1000) + 300)
  };
  if (Object.values(body).some(value => typeof value !== "string" || /[\r\n]/.test(value))) {
    throw new Error("Refund fields must be single-line strings");
  }
  const message = [
    "SoSoValue Custody Refund v2",
    "audience: sodex-mirror-server:prod",
    `account: ${body.account}`,
    `chain: ${body.chain}`,
    `token: ${body.token}`,
    `txHash: ${body.txHash}`,
    `n: ${body.eventIndex}`,
    `to: ${body.refundAddress}`,
    `nonce: ${body.nonce}`,
    `expiryTime: ${body.expiryTime}`
  ].join("\n");
  const accountSign = await signer.signMessage(message);
  return JSON.stringify({ ...body, accountSign });
}

async function submitRefund(signedBody) {
  const response = await fetch("https://mainnet-gw.sodex.dev/api/v1/user/deposit/refund", {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: signedBody
  });
  const result = await response.json();
  if (!response.ok || result.code !== 0) {
    throw new Error(result.message ?? result.error ?? `Refund request failed (HTTP ${response.status})`);
  }
  return result;
}
```

Keep the signed body in the calling application before the first submission.

```javascript
const signedBody = await signRefund(signer, order);
await submitRefund(signedBody);
```

If the response is lost, query H1 and match the order’s `eventIndex`. For `RefundPending` or `Refunded`, continue tracking that order. If it still reports `Rejected` and a retry is needed before `expiryTime`, call `submitRefund(signedBody)` again with the saved string. After expiry, refresh status before asking the payer to sign again.

## Withdrawal status

Return withdrawal records by withdrawal ID or by the ValueChain transaction hash of the withdrawal request.

### Request

```http
GET /api/v1/user/withdraw/status
```

### Query Parameters

| Name         | Type     | Required | Description                                                                                   |
| ------------ | -------- | -------- | --------------------------------------------------------------------------------------------- |
| `chain`      | `string` | `true`   | External chain identifier.                                                                    |
| `withdrawId` | `string` | `false`  | Withdrawal request identifier. Required when `txHash` is omitted.                             |
| `txHash`     | `string` | `false`  | ValueChain transaction hash of the withdrawal request. Required when `withdrawId` is omitted. |

### Request Examples

Query by withdrawal ID:

```bash
curl \
  "https://mainnet-gw.sodex.dev/api/v1/user/withdraw/status?chain=BASE_ETH&withdrawId=12345" \
  -H "Accept: application/json"
```

Query by the ValueChain withdrawal-request transaction hash:

```bash
curl \
  "https://mainnet-gw.sodex.dev/api/v1/user/withdraw/status?chain=BASE_ETH&txHash=0xbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" \
  -H "Accept: application/json"
```

Additional Information:

* At least one of `withdrawId` and `txHash` is required.
* Prefer `withdrawId`. When both parameters are provided, `withdrawId` takes precedence and `txHash` is ignored.
* `withdrawId` is forwarded unchanged. Clients must not assume that it is always numeric.
* The `txHash` fallback accepts only the ValueChain transaction hash of the withdrawal request. It cannot query by the final external-chain withdrawal transaction hash.
* If `chain` does not match the record, the API returns an empty result instead of an error.

## Response

Deposit and withdrawal status share the formal record fields below. Deposit status can also include AML results.

| Name        | Type                              | Required | Description                              |
| ----------- | --------------------------------- | -------- | ---------------------------------------- |
| `code`      | `int32`                           | `true`   | Response status code. `0` means success. |
| `data`      | [TransferStatus](#transferstatus) | `true`   | Matching deposit or withdrawal records.  |
| `timestamp` | `uint64`                          | `true`   | Response timestamp in milliseconds.      |

### TransferStatus

| Name      | Type                                  | Required | Description                                                                              |
| --------- | ------------------------------------- | -------- | ---------------------------------------------------------------------------------------- |
| `aml`     | [DepositAMLResult](#depositamlresult) | `false`  | Deposit status only. Omitted when the AML lookup is skipped or finds no matching orders. |
| `records` | `DepositWithdrawalRecord[]`           | `true`   | Matching deposit or withdrawal records.                                                  |
| `total`   | `int32`                               | `true`   | Total number of matching records.                                                        |

### DepositAMLResult

When orders match, `data.aml` contains both `orders` and `total`. If the AML lookup fails, it contains only `error`. The formal deposit records remain available in `data.records`.

| Name     | Type                                         | Required          | Description                                            |
| -------- | -------------------------------------------- | ----------------- | ------------------------------------------------------ |
| `orders` | [BridgeDepositOrder](#bridgedepositorder)\[] | On match          | AML orders for the queried chain and transaction hash. |
| `total`  | `integer`                                    | On match          | Total number of matching AML orders.                   |
| `error`  | `string`                                     | On lookup failure | Error message from the AML lookup.                     |

### BridgeDepositOrder

| Name           | Type     | Required | Description                                                                                                                                                                                                    |
| -------------- | -------- | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `chain`        | `string` | `true`   | Source chain identifier, for example `BASE_ETH`.                                                                                                                                                               |
| `txHash`       | `string` | `true`   | Original bridge deposit transaction hash on the source chain.                                                                                                                                                  |
| `eventIndex`   | `string` | `true`   | Event index within the transaction. Copy this string into a refund request, including an empty value.                                                                                                          |
| `token`        | `string` | `true`   | Token identifier used for refunds, for example `BASE_USDC`.                                                                                                                                                    |
| `coinSymbol`   | `string` | `true`   | Asset symbol, for example `USDC`.                                                                                                                                                                              |
| `sender`       | `string` | `true`   | Original payer’s address.                                                                                                                                                                                      |
| `receiver`     | `string` | `true`   | Intended recipient of the deposit.                                                                                                                                                                             |
| `amount`       | `string` | `true`   | Integer amount in token base units.                                                                                                                                                                            |
| `decimals`     | `uint8`  | `true`   | Decimal places for `amount`. For example, `"10500000"` with `6` decimals means 10.5 tokens.                                                                                                                    |
| `creditToSpot` | `bool`   | `true`   | `true` when the deposit targets Spot.                                                                                                                                                                          |
| `amlStatus`    | `string` | `true`   | `Pending`, `Approved`, `Rejected`, `RefundPending`, or `Refunded`. See [AML orders](https://docs.sodex.com/for-developers/developers/mirror-protocol/lifecycle/deposits.md#aml-orders) for the action to take. |

### DepositWithdrawalRecord

| Name           | Type     | Required | Description                                          |
| -------------- | -------- | -------- | ---------------------------------------------------- |
| `account`      | `string` | `true`   | Sodex user account address.                          |
| `amount`       | `string` | `true`   | Transfer amount.                                     |
| `chain`        | `string` | `true`   | External chain identifier.                           |
| `coin`         | `string` | `true`   | Coin symbol.                                         |
| `decimals`     | `uint8`  | `true`   | Coin decimals.                                       |
| `failCode`     | `string` | `true`   | Failure code. Empty when no failure occurred.        |
| `failReason`   | `string` | `true`   | Failure reason. Empty when no failure occurred.      |
| `n`            | `string` | `true`   | Mirror record sequence or cursor value.              |
| `receiver`     | `string` | `true`   | Receiving address.                                   |
| `reportAmount` | `string` | `true`   | Amount reported by the external transfer system.     |
| `sender`       | `string` | `true`   | Sending address.                                     |
| `status`       | `string` | `true`   | Current transfer status.                             |
| `statusTime`   | `int64`  | `true`   | Time when the status was last updated.               |
| `stmp`         | `int64`  | `true`   | Record timestamp.                                    |
| `token`        | `string` | `true`   | Token identifier or contract address.                |
| `txHash`       | `string` | `true`   | Current transaction hash.                            |
| `originTxHash` | `string` | `false`  | Original transaction hash. Omitted when unavailable. |
| `type`         | `string` | `true`   | Record type.                                         |
| `withdrawFee`  | `string` | `false`  | Withdrawal fee. Omitted when not applicable.         |
| `withdrawId`   | `uint64` | `false`  | Withdrawal identifier. Omitted when unavailable.     |

## Response Example

### Withdrawal in progress

```json
{
  "code": 0,
  "timestamp": 1780000000000,
  "data": {
    "records": [
      {
        "account": "0x1111111111111111111111111111111111111111",
        "amount": "10000000",
        "chain": "BASE_ETH",
        "coin": "USDC",
        "decimals": 6,
        "failCode": "",
        "failReason": "",
        "n": "123456",
        "receiver": "0x2222222222222222222222222222222222222222",
        "reportAmount": "10000000",
        "sender": "0x1111111111111111111111111111111111111111",
        "status": "Processing",
        "statusTime": 1780000000,
        "stmp": 1780000000,
        "token": "0x3333333333333333333333333333333333333333",
        "txHash": "0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
        "originTxHash": "0xbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
        "type": "withdraw",
        "withdrawFee": "1000000",
        "withdrawId": 123
      }
    ],
    "total": 1
  }
}
```

### Base USDC deposit rejected before formal credit

For `GET /api/v1/user/deposit/status`, `code: 0` means the lookup succeeded. Here the original Base transaction has no formal deposit records (`data.total: 0`) and one rejected AML order (`data.aml.total: 1`). The original payer can use this order’s `txHash`, `eventIndex`, and `token` to [request a refund](#deposit-refund-request).

```json
{
  "code": 0,
  "timestamp": 1791806400000,
  "data": {
    "records": [],
    "total": 0,
    "aml": {
      "orders": [
        {
          "chain": "BASE_ETH",
          "txHash": "0x1122334411223344112233441122334411223344112233441122334411223344",
          "eventIndex": "3",
          "token": "BASE_USDC",
          "coinSymbol": "USDC",
          "sender": "0x8F54e840706351c6ca6ddDcD27aA9fb3880850C6",
          "receiver": "0x8F54e840706351c6ca6ddDcD27aA9fb3880850C6",
          "amount": "10500000",
          "decimals": 6,
          "creditToSpot": true,
          "amlStatus": "Rejected"
        }
      ],
      "total": 1
    }
  }
}
```

## Empty Response Example

No matching record is a successful response:

```json
{
  "code": 0,
  "timestamp": 1780000000000,
  "data": {
    "records": [],
    "total": 0
  }
}
```
