# Cash Operations

## Deposit Pre-Authorization

Deposit transactions deduct cash tokens from the user's wallet. Before calling deposit endpoints, the user's wallet must complete an ERC-20 `approve` to the corresponding spender:

```
ERC20(tokenAddress).approve(spender, rawTokenAmount)
```

Where `rawTokenAmount = tokenAmount × 10^tokenDecimals`.

### Mainnet Spender Addresses

| `x-api-chain-id` | Chain            | `x-api-p`     | Spender                                      |
| ---------------- | ---------------- | ------------- | -------------------------------------------- |
| `1`              | Ethereum Mainnet | `Anchored`    | `0x8c1b182bb0fe4e8407404ffe37c974d6dacef3a9` |
| `143`            | Monad Mainnet    | `Anchored`    | `0x8c1b182bb0fe4e8407404ffe37c974d6dacef3a9` |
| `143`            | Monad Mainnet    | `MondayTrade` | `0xb983787a2882da59bbf9e09cb5a0e47ff0c30141` |

### Check Allowance

```http
GET /api/v1/users/{userId}/balance?spenderAddress={spender}
```

`tokenBalances[].walletAllowance` is the user's wallet allowance to the spender.

{% hint style="warning" %}
When allowance is insufficient, `/cash/deposits/calldata` still returns calldata normally, but the subsequent on-chain transaction will fail.
{% endhint %}

***

## Deposit Endpoints

### Build Deposit Calldata

```
POST /api/v1/cash/deposits/calldata
```

| Field          | Type            | Required | Description                      |
| -------------- | --------------- | -------- | -------------------------------- |
| `userAddress`  | string          | Yes      | User wallet address.             |
| `tokenAddress` | string          | Yes      | Cash token contract address.     |
| `tokenAmount`  | string / number | Yes      | Deposit amount (human-readable). |

Returns `method` as `deposit`, `value` as `"0"`.

### One Click Delegated Deposit

```
POST /api/v1/cash/deposits/send
```

| Field          | Type            | Required | Description                  |
| -------------- | --------------- | -------- | ---------------------------- |
| `tokenAddress` | string          | Yes      | Cash token contract address. |
| `tokenAmount`  | string / number | Yes      | Deposit amount.              |
| `gasLimit`     | number          | No       | Specified gas limit.         |

{% hint style="info" %}
This endpoint uses the **API Key's bound `userAddress`**. It does not read `userAddress` from the request body.
{% endhint %}

### Record Deposit TxHash

```
POST /api/v1/cash/deposits/tx
```

| Field    | Type   | Required | Description                |
| -------- | ------ | -------- | -------------------------- |
| `txHash` | string | Yes      | Submitted deposit tx hash. |

### Query Deposit Records

```
GET /api/v1/cash/deposits?page=1&limit=10
GET /api/v1/cash/deposits/{operationId}
```

`operationId` is backfilled by the indexer after parsing on-chain events.

***

## Withdrawal Endpoints

### Build Withdrawal Calldata

```
POST /api/v1/cash/withdrawals/calldata
```

| Field          | Type            | Required | Description                                |
| -------------- | --------------- | -------- | ------------------------------------------ |
| `userAddress`  | string          | Yes      | User wallet address.                       |
| `tokenAddress` | string          | Yes      | Cash token contract address.               |
| `creditAmount` | string / number | Yes      | Withdrawal credit amount (human-readable). |

Returns `method` as `withdraw`, `value` as `"0"`.

### One Click Delegated Withdrawal

```
POST /api/v1/cash/withdrawals/send
```

### Record Withdrawal TxHash

```
POST /api/v1/cash/withdrawals/tx
```

### Query Withdrawal Records

```
GET /api/v1/cash/withdrawals?page=1&limit=10
GET /api/v1/cash/withdrawals/{operationId}
```

***

## Operation Detail Fields

`TradingCashOperationDetailRespDto`:

| Field                 | Type          | Description                     |
| --------------------- | ------------- | ------------------------------- |
| `mappingStatus`       | string / null | TX mapping status.              |
| `operationStatus`     | string / null | On-chain cash operation status. |
| `mapping`             | object        | Mapping record.                 |
| `depositOperation`    | object / null | Deposit details.                |
| `withdrawalOperation` | object / null | Withdrawal details.             |

### depositOperation Common Fields

| Field          | Type          | Description                     |
| -------------- | ------------- | ------------------------------- |
| `operationId`  | string        | Deposit operation ID.           |
| `userAddress`  | string        | User address.                   |
| `tokenAddress` | string        | Token address.                  |
| `status`       | string        | Operation status.               |
| `isInstant`    | boolean       | Whether instant.                |
| `amount`       | number        | Token amount (human-readable).  |
| `creditAmount` | number        | Credit amount (human-readable). |
| `feeAmount`    | number        | Fee amount (human-readable).    |
| `createTxHash` | string        | Creation tx hash.               |
| `settleTxHash` | string / null | Settlement tx hash.             |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.anchored.finance/trading-api-docs-en/api-reference/cash-operations.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
