lp-math
AMM(自動マーケットメイカー)における、価格変動の影響やLPシェア計算など、流動性提供に関する数学的な処理を、わかりやすく実行・分析するSkill。
📜 元の英語説明(参考)
AMM liquidity provision mathematics including constant-product, concentrated liquidity, price impact, and LP share calculations
🇯🇵 日本人クリエイター向け解説
AMM(自動マーケットメイカー)における、価格変動の影響やLPシェア計算など、流動性提供に関する数学的な処理を、わかりやすく実行・分析するSkill。
※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。
下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o lp-math.zip https://jpskill.com/download/10417.zip && unzip -o lp-math.zip && rm lp-math.zip
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/10417.zip -OutFile "$d\lp-math.zip"; Expand-Archive "$d\lp-math.zip" -DestinationPath $d -Force; ri "$d\lp-math.zip"
完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。
💾 手動でダウンロードしたい(コマンドが難しい人向け)
- 1. 下の青いボタンを押して
lp-math.zipをダウンロード - 2. ZIPファイルをダブルクリックで解凍 →
lp-mathフォルダができる - 3. そのフォルダを
C:\Users\あなたの名前\.claude\skills\(Win)または~/.claude/skills/(Mac)へ移動 - 4. Claude Code を再起動
⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。
🎯 このSkillでできること
下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。
📦 インストール方法 (3ステップ)
- 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
- 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
- 3. 展開してできたフォルダを、ホームフォルダの
.claude/skills/に置く- · macOS / Linux:
~/.claude/skills/ - · Windows:
%USERPROFILE%\.claude\skills\
- · macOS / Linux:
Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。
詳しい使い方ガイドを見る →- 最終更新
- 2026-05-18
- 取得日時
- 2026-05-18
- 同梱ファイル
- 1
📖 Skill本文(日本語訳)
※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。
LP Math — AMM流動性提供の数学
自動マーケットメーカー(AMM)は、従来のオーダーブックを流動性プールに置き換えます。買い手と売り手をマッチングする代わりに、数学的な公式が準備金比率に基づいて価格を決定します。流動性プロバイダー(LP)は両方の資産をプールに入金し、すべての取引から手数料を得ます。
AMMの背後にある数学を理解することは、以下にとって不可欠です。
- 非恒久的損失後に流動性を提供することが有益かどうかを評価する
- 大規模な取引を実行する前に価格への影響を推定する
- プールタイプ(定数積 vs 集中型)間の資本効率を比較する
- 特定のプールポジションに対する予想される手数料収入を計算する
関連スキル: ILの計算についてはimpermanent-loss、LPの利回りモデリングについてはyield-analysis、プールの深さの評価についてはliquidity-analysisを参照してください。
1. 定数積AMM (xy = k)
Raydium V4およびほとんどのSolana DEXで使用されている基本的なAMMモデルです。
コア不変量
x * y = k
ここで:
x= トークンX(例:SOL)の準備金額y= トークンY(例:USDC)の準備金額k= 定数積(手数料により時間とともに増加)
スポット価格
P = x / y (X建てのYの価格)
P = y / x (Y建てのXの価格)
100 SOLと10,000 USDCのプールの場合:SOLの価格 = 10,000 / 100 = 100 USDC。
取引実行
トレーダーがトークンXのΔxをプールにスワップする場合:
# 出力額(手数料前)
delta_y = y * delta_x / (x + delta_x)
# 手数料あり(例:0.3%)
delta_y_after_fee = delta_y * (1 - fee_rate)
# 新しい準備金
x_new = x + delta_x
y_new = y - delta_y_after_fee
重要な洞察:取引規模が大きいほど、各ユニットが比率をさらに動かすため、価格が悪化します。
逆計算
特定の出力額Δyを得るために、必要な入力は次のとおりです。
delta_x = x * delta_y / (y - delta_y)
取引後の価格
price_new = y_new / x_new
実行例
プール:100 SOL / 10,000 USDC (k = 1,000,000)、手数料 = 0.3%
5 SOL相当のUSDCを購入:
- 総出力:
10,000 * 5 / (100 + 5) = 476.19 USDC - 手数料:
476.19 * 0.003 = 1.43 USDC - 純出力:
474.76 USDC - 実質価格:
474.76 / 5 = 94.95 USDC/SOL(スポット100に対して) - 価格インパクト:
(100 - 94.95) / 100 = 5.05% - 新しい準備金:105 SOL / 9,525.24 USDC
- 新しいk:
105 * 9,525.24 = 1,000,150.2(kは手数料から増加)
完全な導出については、references/amm_formulas.mdを参照してください。
2. 集中流動性 (CLMM)
Orca Whirlpool、Raydium CLMM、およびMeteora DLMMで使用されます。流動性は、選択された価格範囲[P_lower, P_upper]内でのみアクティブです。
主要な概念
L = sqrt(x * y) # アクティブな範囲内の流動性
price_at_tick = 1.0001^tick # ティックから価格への変換
資本効率
狭い範囲に流動性を集中させることで、1ドルあたりの深さが増します。
# 資本効率比率
efficiency = sqrt(P_upper / P_lower) / (sqrt(P_upper / P_lower) - 1)
# 例:$100 SOLを中心とした±5%の範囲
P_lower, P_upper = 95, 105
efficiency = sqrt(105/95) / (sqrt(105/95) - 1) # ≈ 20.5x
±5%の範囲は、全範囲よりも約20倍資本効率が高いですが、価格が範囲外に移動すると、ポジションは1つの資産に100%移行します。
ポジション価値
現在の価格Pで、範囲[P_lower, P_upper]に流動性Lを持つCLMMポジションの場合:
if P <= P_lower:
# すべてトークンX(範囲未満)
value_x = L * (1/sqrt(P_lower) - 1/sqrt(P_upper))
value_y = 0
elif P >= P_upper:
# すべてトークンY(範囲超)
value_x = 0
value_y = L * (sqrt(P_upper) - sqrt(P_lower))
else:
# 範囲内 — 両方のトークンを保持
value_x = L * (1/sqrt(P) - 1/sqrt(P_upper))
value_y = L * (sqrt(P) - sqrt(P_lower))
範囲戦略の比較
| 範囲 | 効率 | ILリスク | 手数料獲得 | 最適 |
|---|---|---|---|---|
| ±2% | ~50x | 非常に高い | 範囲内であれば高い | ステーブルコイン、タイトなペッグ |
| ±5% | ~20x | 高い | トレンドに最適 | アクティブ管理 |
| ±25% | ~4x | 中程度 | 一貫性がある | セミパッシブ |
| ±100% | ~2x | 低い | 1ドルあたり低い | パッシブ、ボラティリティの高いペア |
| 全範囲 | 1x | ベースライン | 常に獲得 | 設定して放置 |
完全なCLMMの導出については、references/amm_formulas.mdを参照してください。
3. 価格インパクト
定数積インパクト
# 価格インパクト(分数)
price_impact = delta_x / (x + delta_x)
# プールに対する割合
pool_fraction = trade_value / pool_tvl
# 経験則:インパクト ≈ 定数積の場合、2 * pool_fraction
マルチホップインパクト
複数のプールを経由するルートの場合、インパクトを複合します。
def multi_hop_impact(hops: list[dict]) -> float:
"""ルートレッグ全体の合計価格インパクトを計算します。
Args:
hops: 各レッグの{reserve_in, trade_amount}のリスト。
Returns:
合計価格インパクト(分数)。
"""
remaining = 1.0
for hop in hops:
leg_impact = hop["trade_amount"] / (hop["reserve_in"] + hop["trade_amount"])
remaining *= (1 - leg_impact)
return 1 - remaining
インパクトの閾値
| インパクト | 評価 | アクション |
|---|---|---|
| < 0.1% | 無視できる | 通常どおり続行 |
| 0.1–0.5% | 低い | ほとんどの取引で許容可能 |
| 0.5–2% | 中程度 | プール間で分割することを検討 |
| 2–5% | 高い | 取引を分割、TWAPを使用 |
| > 5% | 深刻 | サイズを縮小するか、より深いプールを見つける |
4. LPシェアの計算
初期デポジット(空のプール)
shares = sqrt(x_deposited * y_deposited)
最初の預金者は比率を設定し、幾何平均に等しいシェアを受け取ります。
後続のデポジット
shares_minted = min(
x_added / x_reserve,
y_added / y_reserve
) * total_shares
デポジットは、現在の準備金比率に比例する必要があります。一方のトークンの超過分は使用されません(または、実装に応じて返されます)。
引き出し
x_out = (shares_burned / total_shares) * x_reserve
y_out = (shares_burned / total_shares) * y_reserve
常に現在の比率で両方のトークンを受け取ります。
シェア
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開
LP Math — AMM Liquidity Provision Mathematics
Automated Market Makers (AMMs) replace traditional orderbooks with liquidity pools. Instead of matching buyers and sellers, a mathematical formula determines prices based on reserve ratios. Liquidity providers (LPs) deposit both assets into a pool and earn fees from every trade.
Understanding the math behind AMMs is essential for:
- Evaluating whether providing liquidity is profitable after impermanent loss
- Estimating price impact before executing large trades
- Comparing capital efficiency across pool types (constant product vs concentrated)
- Calculating expected fee revenue for a given pool position
Related skills: See impermanent-loss for IL calculations, yield-analysis for LP yield modeling, liquidity-analysis for pool depth assessment.
1. Constant Product AMM (xy = k)
The foundational AMM model used by Raydium V4 and most Solana DEXes.
Core Invariant
x * y = k
Where:
x= reserve amount of token X (e.g., SOL)y= reserve amount of token Y (e.g., USDC)k= constant product (increases over time from fees)
Spot Price
P = x / y (price of Y in terms of X)
P = y / x (price of X in terms of Y)
For a pool with 100 SOL and 10,000 USDC: price of SOL = 10,000 / 100 = 100 USDC.
Trade Execution
When a trader swaps Δx of token X into the pool:
# Output amount (before fees)
delta_y = y * delta_x / (x + delta_x)
# With fee (e.g., 0.3%)
delta_y_after_fee = delta_y * (1 - fee_rate)
# New reserves
x_new = x + delta_x
y_new = y - delta_y_after_fee
The key insight: larger trades get worse prices because each unit moves the ratio further.
Inverse Calculation
To get a specific output amount Δy, the required input is:
delta_x = x * delta_y / (y - delta_y)
Price After Trade
price_new = y_new / x_new
Worked Example
Pool: 100 SOL / 10,000 USDC (k = 1,000,000), fee = 0.3%
Buy 5 SOL worth of USDC:
- Gross output:
10,000 * 5 / (100 + 5) = 476.19 USDC - Fee:
476.19 * 0.003 = 1.43 USDC - Net output:
474.76 USDC - Effective price:
474.76 / 5 = 94.95 USDC/SOL(vs spot 100) - Price impact:
(100 - 94.95) / 100 = 5.05% - New reserves: 105 SOL / 9,525.24 USDC
- New k:
105 * 9,525.24 = 1,000,150.2(k increased from fees)
See references/amm_formulas.md for complete derivations.
2. Concentrated Liquidity (CLMM)
Used by Orca Whirlpool, Raydium CLMM, and Meteora DLMM. Liquidity is only active within a chosen price range [P_lower, P_upper].
Key Concepts
L = sqrt(x * y) # Liquidity within the active range
price_at_tick = 1.0001^tick # Tick-to-price conversion
Capital Efficiency
Concentrating liquidity in a narrow range provides more depth per dollar:
# Capital efficiency ratio
efficiency = sqrt(P_upper / P_lower) / (sqrt(P_upper / P_lower) - 1)
# Example: ±5% range around $100 SOL
P_lower, P_upper = 95, 105
efficiency = sqrt(105/95) / (sqrt(105/95) - 1) # ≈ 20.5x
A ±5% range is ~20x more capital-efficient than full-range, but the position goes 100% into one asset if price moves outside the range.
Position Value
For a CLMM position with liquidity L in range [P_lower, P_upper] at current price P:
if P <= P_lower:
# All in token X (below range)
value_x = L * (1/sqrt(P_lower) - 1/sqrt(P_upper))
value_y = 0
elif P >= P_upper:
# All in token Y (above range)
value_x = 0
value_y = L * (sqrt(P_upper) - sqrt(P_lower))
else:
# In range — holds both tokens
value_x = L * (1/sqrt(P) - 1/sqrt(P_upper))
value_y = L * (sqrt(P) - sqrt(P_lower))
Range Strategy Comparison
| Range | Efficiency | IL Risk | Fee Capture | Best For |
|---|---|---|---|---|
| ±2% | ~50x | Very high | High if in range | Stablecoins, tight pegs |
| ±5% | ~20x | High | Good for trending | Active management |
| ±25% | ~4x | Moderate | Consistent | Semi-passive |
| ±100% | ~2x | Low | Lower per $ | Passive, volatile pairs |
| Full range | 1x | Baseline | Always earning | Set and forget |
See references/amm_formulas.md for full CLMM derivations.
3. Price Impact
Constant Product Impact
# Price impact as a fraction
price_impact = delta_x / (x + delta_x)
# As percentage of pool
pool_fraction = trade_value / pool_tvl
# Rule of thumb: impact ≈ 2 * pool_fraction for constant product
Multi-Hop Impact
For a route through multiple pools, compound the impacts:
def multi_hop_impact(hops: list[dict]) -> float:
"""Calculate total price impact across route legs.
Args:
hops: List of {reserve_in, trade_amount} for each leg.
Returns:
Total price impact as a fraction.
"""
remaining = 1.0
for hop in hops:
leg_impact = hop["trade_amount"] / (hop["reserve_in"] + hop["trade_amount"])
remaining *= (1 - leg_impact)
return 1 - remaining
Impact Thresholds
| Impact | Assessment | Action |
|---|---|---|
| < 0.1% | Negligible | Proceed normally |
| 0.1–0.5% | Low | Acceptable for most trades |
| 0.5–2% | Moderate | Consider splitting across pools |
| 2–5% | High | Split trade, use TWAP |
| > 5% | Severe | Reduce size or find deeper pools |
4. LP Share Calculations
Initial Deposit (Empty Pool)
shares = sqrt(x_deposited * y_deposited)
The first depositor sets the ratio and receives shares equal to the geometric mean.
Subsequent Deposits
shares_minted = min(
x_added / x_reserve,
y_added / y_reserve
) * total_shares
Deposits must be proportional to the current reserve ratio. Any excess of one token is not used (or returned, depending on implementation).
Withdrawal
x_out = (shares_burned / total_shares) * x_reserve
y_out = (shares_burned / total_shares) * y_reserve
You always receive both tokens in the current ratio.
Share Value
share_value = pool_tvl / total_shares
your_value = your_shares * share_value
5. Fee Accrual
Fees accumulate inside the pool, increasing k:
# Before trade: k = x * y
# After trade with fee:
# k_new = (x + delta_x) * (y - delta_y_net) > k
# The difference is the fee retained in the pool
# Fee APR estimation
daily_volume = 500_000 # USD
fee_rate = 0.003 # 0.3%
daily_fees = daily_volume * fee_rate # $1,500
tvl = 2_000_000 # $2M pool
fee_apr = (daily_fees * 365) / tvl # 27.4%
For CLMM positions, fee earnings depend on:
- Whether price stays within your range (out-of-range = no fees)
- Your share of active liquidity in that range
- Total volume routed through the pool
# CLMM fee estimation
your_liquidity = 50_000 # Your L
total_liquidity = 1_000_000 # Total L in your tick range
your_share = your_liquidity / total_liquidity # 5%
your_daily_fees = daily_fees * your_share # $75
6. Solana Pool Types
Raydium V4 (Constant Product)
- Model: Standard xy = k
- Fee: 0.25% (0.22% to LP, 0.03% to RAY buyback)
- Best for: New token launches, volatile pairs
- Note: Integrated with OpenBook for limit order flow
Orca Whirlpool (Concentrated Liquidity)
- Model: Concentrated liquidity with tick spacing
- Fee tiers: 0.01%, 0.05%, 0.3%, 1%
- Position: Represented as NFT (each position is unique)
- Best for: Major pairs (SOL/USDC), stablecoin pairs
Raydium CLMM
- Model: Concentrated liquidity (similar to Uniswap V3)
- Tick spacing: 1, 10, 60, 200
- Fee tiers: 0.01%, 0.05%, 0.25%, 1%
- Best for: Pairs with predictable ranges
Meteora DLMM (Dynamic Liquidity Market Maker)
- Model: Discrete bins instead of continuous ticks
- Strategies: Spot (uniform), Curve (concentrated), Bid-Ask (around current price)
- Fees: Dynamic, adjusting based on volatility
- Best for: Active LPs who rebalance frequently
See references/pool_mechanics.md for detailed mechanics and comparison.
7. Practical Decision Framework
Should You LP?
1. Calculate expected fee APR
2. Estimate impermanent loss for expected price movement
3. Net return = fee APR - IL
4. Compare to simply holding the assets
Which Pool Type?
Stablecoin pair → CLMM with tight range (±0.5%)
Major pair (SOL/USDC) → CLMM with moderate range (±10-25%)
New/volatile token → Constant product (full range)
Active management → Meteora DLMM with dynamic rebalancing
Position Sizing for LP
# Never LP more than you can afford to lose to IL
max_lp_allocation = portfolio_value * 0.20 # 20% max in any single pool
# For volatile pairs, reduce further
volatility_adjustment = 1 - (annualized_vol / 2) # Scale down for vol
adjusted_allocation = max_lp_allocation * max(0.1, volatility_adjustment)
Files
References
references/amm_formulas.md— Complete mathematical derivations for constant product and concentrated liquidity AMMsreferences/pool_mechanics.md— Solana-specific pool mechanics for Raydium, Orca, and Meteora
Scripts
scripts/amm_calculator.py— Constant product AMM calculator with trade simulation, LP shares, and fee accrualscripts/clmm_calculator.py— Concentrated liquidity calculator with position valuation, capital efficiency, and range comparison
Quick Reference
| Formula | Expression |
|---|---|
| Constant product | x * y = k |
| Spot price | P = y / x |
| Trade output | Δy = y * Δx / (x + Δx) |
| Required input | Δx = x * Δy / (y - Δy) |
| Price impact | Δx / (x + Δx) |
| Initial LP shares | sqrt(x * y) |
| Subsequent shares | min(Δx/x, Δy/y) * total |
| Fee APR | (daily_fees * 365) / TVL |
| CLMM efficiency | sqrt(P_u/P_l) / (sqrt(P_u/P_l) - 1) |
| Tick to price | 1.0001^tick |