> ## 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`                                             | 選擇畢業目標：AMM v4 或 CPMM。見 [`instructions`](/zh-Hant/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-Hant/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（或 AMM v4）曲線，所以畢業交接在機制上是無縫的：在 `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.9` ⇒ `s ≈ 6.22e6` 個基礎代幣購買。
* 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.9` 的牛頓解約給出 `∆s ≈ 0.4e6` ——與首次購買相比，每 USDC 基礎減少約 15 倍。

## 曲線階段期間的手續費機制

每次 `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`。
* 「購買精確報價」和「賣出精確報價」的牛頓解以 `u128` 定點迭代，最大迭代次數可配置（預設 10）。失敗模式是 `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
```

對於二次曲線，`cpmm_initial_price` 在機制上是 `price(base_sold)`（它是交接時刻的邊際曲線價格）。CPMM 池以恰好那個價格開啟，所以從曲線 UI 切換到 CPMM UI 的觀察者看不到跳躍。

## 後續步驟

* [`products/launchlab/accounts`](/zh-Hant/products/launchlab/accounts) — 儲存這些參數的 `LaunchState` 欄位。
* [`products/launchlab/instructions`](/zh-Hant/products/launchlab/instructions) — `Buy`、`Sell`、`Graduate` 帳戶列表。
* [`algorithms/constant-product`](/zh-Hant/algorithms/constant-product) — 畢業後池使用的 CPMM 數學。

來源：

* [Raydium SDK v2 `LaunchLab` 模組](https://github.com/raydium-io/raydium-sdk-V2)
* Raydium LaunchLab 程式原始碼
