Skip to content

zz-gopher/dex-analyzer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DEX Single-Pool Execution Analyzer

DEX 单池执行价分析器(V2 AMM)


🔍 What is this?

This is a CLI tool that analyzes real execution prices on Uniswap V2–like pools,
based directly on on-chain reserves.

Given a pool and a trade size, it shows:

  • Mid price (reserve ratio)
  • Buy execution price
  • Sell execution price
  • Slippage impact caused by AMM curves

This tool focuses on single-pool behavior,
not router-optimized or UI-level quotes.


🔍 这是什么?

这是一个 命令行工具(CLI),用于分析 Uniswap V2 / V2-like 池子中的
真实成交执行价,数据直接来自链上 getReserves()

给定一个池子和交易规模(size),它可以计算:

  • 中间价(mid,基于储备比例)
  • 实际买入执行价
  • 实际卖出执行价
  • 由 AMM 曲线带来的滑点影响

本工具专注于 单一池子的真实行为
不是 前端或聚合器的最优报价模拟。


🎯 Why does this exist?

DEX frontends and aggregators usually show optimized quotes:

  • Multi-pool routing
  • Order splitting
  • Price smoothing

However, these optimizations often hide the raw behavior of a pool.

This tool exists to answer a simpler but fundamental question:

If I trade directly in this pool with size X,
what will actually happen?


🎯 为什么要做这个工具?

DEX 前端和聚合器展示的通常是 优化后的报价

  • 多池路由
  • 拆单
  • 平滑价格曲线

但这些会 掩盖单个池子本身的真实承载能力

这个工具只回答一个更基础的问题:

如果我真的在这个池子里,用 size = X 交易,
会发生什么?


🧠 Key Concepts

  • Base: the asset being traded (e.g. ETH, WBNB)
  • Quote: the asset used to price the base (e.g. USDC, USDT)
  • Price = quote / base
  • Execution price ≠ UI price

Slippage is non-linear and grows rapidly as trade size increases.


🧠 核心概念

  • Base(基准资产):被交易的资产(如 ETH、WBNB)
  • Quote(计价资产):用于定价的资产(如 USDC、USDT)
  • 价格 = quote / base
  • 执行价 ≠ 前端显示价

AMM 的滑点是 非线性的,交易规模越大,惩罚越明显。


✨ Features

  • Supports Uniswap V2–like AMMs (Uniswap V2, PancakeSwap V2, Sushi V2, etc.)
  • Reads on-chain data directly (getReserves)
  • Computes buy / sell execution prices
  • Automatically detects quote / base
    • Stablecoins are preferred as quote
  • Allows manual --quote override with strict validation
  • Clear and deterministic output

✨ 功能特性

  • 支持所有 V2 模式 AMM(Uniswap V2、PancakeSwap V2、Sushi 等)
  • 直接读取链上数据(getReserves
  • 计算真实 买入 / 卖出执行价
  • 自动识别 quote / base
    • 若池子中包含稳定币,优先作为 quote
  • 支持手动指定 --quote(严格校验,错误即退出)
  • 输出口径清晰、行为确定

🚫 What this tool is NOT

  • ❌ Not a trading bot
  • ❌ Not an arbitrage system
  • ❌ Not a Uniswap UI replacement
  • ❌ Not a router / aggregator simulator
  • ❌ Not MEV-aware

🚫 本工具不做什么

  • ❌ 不是交易机器人
  • ❌ 不是套利系统
  • ❌ 不是 Uniswap 前端替代
  • ❌ 不模拟聚合器路由
  • ❌ 不涉及 MEV

🧪 Example Usage

go run ./cmd \
  --rpc  https://arb1.arbitrum.io/rpc \
  --pair 0xF64Dfe17C8b87F012FCf50FbDA1D62bfA148366a \
  --sizes 0.1,1,5

🧪 Example output:

Quote/Base selected: USDC/WETH
Pair: 0xF64Dfe17C8b87F012FCf50FbDA1D62bfA148366a
token0(quote)=USDC(6) 0xaf88d065e77c8cC2239327C5EDb3A432268e5831 | token1(base)=WETH(18) 0x82aF49447D8a07e3bd95BD0d56f35241523fBab1
reserve0=40807956440 | reserve1=13951121552446518257
DEX(mid) USDC/WETH: 2925.066367
size=0.1 WETH | DEX buy/sell exec USDC/WETH: 2955.049420 / 2895.598120
size=1 WETH | DEX buy/sell exec USDC/WETH: 3160.401864 / 2721.782294
size=5 WETH | DEX buy/sell exec USDC/WETH: 4572.694991 / 2148.567353

About

A CLI tool for analyzing real execution prices and slippage in Uniswap V2–like AMMs, based on on-chain reserves.(一款基于链上储备金的CLI工具,用于分析类似Uniswap V2的自动做市商(AMM)中的实际执行价格与滑点。)

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages