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

# 错误代码

> Raydium 每个链上程序的 Anchor 错误枚举，附带原因说明和推荐的 UX 提示信息。

<Info>
  **本页内容由 AI 自动翻译，所有内容以英文版本为准。**

  [查看英文版 →](/reference/error-codes)
</Info>

<Info>
  **权威来源。** 下表从各程序在 Raydium 公开仓库中的 `error.rs` 自动生成。当程序升级并新增变体时，请重新运行提取脚本（每张表底部有链接），并将新行追加到表尾，而不是重新排列——Anchor 错误代码按**源码顺序**分配，而非按名称，调整顺序会破坏集成方的错误处理逻辑。
</Info>

## Anchor 错误代码的工作原理

Anchor 从 `6000` 开始，依次为程序 `ErrorCode` 枚举的每个变体分配数字代码。交易失败时会暴露以下信息：

* **数字错误代码**（例如 `0x1771` = 6001），出现在交易日志中。
* **错误名称**（例如 `InvalidOwner`），来自 IDL。
* **`#[msg(...)]` 字符串**，由 Anchor 写入 `log_messages`。

集成方应匹配**数字代码**，而非消息字符串（字符串可能在不升级版本的情况下被修改）。

```ts theme={null}
// Example: detect the CPMM slippage error and surface a clean UX message.
const CPMM_EXCEEDED_SLIPPAGE = 6005;

try {
  await sdk.cpmm.swap({ ... });
} catch (err: any) {
  const code = err?.error?.errorCode?.number ?? err?.code;
  if (code === CPMM_EXCEEDED_SLIPPAGE) {
    showToast("Price moved past your slippage tolerance. Increase slippage or retry.");
    return;
  }
  throw err;
}
```

## CPMM（标准 AMM）错误

