# One Click 接口

> One Click 用于通过已授权的代理钱包代发交易。调用 `/send` 系列接口前，需先完成授权流程。

## 查询授权状态

```
GET /api/v1/1ct/status
```

返回 `data`：

| 字段          | 类型     | 说明                            |
| ----------- | ------ | ----------------------------- |
| `status`    | string | 授权状态。`/send` 接口要求值为 `enable`。 |
| `delegatee` | string | 代理钱包地址。                       |

***

## 生成 EIP-712 Payload

```
POST /api/v1/1ct/prepare
```

### 请求体

| 字段         | 类型     | 必填 | 说明                                          |
| ---------- | ------ | -- | ------------------------------------------- |
| `deadline` | number | 是  | EIP-712 签名 deadline（Unix 秒）。≤ `4294967295`。 |

### 返回 `data`

| 字段            | 类型     | 说明                  |
| ------------- | ------ | ------------------- |
| `delegatee`   | string | 代理钱包地址。             |
| `signPayload` | object | EIP-712 typed data。 |
| `nonce`       | number | Delegate nonce。     |
| `deadline`    | number | 与请求一致的 deadline。    |

### signPayload 完整结构

```json
{
  "domain": {
    "name": "OneClickRouter",
    "version": "1",
    "chainId": 10143,
    "verifyingContract": "0x..."
  },
  "types": {
    "EIP712Domain": [
      { "name": "name", "type": "string" },
      { "name": "version", "type": "string" },
      { "name": "chainId", "type": "uint256" },
      { "name": "verifyingContract", "type": "address" }
    ],
    "Delegate": [
      { "name": "user", "type": "address" },
      { "name": "delegatee", "type": "address" },
      { "name": "nonce", "type": "uint64" },
      { "name": "deadline", "type": "uint32" }
    ]
  },
  "primaryType": "Delegate",
  "message": {
    "user": "0x...",
    "delegatee": "0x...",
    "nonce": 0,
    "deadline": 1893456000
  }
}
```

***

## 开启 One Click

```
POST /api/v1/1ct/enable
```

### 请求体

| 字段          | 类型     | 必填 | 说明                                            |
| ----------- | ------ | -- | --------------------------------------------- |
| `signature` | string | 是  | 用户对 `signPayload` 的 EIP-712 签名（65 bytes hex）。 |
| `deadline`  | number | 是  | 与签名 payload 中一致的 deadline。                    |

{% hint style="warning" %}
`signature` 是 `0x` 开头的 65 bytes hex。`deadline` **必须**使用 `/prepare` 返回的同一值。
{% endhint %}

### Node.js 签名示例（ethers v6）

```js
import { Wallet } from "ethers";

const { signPayload, deadline } = prepareResponse.data;
const wallet = new Wallet(process.env.USER_PRIVATE_KEY);

// 校验 signer 地址一致性
if (wallet.address.toLowerCase() !== signPayload.message.user.toLowerCase()) {
  throw new Error("signer address must match signPayload.message.user");
}

// ethers v6 签名
const signature = await wallet.signTypedData(
  { ...signPayload.domain, chainId: BigInt(signPayload.domain.chainId) },
  { Delegate: signPayload.types.Delegate },
  {
    ...signPayload.message,
    nonce: BigInt(signPayload.message.nonce),
    deadline: BigInt(signPayload.message.deadline),
  }
);

console.log({ signature, deadline });
```

***

## 关闭 One Click

```
POST /api/v1/1ct/disable
```

无请求体。签名时 `RAW_BODY` 使用空字符串。

***

## 可用的 Send 接口

One Click 启用后，可调用以下 `/send` 接口代发交易：

| 操作类型 | 接口                              | 方法     |
| ---- | ------------------------------- | ------ |
| 下单   | `/api/v1/orders/send`           | POST   |
| 撤单   | `/api/v1/orders/{orderId}/send` | DELETE |
| 入金   | `/api/v1/cash/deposits/send`    | POST   |
| 出金   | `/api/v1/cash/withdrawals/send` | POST   |

`/send` 系列接口内部流程：先构建 calldata → 再通过 One Click 发送交易。下单、入金、出金发送成功后自动记录 txHash。


---

# 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-zh/api-jie-kou/one-click.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.
