> ## 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.

# LaunchLab 联动曲线

> LaunchLab 支持的曲线公式、闭式买卖成本、毕业阈值推导，以及从首次购买到毕业的完整数值示例。

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

  [查看英文版 →](/products/launchlab/bonding-curve)
</Info>

<Info>
  LaunchLab 支持三种曲线形状，在 `Initialize` 时选择：**constant-product**（最常见，标准 `x · y = k` 曲线的虚拟储备形式）、**linear-price** 和 **fixed-price**。毕业阈值公式在所有三种形式中共享。本页详细讲解 constant-product 数学；linear 和 fixed 形式在末尾总结。
</Info>

## 存储在 `LaunchState` 上的参数

| 字段 | 含义 |
| - | - |
| `curve_type` | `0` = constant-product（虚拟储备），`1` = fixed-price，`2` = linear-price。 |
| `base_supply_max` | 曲线能够铸造的总基础代币数。 |
| `base_supply_graduation` | 必须售出的基础代币数以达到毕业。通常为 `0.8 × base_supply_max`；剩余 20% 成为毕业后流动性池的初始 LP。 |
| `quote_reserve_target` | 触发毕业的报价金额。在 `Initialize` 时从曲线参数 + `base_supply_graduation` 推导。 |
| `virtual_base` / `virtual_quote` | constant-product 曲线的虚拟储备种子。 |
| `migrate_type` | 新初始化时必须为 `CPSWAP`。存储的 AMM v4 值仅为遗留状态。参见 [`instructions`](/zh/products/launchlab/instructions)。 |
| `fees.buy_numerator / buy_denominator` | 买方费用，例如 `100 / 10_000 = 1.00%`。 |
| `fees.sell_numerator / sell_denominator` | 卖方费用。通常与买方相同。 |
| `fees.protocol_share`、`fees.creator_share`、`fees.lp_share` | 上述费用的分配，总和为分母。 |

Rust 结构体中的字段名与 [`accounts`](/zh/products/launchlab/accounts) 中描述的 `PoolState` 字段匹配；上面的单位是概念性的。

## 带虚拟储备的 constant-product 曲线（`curve_type = 0`）

默认且最常用的曲线。Pump 风格的启动都使用这种形式。该曲线假设从一开始就存在一个**虚拟报价储备** `V_q` 和一个**虚拟基础储备** `V_b`（存储在 `PoolState` 上的 `virtual_quote` 和 `virtual_base`），因此有效池看起来像一个具有这些储备的 CPMM。购买遵循 `x · y = k` 数学：

```
(V_q + real_quote_in_after_fee) × (V_b + real_base_remaining − base_out) = V_q × V_b
```

求解 `base_out`：

```
base_out = (V_b + real_base_remaining) × quote_in_after_fee / (V_q + real_quote_in_after_fee)
```

在基础售出 `s` 处的有效价格：

```
price(s) = (V_q + real_quote_in(s)) / (V_b + real_base_remaining(s))
```

LaunchLab 在毕业前应用的相同 `x · y = k` 不变量随后成为毕业后的 CPMM 曲线，因此交接在机制上是无缝的：在 `base_sold = base_supply_graduation` 处的边际价格等于毕业后池以 `(quote_vault, base_vault_remaining)` 作为其储备开放时的价格。

## Fixed-price 曲线（`curve_type = 1`）

平价曲线。每次买卖都以恒定价格进行，在 `Initialize` 时可配置：

```
price(s) = virtual_quote / virtual_base    (对所有 s 恒定)
```

适用于团队希望为所有参与者提供统一定价的公平启动，无论他们何时购买。当 `base_supply_graduation` 已售出时毕业触发（线性成本关系使 `quote_reserve_target` 易于推导）。

## Linear-price 曲线（`curve_type = 2`）

价格随 `base_sold` 线性增加：

```
price(s) = a · s     (a = 斜率，从 virtual_base / virtual_quote 推导)
```

集成成本：

```
cost(s_0, s_1) = a · (s_1² − s_0²) / 2
```

关于 `base_sold` 是二次的——早期购买者支付接近零，后期购买者支付大得多，边际价格始终以固定斜率上升。链上实现位于 `curve/linear_price.rs`。

## 曲线形状比较

```
price
  │   linear (steep tail)               linear (curve_type = 2)
  │       ╱
  │      ╱
  │     ╱            const-product (curve_type = 0)
  │    ╱            ╱
  │   ╱           ╱
  │  ╱         ╱
  │ ╱       ╱
  │╱_____╱_______________________  fixed-price (curve_type = 1)
  └──────────────────────────────── base_sold
  0                  S_grad         S_max
```

## 毕业阈值

`quote_reserve_target` 在 `Initialize` 时计算为将 `base_sold` 从 0 驱动到 `base_supply_graduation` 所需的报价：

```
quote_reserve_target = cost(0, base_supply_graduation) × (1 + buy_fee_rate)
                                                         ^^^^^^^^^^^^^^^^^
                                                         近似值；精确形式
                                                         与 Buy 上使用的费用
                                                         舍入相匹配。
```

