Menu

Reading DEX prices from Ethereum logs: Uniswap v2/v3/v4, Balancer, Curve, Fluid and DODO next to Binance
📰

Reading DEX prices from Ethereum logs: Uniswap v2/v3/v4, Balancer, Curve, Fluid and DODO next to Binance

DEV Community: rust·StarGate·about 20 hours ago
#CoeGSqku
#devtorust#devto#dev#price#pool
Reading 0:00
15s threshold

We wanted one chart that shows BTC and ETH from Binance and from every large Ethereum pool as separate lines, with no averaging and no invented points. Binance is the easy half: its @trade stream gives price, quantity and time per trade. The pools are harder: eight protocol families, each with its own events, its own math and its own idea of what "the price" is. This post is what we learned building that observer in Rust, with numbers from its own data.

Two kinds of price

For every pool we keep two things apart:

Trade price — the ratio of what actually changed hands in one swap: quote_amount / base_amount , taken from the swap's two legs. It produces volume.

Spot price — the pool's marginal price right after an event (or at block end). It produces the line on the chart and never produces volume.

A swap whose legs do not move in opposite directions is not a trade and is skipped. All ratios are exact decimals truncated (not rounded) at 24 places; JSON carries them as strings.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.