uniswap-math-expert

uniswap-math-expert is an agent for Claude Code from ccashwell/evm-cortex. It costs 35 tokens per session (1,992 once invoked), scanned A, original, MIT.

A mathematical guide to Uniswap V3 and V4, decentralized exchange protocols that trade assets through liquidity pools. It covers price, liquidity, swaps, fees, and the fixed-point arithmetic used by their contracts.

In plain words
What is it for?
Use it to implement or review tick and price conversions, liquidity and amount calculations, swap steps, fee accounting, bitmap traversal, and position management.
Why use it?
Small rounding or overflow mistakes can produce incorrect prices, fees, or token amounts and threaten protocol solvency. This guide helps check the formulas and boundary cases behind those calculations.

Agent for Claude Code

Written for Claude Code: a Claude Code subagent (agents/*.md). Also seen: model in frontmatter.

Good fit Use it to implement or review tick and price conversions, liquidity and amount calculations, swap steps, fee accounting, bitmap traversal, and position management.

Compare 6 agents from other repositories ↓
Install with agentmods
npx agentmods add agents/ccashwell/evm-cortex/uniswap-math-expert
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.

Clone the repo
git clone --depth 1 https://github.com/ccashwell/evm-cortex

Made for: Claude Code.

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 uniswap-math-expert

README.md
[![agentmods](https://agentmods.dev/badge/agents/ccashwell/evm-cortex/uniswap-math-expert/github.svg)](https://agentmods.dev/agents/ccashwell/evm-cortex/uniswap-math-expert)
Your own site
<a href="https://agentmods.dev/agents/ccashwell/evm-cortex/uniswap-math-expert"><img src="https://agentmods.dev/badge/agents/ccashwell/evm-cortex/uniswap-math-expert/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 uniswap-math-expert

Your own site · 80×15
<a href="https://agentmods.dev/agents/ccashwell/evm-cortex/uniswap-math-expert"><img src="https://agentmods.dev/badge/agents/ccashwell/evm-cortex/uniswap-math-expert.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 35 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 1,992 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.
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.00035 $0.01992
Opus 5.5 $0.00014 $0.00797
Sonnet 5.5 $0.00007 $0.00398
Haiku 4.5 $0.00003 $0.00199

Measured 2mo ago against content hash d82418b17ed7, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

uniswap-math-expert 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 2mo ago.

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.

agents/uniswap-math-expert.md · 155 lines

How it starts

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

Uniswap Math Expert

You are a specialist in the mathematical foundations underlying Uniswap V3 and V4. You understand Q64.96 fixed-point encoding, tick-price relationships, concentrated liquidity formulas, the swap step computation loop, fee growth accounting, and the rounding conventions that ensure protocol solvency. You can derive any formula from first principles and catch subtle errors in price/liquidity calculations.

Expertise

  • Q64.96 fixed-point — sqrtPriceX96 encoding, uint160 storage, conversion to/from human-readable prices
  • TickMath — tick ↔ sqrtPriceX96 conversion, MIN_TICK/MAX_TICK boundaries, tick spacing constraints
  • SqrtPriceMath — amount0/amount1 deltas from price ranges, next price from input/output amounts
  • SwapMath — computeSwapStep() inner loop, fee extraction, exact input vs exact output
  • FullMath — 512-bit mulDiv for overflow-safe Q96 arithmetic
  • TickBitmap — packed bit storage for initialized ticks, word/bit decomposition, traversal
  • Position library — position key computation, fee growth tracking per position
  • LiquidityAmounts — token amounts ↔ liquidity conversion for given price ranges
  • Fee accounting — feeGrowthGlobal, feeGrowthOutside, feeGrowthInside derivation, X128 encoding
  • Rounding conventions — round UP when user pays, round DOWN when user receives (protocol solvency)

Core Formulas

Price-Tick Relationship

P(tick) = 1.0001^tick
tick = floor(log(P) / log(1.0001))
sqrtPriceX96 = sqrt(P) × 2^96
P = (sqrtPriceX96 / 2^96)²

Token Amounts from Liquidity + Price Range

For position with liquidity L in range [P_a, P_b] at current price P:

In range (P_a ≤ P ≤ P_b):

amount0 = L × (√P_b - √P) / (√P × √P_b)    = L × (1/√P - 1/√P_b)
amount1 = L × (√P - √P_a)

Below range (P < P_a):

amount0 = L × (√P_b - √P_a) / (√P_a × √P_b) = L × (1/√P_a - 1/√P_b)
amount1 = 0

Above range (P > P_b):

amount0 = 0
amount1 = L × (√P_b - √P_a)

Liquidity from Token Amounts

L_from_amount0 = amount0 × √P_a × √P_b / (√P_b - √P_a)
L_from_amount1 = amount1 / (√P_b - √P_a)
L = min(L_from_amount0, L_from_amount1)   // when both tokens provided

Read the full file on GitHub · 155 lines

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. 2mo ago Changed d82418b17ed7
  2. 3mo ago First seen · 155 lines · 35 tokens per session scan A 3a8fa40cfa8f

Subscribe to this mod's changes

uniswap-math-expert is an agent published in the GitHub repository ccashwell/evm-cortex (131 stars, last pushed 1mo ago), licensed MIT. It adds 35 tokens to every session and 1,992 once invoked, about $0.0001 per session on Opus 5.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.

Related

uniswap-math-expert compared with agents from other repositories

uniswap-math-expert next to 6 agents from other repositories
ModTypeStarsLast pushLicenceScanTokensWorks with
uniswap-math-expertccashwell/evm-cortexAgent1311mo agoMITA35Claude Code
chainaware-ltv-estimatorChainAware/behavioral-prediction-mcpAgent1020d agoMITA297Claude Code
chainaware-counterparty-screenerChainAware/behavioral-prediction-mcpAgent1020d agoMITA231Claude Code
token-economics-designerMatt-Dionis/claude-code-configsAgent6191y agoMITA28Claude Code
crypto-analystcoinpaprika/claude-marketplaceAgent9yesterdaynoneA34Claude Code
defi-engineerGeckoVision/gecko-surfAgent221mo agoApache-2.0A100Claude Code
crypto-traderrafaelkamimura/claude-toolsAgent1010mo agoMITA36Claude Code