一旦 `quote_vault.balance ≥ quote_reserve_target`，启动就会毕业。由于购买以离散大小进行，毕业时的实际余额可能略微超过目标——盈余成为生成的 CPMM 池中额外的报价端流动性。

## 工作示例——二次启动

参数：

* `base_supply_max        = 1_000_000_000`（10 亿基础代币，6 位小数）
* `base_supply_graduation = 800_000_000`（售出 80% 触发毕业）
* `k                      = 40`（价格标度）
* 费用：1% 买入，1% 卖出，分配 `lp:creator:protocol = 60:20:20`。

**初始价格**（`s = 0`）：`0`（纯二次从零开始）。

**售出 50% 时的价格**（`s = 500_000_000`）：

```
price = 40 × (500e6 / 1e9)² = 40 × 0.25 = 10  (报价每基础，6 位小数)
```

**毕业时的价格**（`s = 800_000_000`）：

```
price = 40 × (800e6 / 1e9)² = 40 × 0.64 = 25.6
```

**达到毕业所需的报价**（集成成本）：

```
cost(0, 800_000_000) = (40 / (3 × 1e18)) × ((800e6)³ − 0)
                     = (40 / 3e18) × 5.12e26
                     ≈ 6.827e9
```

因此约 6.827 个报价原生单位（在配置的任何 6 位小数报价铸币中，例如，如果报价是 USDC，则约 6,827 USDC）。

**应用的费用**：

```
quote_reserve_target ≈ 6.827e9 × 1.01 ≈ 6.895e9  (6,895 USDC)
```

**首次购买** 10 USDC：

* 虚拟状态：`s = 0`，`quote_vault = 0`。
* 减去费用：`quote_after_fee = 10 × 0.99 = 9.9`。
* 求解 `(40 / (3e18)) × s³ = 9.9e6` —— 9.9 USDC 以原生的 6 位小数单位表示，与上面 `6.827e9` 所用的单位相同 ⇒ `s ≈ 9.06e7` 个基础代币被买入。
* 1% 费用（`0.1 USDC`）分配：lp `0.06`、creator `0.02`、protocol `0.02`。lp 份额留在 `quote_vault`；其他两个路由到各自的应计计数器。

**在售出 75% 时购买**（接近毕业）：

相同的 10 USDC 现在购买的基础要少得多，因为曲线很陡。在 `s₀ = 750e6` 处以 `quote_in_after_fee = 9.9e6` 求解，得到 `∆s ≈ 4.4e5` —— 与首次买入相比，每 USDC 获得的基础减少了 **\~200×**。

## 曲线阶段期间的费用机制

在每次 `Buy` 上：

```
gross_fee      = ceil(quote_in_gross × buy_numerator / buy_denominator)
lp_share       = gross_fee × fees.lp_share / fees.total_share
protocol_share = gross_fee × fees.protocol_share / fees.total_share
creator_share  = gross_fee × fees.creator_share / fees.total_share
```

* `lp_share` 留在 `quote_vault`。这是使有效曲线更紧（相同基础供应中更多报价储备）的原因。
* `protocol_share` 增加 `LaunchState.state_data.protocol_fees_quote`。
* `creator_share` 增加 `LaunchState.state_data.creator_fees_quote`。

在 `Sell` 上，相同的分配适用，但费用从出站 `quote_out` 中扣除。

两个计数器都通过 `CollectFees` 扫除（管理员或创建者，各自到自己的计数器）。

## 精度

* 基础端金额：`u64`。
* 报价端金额：`u64`。
* 中间立方体 / 乘积：`u128`。
* "买入精确报价"和"卖出精确报价"都以**闭式解**反解 —— 恒定乘积曲线用代数法，固定价格曲线用除法，线性价格曲线用平方根。程序中没有牛顿求解器，没有迭代上限，也没有 `NotConverged` 错误。

## 交接到 CPMM

当 `Graduate` 触发时：

```
cpmm_quote_reserve = quote_vault − swept_protocol_fees − swept_creator_fees
cpmm_base_reserve  = base_vault                       // 即 base_supply_max − base_sold
cpmm_initial_price = cpmm_quote_reserve / cpmm_base_reserve
```

对于**恒定乘积**曲线 —— LaunchLab 的默认类型，也是目前唯一活跃的类型 —— `cpmm_initial_price` 恰好就是 `price(base_sold)`，即交接时刻的边际曲线价格，因此从曲线 UI 切换到 CPMM UI 的观察者看不到跳跃。对于二次价格曲线则不然：积分平均价格高于边际价格（在上面的例子中高出 `4/3` 倍），因此交接时预计会出现一个跳变。

## 接下来去哪里

* [`products/launchlab/accounts`](/zh/products/launchlab/accounts)——存储这些参数的 `LaunchState` 字段。
* [`products/launchlab/instructions`](/zh/products/launchlab/instructions)——`Buy`、`Sell`、`Graduate` 账户列表。
* [`algorithms/constant-product`](/zh/algorithms/constant-product)——毕业后池使用的 CPMM 数学。

来源：

* [Raydium SDK v2 `LaunchLab` 模块](https://github.com/raydium-io/raydium-sdk-V2)
* Raydium LaunchLab 程序源代码


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.