Skip to content

Pricing calculations

A launch token’s price is the price of a standard Uniswap V3 pool. Because the token is always 18 decimals and pairs against 18-decimal WETH, there is no decimal scaling to worry about. The only thing to get right is which side of the pool the token is on.

Uniswap V3 stores price as sqrtPriceX96, where:

sqrtPriceX96 = sqrt(price) × 2^96
price = (sqrtPriceX96 / 2^96)² // token1 per token0, raw units

Read sqrtPriceX96 from pool.slot0(). Then convert to WETH per token using the ordering:

const Q96 = 2n ** 96n;
const ratio = (Number(sqrtPriceX96) / Number(Q96)) ** 2; // token1 per token0
// tokenIsToken0 = launch token address < WETH address
const priceWethPerToken = tokenIsToken0
? ratio // token is token0 → token1(=WETH) per token0(=token)
: 1 / ratio; // token is token1 → invert

Because both tokens are 18-decimal, no 10^(decimals) adjustment is needed. If you ever generalize to non-18-decimal pairs, scale by 10^(decimals0 − decimals1).

Each Uniswap V3 Swap event carries the post-swap sqrtPriceX96, so you can update price on every trade without an extra call:

Swap(sender, recipient, amount0, amount1, sqrtPriceX96, liquidity, tick)

Apply the same conversion to the event’s sqrtPriceX96. The signed amount0 / amount1 give trade size and direction (a negative amount is tokens leaving the pool to the trader).

Multiply the WETH price by an ETH/USD reference:

priceUsd = priceWethPerToken × ethUsd

Merry Men does not publish an oracle; use your existing ETH/USD source. Market-cap = priceUsd × totalSupply / 10^18 (supply is fixed, so FDV = market cap).

Spot price ignores slippage. To quote what a specific trade would actually fill at, call QuoterV2 for the network (see Contract addresses):

QuoterV2.quoteExactInputSingle
(uint256 amountOut, , , ) = quoter.quoteExactInputSingle(
QuoteExactInputSingleParams({
tokenIn: weth, // or token, for a sell
tokenOut: token,
amountIn: amountIn,
fee: 10000, // 1% tier
sqrtPriceLimitX96: 0
})
);

Then route the actual swap through the correct SwapRouter for the network, and mind the router ABI difference between mainnet (SwapRouter02, no deadline) and testnet (SwapRouter, deadline in struct).