程序 ID：参见 [reference/program-addresses](/zh/reference/program-addresses#on-chain-programs)。来源：`raydium-cp-swap/programs/cp-swap/src/error.rs`。

| 代码   | 变体                             | `#[msg]` 字符串                                                                  | 典型原因                                                                       | 推荐 UX 提示                     |
| ---- | ------------------------------ | ----------------------------------------------------------------------------- | -------------------------------------------------------------------------- | ---------------------------- |
| 6000 | `NotApproved`                  | Not approved                                                                  | 调用方不是管理员指令的配置权限账户。                                                         | "只有池管理员才能执行此操作。"             |
| 6001 | `InvalidOwner`                 | Input account owner is not the program address                                | 传入账户归属于错误的程序（通常是错误的 token 程序或错误程序的 PDA）。                                   | "内部错误：账户所有者不匹配，请刷新后重试。"      |
| 6002 | `EmptySupply`                  | Input token account empty                                                     | LP 或 token 账户余额为零，而该步骤需要正数金额。                                              | "没有可提取的内容。"                  |
| 6003 | `InvalidInput`                 | InvalidInput                                                                  | 通用参数错误（金额越界、标志位错误）。                                                        | "输入无效，请检查金额后重试。"             |
| 6004 | `IncorrectLpMint`              | Address of the provided lp token mint is incorrect                            | 传入的 LP mint 账户与 `pool_state.lp_mint` 不匹配。                                  | "内部错误：LP mint 错误，请刷新池数据。"    |
| 6005 | `ExceededSlippage`             | Exceeds desired slippage limit                                                | 成交价格比用户设置的 `minAmountOut` / `maxAmountIn` 更差。                              | "价格已超出你的滑点容忍范围，请提高滑点或重试。"    |
| 6006 | `ZeroTradingTokens`            | Given pool token amount results in zero trading tokens                        | 存款/提款计算将某一侧四舍五入为零（头寸过小）。                                                   | "金额低于该池的最低要求。"               |
| 6007 | `NotSupportMint`               | Not support token\_2022 mint extension *(语法问题来自源码)*                           | 池遇到了无法安全处理的 Token-2022 扩展（例如 `TransferHook`、`DefaultAccountState=Frozen`）。 | "该代币包含 Raydium CPMM 不支持的扩展。" |
| 6008 | `InvalidVault`                 | invaild vault *(源码拼写错误)*                                                      | 传入的 vault 账户与 `pool_state` 中记录的不匹配。                                        | "内部错误：vault 错误，请刷新后重试。"      |
| 6009 | `InitLpAmountTooLess`          | Init lp amount is too less(Because 100 amount lp will be locked) *(语法问题来自源码)* | 初始化池时，计算出的 LP 供应量低于永久锁定量。                                                  | "初始流动性过小，请增加存款金额。"           |
| 6010 | `TransferFeeCalculateNotMatch` | TransferFee calculate not match                                               | Token-2022 手续费 mint 转账后的实际金额与预计算值不符。                                       | "代币转账手续费在交易中途发生变化，请重试。"      |
| 6011 | `MathOverflow`                 | Math overflow                                                                 | 中间的 swap / 存款 / 手续费计算发生溢出。                                                 | "该金额对此池而言过大。"                |
| 6012 | `InsufficientVault`            | Insufficient vault                                                            | 池的 vault 余额不足以覆盖所请求的输出金额。                                                  | "池中流动性不足，无法满足此规模。"           |
| 6013 | `InvalidFeeModel`              | Invalid fee model                                                             | 管理员设置的 `AmmConfig` 参数组合被链上拒绝。                                              | N/A — 仅限管理员路径。               |
| 6014 | `NoFeeCollect`                 | Fee is zero                                                                   | 调用 `collect_protocol_fee` / `collect_fund_fee` 时可收集手续费为零。                  | N/A — 管理员路径；工具层应忽略此错误。       |

生成来源：[github.com/raydium-io/raydium-cp-swap — error.rs](https://github.com/raydium-io/raydium-cp-swap/blob/master/programs/cp-swap/src/error.rs)。

## CLMM 错误

程序 ID：参见 [reference/program-addresses](/zh/reference/program-addresses#on-chain-programs)。来源：`raydium-clmm/programs/amm/src/error.rs`。

| 代码   | 变体                                       | `#[msg]` 字符串                                                                            | 典型原因                                                                                                 | 推荐 UX 提示                         |
| ---- | ---------------------------------------- | --------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------- | -------------------------------- |
| 6000 | `NotApproved`                            | Not approved                                                                            | 调用方不是该指令的配置管理员。                                                                                      | "只有池管理员才能执行此操作。"                 |
| 6001 | `InvalidUpdateConfigFlag`                | invalid update amm config flag                                                          | 管理员向 `update_amm_config` 传入了无法识别的 `param` 值。                                                         | N/A — 仅限管理员路径。                   |
| 6002 | `AccountLack`                            | Account lack                                                                            | 交易中缺少必需的 remaining account（通常是 tick-array 或 oracle 扩展）。                                              | "内部错误：缺少账户，请刷新池数据。"              |
| 6003 | `ClosePositionErr`                       | Remove liquidity, collect fees owed and reward then you can close position account      | 尝试关闭仍有流动性、未收取手续费或未收取奖励的头寸。                                                                           | "请先提取所有流动性并领取手续费/奖励，再关闭头寸。"      |
| 6004 | `InvalidTickIndex`                       | Tick out of range                                                                       | `tick_lower` 或 `tick_upper` 超出 `[-443636, 443636]` 范围。                                               | "该池的价格区间超出边界。"                   |
| 6005 | `TickInvalidOrder`                       | The lower tick must be below the upper tick                                             | `tick_lower >= tick_upper`。                                                                          | "下限价格必须低于上限价格。"                  |
| 6006 | `TickLowerOverflow`                      | The tick must be greater, or equal to the minimum tick(-443636)                         | 下限 tick 下溢。                                                                                          | "下限价格过低。"                        |
| 6007 | `TickUpperOverflow`                      | The tick must be lesser than, or equal to the maximum tick(443636)                      | 上限 tick 溢出。                                                                                          | "上限价格过高。"                        |
| 6008 | `TickAndSpacingNotMatch`                 | tick % tick\_spacing must be zero                                                       | 提交的 tick 不是池 `tick_spacing` 的整数倍。                                                                    | "请将价格对齐到最近的有效刻度。"                |
| 6009 | `InvalidTickArray`                       | Invalid tick array account                                                              | 传入了错误的 tick-array 槽位 PDA。                                                                            | "内部错误：tick array 错误，请刷新池数据。"     |
| 6010 | `InvalidTickArrayBoundary`               | Invalid tick array boundary                                                             | tick-array 索引存在偏差。                                                                                   | "内部错误：tick-array 边界错误。"          |
| 6011 | `SqrtPriceLimitOverflow`                 | Square root price limit overflow                                                        | 调用方提供的 `sqrt_price_limit` 超出有效范围。                                                                    | "价格限制超出范围。"                      |
| 6012 | `SqrtPriceX64`                           | sqrt\_price\_x64 out of range                                                           | 池当前 sqrt 价格在 swap 中途偏离范围。                                                                            | "请重试 swap。"                      |
| 6013 | `LiquiditySubValueErr`                   | Liquidity sub delta L must be smaller than before                                       | 减少流动性时内部不变量被违反。                                                                                      | "内部错误：流动性计算异常。"                  |
| 6014 | `LiquidityAddValueErr`                   | Liquidity add delta L must be greater, or equal to before                               | 增加流动性时内部不变量被违反。                                                                                      | "内部错误：流动性计算异常。"                  |
| 6015 | `ForbidBothZeroForSupplyLiquidity`       | Both token amount must not be zero while supply liquidity                               | 增加流动性时 `amount_0_max` 和 `amount_1_max` 均为零。                                                          | "请至少提供一种代币。"                     |
| 6016 | `LiquidityInsufficient`                  | Liquidity insufficient                                                                  | 头寸流动性不足以满足提取请求。                                                                                      | "提取金额超过头寸流动性。"                   |
| 6017 | `PriceSlippageCheck`                     | Price slippage check                                                                    | 成交价格未通过调用方的滑点保护检查。                                                                                   | "价格已超出你的滑点容忍范围，请提高滑点或重试。"        |
| 6018 | `TooLittleOutputReceived`                | Too little output received                                                              | `SwapBaseInput`：输出金额低于 `other_amount_threshold`。                                                     | "滑点超限，未达到最小输出要求。"                |
| 6019 | `TooMuchInputPaid`                       | Too much input paid                                                                     | `SwapBaseOutput`：输入金额超过 `other_amount_threshold`。                                                    | "滑点超限，超出最大输入限制。"                 |
| 6020 | `ZeroAmountSpecified`                    | Swap special amount can not be zero                                                     | swap 指令中 `amount` 为零。                                                                                | "请输入大于零的金额。"                     |
| 6021 | `InvalidInputPoolVault`                  | Input pool vault is invalid                                                             | swap 的 input-vault 账户与池记录的 vault 不匹配。                                                                | "内部错误：input vault 错误，请刷新池数据。"    |
| 6022 | `TooSmallInputOrOutputAmount`            | Swap input or output amount is too small                                                | swap 计算结果四舍五入为零，通常因金额极小（dust）。                                                                       | "金额过小，无法在该池中执行 swap。"            |
| 6023 | `NotEnoughTickArrayAccount`              | Not enough tick array account                                                           | 为 swap 范围提供的 tick-array remaining accounts 数量不足。                                                     | "内部错误：tick-array 不足，请刷新池数据。"     |
| 6024 | `InvalidFirstTickArrayAccount`           | Invalid first tick array account                                                        | 传入的第一个 tick-array 账户不覆盖当前 tick。                                                                      | "内部错误：首个 tick array 错误，请刷新池数据。"  |
| 6025 | `InvalidRewardIndex`                     | Invalid reward index                                                                    | `reward_index` 超出 `[0, 2]` 范围。                                                                       | N/A — 管理员路径。                     |
| 6026 | `FullRewardInfo`                         | The init reward token reach to the max                                                  | 池已配置最大数量（3 个）的奖励 mint。                                                                               | N/A — 管理员路径。                     |
| 6027 | `RewardTokenAlreadyInUse`                | The init reward token already in use                                                    | 奖励 mint 与现有 mint 重复。                                                                                 | N/A — 管理员路径。                     |
| 6028 | `ExceptRewardMint`                       | The reward tokens must contain one of pool vault mint except the last reward            | 在第 2 个槽位之前，奖励 mint 必须等于池 vault mint 之一。                                                              | N/A — 管理员路径。                     |
| 6029 | `InvalidRewardInitParam`                 | Invalid reward init param                                                               | 奖励排放的起止时间或每秒速率参数错误。                                                                                  | N/A — 管理员路径。                     |
| 6030 | `InvalidRewardInputAccountNumber`        | Invalid collect reward input account number                                             | 传给 `CollectReward` 的 remaining accounts 数量错误。                                                        | "内部错误：账户数量错误，请刷新后重试。"            |
| 6031 | `InvalidRewardPeriod`                    | Invalid reward period                                                                   | 奖励排放周期无效（`end <= start` 或持续时间为零）。                                                                    | N/A — 管理员路径。                     |
| 6032 | `NotApproveUpdateRewardEmissions`        | Modification of emissions is allowed within 72 hours from the end of the previous cycle | 管理员在距周期边界 72 小时窗口之外修改排放参数。                                                                           | N/A — 管理员路径。                     |
| 6033 | `UnInitializedRewardInfo`                | uninitialized reward info                                                               | 引用了未初始化的奖励槽位。                                                                                        | N/A — 管理员路径。                     |
| 6034 | `NotSupportMint`                         | Not support token\_2022 mint extension                                                  | CLMM 遇到了无法处理的 Token-2022 扩展。                                                                         | "该代币包含 Raydium CLMM 不支持的扩展。"     |
| 6035 | `MissingTickArrayBitmapExtensionAccount` | Missing tickarray bitmap extension account                                              | swap 跨越了基础 bitmap 未覆盖的 tick 范围，需要扩展 bitmap 账户。                                                       | "内部错误：缺少 tick-array 扩展，请刷新池数据。"  |
| 6036 | `InsufficientLiquidityForDirection`      | Insufficient liquidity for this direction                                               | swap 方向上的流动性不足。                                                                                      | "该 swap 规模的流动性不足。"               |
| 6037 | `MaxTokenOverflow`                       | Max token overflow                                                                      | 输入/输出金额超过 u64 上限。                                                                                    | "该金额对此池而言过大。"                    |
| 6038 | `CalculateOverflow`                      | Calculate overflow                                                                      | 手续费/流动性计算溢出。                                                                                         | "该金额对此池而言过大。"                    |
| 6039 | `TransferFeeCalculateNotMatch`           | TransferFee calculate not match                                                         | Token-2022 转账手续费实际金额与预期不符。                                                                           | "代币转账手续费在交易中途发生变化，请重试。"          |
| 6040 | `OrderAlreadyFilled`                     | Order already fully filled, cannot modify                                               | `IncreaseLimitOrder` / `DecreaseLimitOrder` 作用于未成交部分为零的订单。                                           | "该限价单已完全成交，请结算以领取输出代币。"          |
| 6041 | `InvalidOrderPhase`                      | Invalid order phase                                                                     | 修改订单时，FIFO 批次阶段与 tick 当前批次不再匹配。                                                                      | "当前状态下无法对该订单执行此操作。"              |
| 6042 | `InvalidLimitOrderAmount`                | Invalid limit order amount                                                              | 开仓/增仓/减仓时，订单输入低于池的最低要求（或为零）。                                                                         | "订单规模低于池的最低限制。"                  |
| 6043 | `OrderPhaseSaturated`                    | Tick order phase saturated                                                              | tick 上的批次 `order_phase` 计数器已饱和，在现有批次结算并轮转之前，该 tick 无法新增订单。                                           | "该价格的活跃订单过多，请尝试相邻 tick 或等待订单结算。" |
| 6044 | `InvalidDynamicFeeConfigParams`          | Invalid dynamic fee config params                                                       | `CreateDynamicFeeConfig` / `UpdateDynamicFeeConfig` 被拒绝；或 `CreateCustomizablePool` 启用了动态手续费但未提供有效配置。 | 管理员路径 N/A；用户路径提示"动态手续费配置无效"。     |
| 6045 | `InvalidFeeOn`                           | Invalid fee on which token (must be 0, 1, or 2)                                         | `CreateCustomizablePool` 传入的 `collect_fee_on` 值不在 `{0, 1, 2}` 范围内。                                   | "内部错误：无效的手续费模式。"                 |
| 6046 | `ZeroSqrtPrice`                          | sqrt\_price\_x64 must be greater than 0                                                 | `CreateCustomizablePool`（或其他接受自定义初始 sqrt 价格的路径）以 `sqrt_price_x64 == 0` 调用。                           | "初始价格必须大于零。"                     |
| 6047 | `ZeroLiquidity`                          | liquidity must be greater than 0                                                        | 提供流动性的路径以 `liquidity == 0` 且无补偿金额调用。                                                                 | "流动性金额必须大于零。"                    |
| 6048 | `MissingBaseFlag`                        | base\_flag is required when liquidity is zero                                           | 按金额开仓路径计算出 `liquidity == 0`，但调用方未提供 `base_flag` 以确定哪一侧是基础代币。                                         | "请提供非零流动性，或指定哪种代币为基础代币。"         |
| 6049 | `MissingMintAccount`                     | Mint account is required but not provided                                               | Token-2022 感知路径调用时未传入所需的 input/output mint 账户（用于验证扩展和转账手续费）。                                         | "内部错误：缺少 mint 账户，请刷新池数据。"        |
| 6050 | `MissingTokenProgram2022`                | Token-2022 program is required but not provided                                         | 同上，缺少的是 SPL-Token-2022 程序账户。                                                                         | "内部错误：缺少 Token-2022 程序，请刷新后重试。"  |

> **关于重新编号的说明。** 本次发布中，CLMM `ErrorCode` 枚举进行了重新编号：移除/修复了五个旧变体（`LOK`、`ZeroMintAmount`、`InvalidLiquidity`、`TransactionTooOld`、`InvalidRewardDesiredAmount`）及若干拼写错误（`Liquitity`、`enought`、`emissiones`），并追加了十一个新变体。由于 Anchor 按源码顺序为错误编号，`6000` 起的所有代码相对于预发布版本均已发生偏移。对旧版本硬编码了数字代码的客户端需要重新映射。

生成来源：[github.com/raydium-io/raydium-clmm — error.rs](https://github.com/raydium-io/raydium-clmm/blob/master/programs/amm/src/error.rs)。

## AMM v4、Farm v3 / v5 / v6、LaunchLab 错误

这些程序的错误已在各自的章节中说明（参见 [`products/amm-v4/instructions`](/zh/products/amm-v4/instructions)、[`products/farm-staking/instructions`](/zh/products/farm-staking/instructions)、[`products/launchlab/instructions`](/zh/products/launchlab/instructions)）。由于这些程序混合使用 Anchor 和原生 Solana 的错误机制，其错误表位于对应的指令参考页，而非此处。以下代码范围由各章节保留：

| 程序           | 代码范围（仅 Anchor）         | 参考                                                                             |
| ------------ | ---------------------- | ------------------------------------------------------------------------------ |
| AMM v4       | 自定义 u32 代码，非 Anchor 风格 | [`products/amm-v4/instructions`](/zh/products/amm-v4/instructions)             |
| Farm v3 / v5 | 自定义 u32 代码             | [`products/farm-staking/instructions`](/zh/products/farm-staking/instructions) |
| Farm v6      | 6000+（Anchor）          | [`products/farm-staking/instructions`](/zh/products/farm-staking/instructions) |
| LaunchLab    | 6000+（Anchor）          | [`products/launchlab/instructions`](/zh/products/launchlab/instructions)       |

## 将 SDK 错误映射到程序错误

官方 TypeScript SDK 将链上错误封装为 `SendTransactionError`，对于 Anchor 程序则封装为 `AnchorError`：

```ts theme={null}
import { AnchorError } from "@coral-xyz/anchor";

try {
  await sdk.cpmm.swap({ ... });
} catch (err) {
  if (err instanceof AnchorError) {
    console.log(err.error.errorCode.number, err.error.errorCode.code, err.error.errorMessage);
    // 6005 ExceededSlippage "Exceeds desired slippage limit"
  } else {
    // Raw SendTransactionError — inspect err.logs for the "custom program error: 0x..." line.
  }
}
```

如果你没有使用 Anchor 客户端，可以解析交易日志：

```
Program <ProgramID> invoke [1]
Program log: AnchorError caused by account: pool_state. Error Code: ExceededSlippage. Error Number: 6005. Error Message: Exceeds desired slippage limit.
```

正则模式 `Error Number: (\d+)` 在各 Anchor 版本中稳定，可安全匹配。

## 重新生成这些表

当程序升级并新增错误时，请从源码重新提取：

```bash theme={null}
# Clone and grep the error enum in order.
git clone --depth=1 https://github.com/raydium-io/raydium-cp-swap
awk '/#\[msg\(/{ gsub(/^[ \t]*#\[msg\("|"\)\][ \t]*/,""); m=$0; getline; gsub(/,/,""); gsub(/^[ \t]+/,""); print "6000+++\t" $0 "\t" m }' \
  raydium-cp-swap/programs/cp-swap/src/error.rs
# Replace 6000+++ with monotonically-increasing 6000,6001,... Append new rows to the table above.
```

每当新增变体时，请同时更新 [`reference/changelog`](/zh/reference/changelog)，以便升级 SDK 的集成方及时刷新其错误处理逻辑。

来源：

* [raydium-cp-swap error.rs（主网 CPMM）](https://github.com/raydium-io/raydium-cp-swap/blob/master/programs/cp-swap/src/error.rs)
* [raydium-clmm error.rs（主网 CLMM）](https://github.com/raydium-io/raydium-clmm/blob/master/programs/amm/src/error.rs)
