跳转到主要内容

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.

本页内容由 AI 自动翻译,所有内容以英文版本为准。查看英文版 →
LaunchLab 支持在 Initialize 时选择三种曲线形状:constant-product(最常见,标准 x · y = k 曲线的虚拟储备形式)、linear-pricefixed-price。所有三种形式共享同一毕业阈值公式。本页详细讲解 constant-product 数学;线性和固定形式的总结见末尾。

LaunchState 上存储的参数

字段含义
curve_type0 = 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_quoteconstant-product 曲线的虚拟储备种子。
migrate_type选择毕业目标:AMM v4 还是 CPMM。见 instructions
fees.buy_numerator / buy_denominator买方费用,例如 100 / 10_000 = 1.00%
fees.sell_numerator / sell_denominator卖方费用。通常与买方相同。
fees.protocol_sharefees.creator_sharefees.lp_share上述费用的分配,总和为分母。
Rust 结构体中的字段名称与 accounts 中描述的 PoolState 字段相匹配;上面的单位是概念性的。

带虚拟储备的 Constant-product 曲线(curve_type = 0

默认且最常用的曲线。所有 Pump 风格的启动都使用这种形式。该曲线假设从一开始就存在虚拟报价储备 V_q虚拟基础储备 V_b(存储在 PoolState 上的 virtual_quotevirtual_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) 作为储备时打开的价格。

固定价格曲线(curve_type = 1

平价曲线。每次买卖都以恒定价格进行,在 Initialize 时可配置:
price(s) = virtual_quote / virtual_base    (对所有 s 恒定)
适用于团队希望所有参与者无论何时购买都以统一价格进行的公平启动。毕业在已售 base_supply_graduation 时触发(线性成本关系使得 quote_reserve_target 易于推导)。

线性价格曲线(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_targetInitialize 时计算为驱动 base_sold 从 0 到 base_supply_graduation 所需的报价:
quote_reserve_target = cost(0, base_supply_graduation) × (1 + buy_fee_rate)
                                                         ^^^^^^^^^^^^^^^^^
                                                         近似;精确形式
                                                         与买入费用舍入
                                                         的形式相匹配。
一旦 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 若报价是 USDC 的话约 6,827 个)。 应用上面的费用
quote_reserve_target ≈ 6.827e9 × 1.01 ≈ 6.895e9  (6,895 USDC)
首次购买 10 USDC:
  • 虚拟状态:s = 0quote_vault = 0
  • 减去费用:quote_after_fee = 10 × 0.99 = 9.9
  • 求解 (40 / (3e18)) × s³ = 9.9s ≈ 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 的观察者看不到价格跳跃。

后续步骤

来源: