lp-math

lp-math is a skill for Claude Code from agiprolabs/claude-trading-skills. It costs 23 tokens per session (2,871 once invoked), scanned A, original, MIT.

A mathematics guide to providing liquidity in automated market makers, which set trade prices from asset balances instead of matching orders in an order book.

In plain words
What is it for?
Use it to compare constant-product and concentrated-liquidity pools, estimate trading fees and capital efficiency, and assess whether providing liquidity may be profitable.
Why use it?
It helps calculate price impact, fee income, liquidity-provider share values, and the risks of different pool designs.

Skill for Claude Code

Written for Claude Code: shipped in a Claude Code plugin. Also seen: positional $N argument.

Part of the trading-skills plugin — 68 skills shipped together

Good fit Use it to compare constant-product and concentrated-liquidity pools, estimate trading fees and capital efficiency, and assess whether providing liquidity may be profitable.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/agiprolabs/claude-trading-skills/lp-math
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add agiprolabs/claude-trading-skills --skill lp-math
Clone the repo
git clone --depth 1 https://github.com/agiprolabs/claude-trading-skills

Made for: Claude Code.

Or install trading-skills, the plugin that ships this one along with the rest of its 68 skills.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for lp-math

README.md
[![agentmods](https://agentmods.dev/badge/skills/agiprolabs/claude-trading-skills/lp-math/github.svg)](https://agentmods.dev/skills/agiprolabs/claude-trading-skills/lp-math)
Your own site
<a href="https://agentmods.dev/skills/agiprolabs/claude-trading-skills/lp-math"><img src="https://agentmods.dev/badge/skills/agiprolabs/claude-trading-skills/lp-math/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for lp-math

Your own site · 80×15
<a href="https://agentmods.dev/skills/agiprolabs/claude-trading-skills/lp-math"><img src="https://agentmods.dev/badge/skills/agiprolabs/claude-trading-skills/lp-math.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 23 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,871 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe. Third-party audits
  • NVIDIA SkillSpector warn 7 Sept 2026
SkillSpector: 1 finding, up to medium

These are SkillSpector’s own severities. On a checked sample its high-severity flags on skills were ~96% false positives — a documented command, a public API, a “never do X” rule — so we show them as a caution to read, not a verdict. Why →

  • medium analysis-evasion · line 1
    Suspicious Unicode normalization or mixed-script content
    Fix: Review the flagged content for security risks. Ensure no credentials, secrets, or sensitive data are exposed.
How audits are shown
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00023 $0.02871
Opus 5 $0.00012 $0.01435
Sonnet 5 $0.00005 $0.00574
Haiku 4.5 $0.00002 $0.00287

Measured 11d ago against content hash dabe3bc9ef02, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-11, from the pricing page.

Security

Grade A, and why

lp-math scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 11d ago.

The scan reads SKILL.md. This mod also ships 2 executable files (scripts/amm_calculator.py, scripts/clmm_calculator.py), listed below but not scanned — reading those needs a real analyzer, not pattern matching.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

skills/lp-math/SKILL.md · 364 lines

How it starts

The opening of the file, as written. The whole thing — 364 lines — stays where its author put it; the contents beside it link to each section on GitHub.

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:

  1. Gross output: 10,000 * 5 / (100 + 5) = 476.19 USDC
  2. Fee: 476.19 * 0.003 = 1.43 USDC
  3. Net output: 474.76 USDC
  4. Effective price: 474.76 / 5 = 94.95 USDC/SOL (vs spot 100)
  5. Price impact: (100 - 94.95) / 100 = 5.05%
  6. New reserves: 105 SOL / 9,525.24 USDC
  7. New k: 105 * 9,525.24 = 1,000,150.2 (k increased from fees)

Read the full file on GitHub · 364 lines

Files

What ships with it

4 files beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 11d ago First seen · 364 lines · 23 tokens per session scan A dabe3bc9ef02

Subscribe to this mod's changes

lp-math is a skill published in the GitHub repository agiprolabs/claude-trading-skills (354 stars, last pushed 8d ago), licensed MIT. It adds 23 tokens to every session and 2,871 once invoked, about $0.0001 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.