uniswap-math-expert

uniswap-math-expert is an agent for coding agents from ccashwell/evm-cortex. It costs 35 tokens per session (1,865 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

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.

agentmods
npx agentmods add agents/ccashwell/evm-cortex/uniswap-math-expert
Clone the repo
git clone --depth 1 https://github.com/ccashwell/evm-cortex

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.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.svg" alt="Measured on agentmods" 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,865 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
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 $0.00035 $0.01865
Opus 5 $0.00017 $0.00932
Sonnet 5 $0.00007 $0.00373
Haiku 4.5 $0.00003 $0.00186

Measured 5d ago against content hash 3a8fa40cfa8f, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, 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 5d 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. 5d 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 (127 stars, last pushed 25d ago), licensed MIT. It adds 35 tokens to every session and 1,865 once invoked, about $0.0002 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.

Related

Other agents, from other repositories

orquestra-tx-builder

Builds unsigned Solana transactions using Orquestra MCP's buildinstruction tool. Requires all accounts and arguments to be fully resolved before calling. Outputs a base64-encoded wire transaction (Solana RPC standard) ready for signing. Uses ONLY Orquestra MCP tools. Examples: Context: All accounts are known, user…

berkayoztunc/orquestra · 288 tokens

chainaware-ltv-estimator

Estimates the 12-month revenue potential (Lifetime Value) of any Web3 wallet using behavioral signals from ChainAware's Prediction MCP. Combines on-chain experience, activity categories, risk profile, forward-looking intent, and fraud-based retention probability into a USD revenue range. Use this agent PROACTIVELY…

ChainAware/behavioral-prediction-mcp · 297 tokens

chainaware-counterparty-screener

Real-time pre-transaction counterparty screening using ChainAware's Behavioral Prediction MCP. Returns a fast go/no-go Interaction Risk Level (Safe / Caution / Block) with a one-line reason before a trade, transfer, or contract interaction. Use this agent PROACTIVELY whenever a user is about to interact with an…

ChainAware/behavioral-prediction-mcp · 231 tokens

token-economics-designer

Token economics and tier design specialist. Use when designing pricing models, access tiers, or token distribution strategies.

Matt-Dionis/claude-code-configs · 28 tokens

crypto-analyst

Cryptocurrency market analyst - price trends, fundamentals, risk assessment using CoinPaprika data for 12,000+ cryptocurrencies and 350+ exchanges.

coinpaprika/claude-marketplace · 34 tokens

crypto-trader

Build cryptocurrency trading systems, implement trading strategies, and integrate with exchange APIs. Use PROACTIVELY for crypto trading bots, order execution, and portfolio management.

rafaelkamimura/claude-tools · 36 tokens